forked from flutter/flutter
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
packages/flutter/lib/src/services/keyboard_inserted_content.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2014 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'package:flutter/foundation.dart'; | ||
|
||
/// A class representing rich content (such as a PNG image) inserted via the | ||
/// system input method. | ||
/// | ||
/// The following data is represented in this class: | ||
/// - MIME Type | ||
/// - Bytes | ||
/// - URI | ||
@immutable | ||
class KeyboardInsertedContent { | ||
/// Creates an object to represent content that is inserted from the virtual | ||
/// keyboard. | ||
/// | ||
/// The mime type and URI will always be provided, but the bytedata may be null. | ||
const KeyboardInsertedContent({required this.mimeType, required this.uri, this.data}); | ||
|
||
/// Converts JSON received from the Flutter Engine into the Dart class. | ||
KeyboardInsertedContent.fromJson(Map<String, dynamic> metadata): | ||
mimeType = metadata['mimeType'] as String, | ||
uri = metadata['uri'] as String, | ||
data = metadata['data'] != null | ||
? Uint8List.fromList(List<int>.from(metadata['data'] as Iterable<dynamic>)) | ||
: null; | ||
|
||
/// The mime type of the inserted content. | ||
final String mimeType; | ||
|
||
/// The URI (location) of the inserted content, usually a "content://" URI. | ||
final String uri; | ||
|
||
/// The bytedata of the inserted content. | ||
final Uint8List? data; | ||
|
||
/// Convenience getter to check if bytedata is available for the inserted content. | ||
bool get hasData => data?.isNotEmpty ?? false; | ||
|
||
@override | ||
String toString() => '${objectRuntimeType(this, 'KeyboardInsertedContent')}($mimeType, $uri, $data)'; | ||
|
||
@override | ||
bool operator ==(Object other) { | ||
if (other.runtimeType != runtimeType) { | ||
return false; | ||
} | ||
return other is KeyboardInsertedContent | ||
&& other.mimeType == mimeType | ||
&& other.uri == uri | ||
&& other.data == data; | ||
} | ||
|
||
@override | ||
int get hashCode => Object.hash(mimeType, uri, data); | ||
} |