Add support for image insertion on Android (#110052)

* Add support for image insertion on Android

* Fix checks

* Use proper Dart syntax on snippet

* Specify type annotation on list

* Fix nits, add some asserts, and improve example code

* Add missing import

* Fix nullsafety error

* Fix nullsafety error

* Remove reference to contentCommitMimeTypes in docs

* Fix nits

* Fix warnings and import

* Add test for content commit in editable_text_test.dart

* Check that URIs are equal in test

* Fix nits and rename functions / classes to be more self-explanatory

* Fix failing debugFillProperties tests

* Add empty implementation to `insertContent` in TextInputClient

* Tweak documentation slightly

* Improve docs for contentInsertionMimeTypes and fix assert

* Rework contentInsertionMimeType asserts

* Add test for onContentInserted example

* Switch implementation to a configuration class for more granularity in setting mime types

* Fix nits

* Improve docs and fix doc tests

* Fix more nits (LongCatIsLooong)

* Fix failing tests

* Make parameters (guaranteed by platform to be non-nullable) non-nullable

* Fix analysis issues
This commit is contained in:
Tanay Neotia
2023-01-31 14:46:18 -05:00
committed by GitHub
parent 7bf95f41e4
commit 0e22aca785
12 changed files with 437 additions and 2 deletions

View File

@@ -0,0 +1,73 @@
// 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.
// Flutter code sample for EditableText.onContentInserted
import 'dart:typed_data';
import 'package:flutter/material.dart';
void main() => runApp(const KeyboardInsertedContentApp());
class KeyboardInsertedContentApp extends StatelessWidget {
const KeyboardInsertedContentApp({super.key});
static const String _title = 'Keyboard Inserted Content Sample';
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: _title,
home: KeyboardInsertedContentDemo(),
);
}
}
class KeyboardInsertedContentDemo extends StatefulWidget {
const KeyboardInsertedContentDemo({super.key});
@override
State<KeyboardInsertedContentDemo> createState() => _KeyboardInsertedContentDemoState();
}
class _KeyboardInsertedContentDemoState extends State<KeyboardInsertedContentDemo> {
final TextEditingController _controller = TextEditingController();
Uint8List? bytes;
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Keyboard Inserted Content Sample')),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text("Here's a text field that supports inserting only png or gif content:"),
TextField(
controller: _controller,
contentInsertionConfiguration: ContentInsertionConfiguration(
allowedMimeTypes: const <String>['image/png', 'image/gif'],
onContentInserted: (KeyboardInsertedContent data) async {
if (data.data != null) {
setState(() {
bytes = data.data;
});
}
},
),
),
if (bytes != null)
const Text("Here's the most recently inserted content:"),
if (bytes != null)
Image.memory(bytes!),
],
),
);
}
}