Skip to content

Commit

Permalink
Oopsie
Browse files Browse the repository at this point in the history
  • Loading branch information
tneotia committed Jan 27, 2023
1 parent 76c4df3 commit 18e3b3a
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions packages/flutter/lib/src/services/keyboard_inserted_content.dart
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);
}

0 comments on commit 18e3b3a

Please sign in to comment.