From 4f044e2b0925634199442f98930ca8f3760ec306 Mon Sep 17 00:00:00 2001 From: singerdmx Date: Sun, 21 Feb 2021 06:33:50 -0800 Subject: [PATCH] Rename uploadFileCallback to onImagePickCallback --- README.md | 4 ++-- app/lib/pages/home_page.dart | 3 ++- app/pubspec.lock | 4 ++-- example/main.dart | 2 +- lib/widgets/text_line.dart | 2 +- lib/widgets/toolbar.dart | 20 ++++++++++---------- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 4b03b0ac..b8f8b6be 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ and then embed the toolbar and the editor, within your app. For example: Column( children: [ QuillToolbar.basic( - controller: _controller, uploadFileCallback: _uploadImageCallBack), + controller: _controller, onImageTapCallBack: _uploadImageCallBack), Expanded( child: Container( child: QuillEditor.basic( @@ -65,7 +65,7 @@ _controller = QuillController( ## Configuration -The `QuillToolbar` class lets you customise which formating options are available. To prevent the image uploading widget from appearing, set `uploadFileCallback` to null. +The `QuillToolbar` class lets you customise which formatting options are available. To prevent the image uploading widget from appearing, set `onImageTapCallBack` to null. ## Web diff --git a/app/lib/pages/home_page.dart b/app/lib/pages/home_page.dart index dafa4859..fe8c101b 100644 --- a/app/lib/pages/home_page.dart +++ b/app/lib/pages/home_page.dart @@ -125,12 +125,13 @@ class _HomePageState extends State { Container( child: QuillToolbar.basic( controller: _controller, - uploadFileCallback: _fakeUploadImageCallBack), + onImageTapCallBack: _fakeUploadImageCallBack), ) ], ); } + /// Upload the image file to AWS s3 when image is picked Future _fakeUploadImageCallBack(File file) async { print(file); var completer = new Completer(); diff --git a/app/pubspec.lock b/app/pubspec.lock index 66f4b1e0..ec94357a 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -103,7 +103,7 @@ packages: path: ".." relative: true source: path - version: "0.2.9" + version: "0.2.12" flutter_test: dependency: "direct dev" description: flutter @@ -141,7 +141,7 @@ packages: name: image_picker url: "https://pub.dartlang.org" source: hosted - version: "0.6.7+17" + version: "0.6.7+22" image_picker_platform_interface: dependency: transitive description: diff --git a/example/main.dart b/example/main.dart index b79b35e5..c10e3a7b 100644 --- a/example/main.dart +++ b/example/main.dart @@ -20,7 +20,7 @@ class _HomePageState extends State { body: Column( children: [ QuillToolbar.basic( - controller: _controller, uploadFileCallback: _uploadImageCallBack), + controller: _controller, onImageTapCallBack: _uploadImageCallBack), Expanded( child: Container( child: QuillEditor.basic( diff --git a/lib/widgets/text_line.dart b/lib/widgets/text_line.dart index 986cf762..8608e69b 100644 --- a/lib/widgets/text_line.dart +++ b/lib/widgets/text_line.dart @@ -48,7 +48,7 @@ class TextLine extends StatelessWidget { StrutStyle.fromTextStyle(textSpan.style, forceStrutHeight: true); final textAlign = _getTextAlign(); RichText child = RichText( - text: textSpan, + text: TextSpan(children: [textSpan]), textAlign: textAlign, textDirection: textDirection, strutStyle: strutStyle, diff --git a/lib/widgets/toolbar.dart b/lib/widgets/toolbar.dart index 69de725a..a05fde04 100644 --- a/lib/widgets/toolbar.dart +++ b/lib/widgets/toolbar.dart @@ -14,7 +14,7 @@ import 'controller.dart'; double iconSize = 18.0; double kToolbarHeight = iconSize * 2; -typedef UploadFileCallback = Future Function(File file); +typedef OnImagePickCallback = Future Function(File file); class InsertEmbedButton extends StatelessWidget { final QuillController controller; @@ -490,7 +490,7 @@ class ImageButton extends StatefulWidget { final QuillController controller; - final UploadFileCallback uploadFileCallback; + final OnImagePickCallback onImagePickCallback; final ImageSource imageSource; @@ -499,7 +499,7 @@ class ImageButton extends StatefulWidget { @required this.icon, @required this.controller, @required this.imageSource, - this.uploadFileCallback}) + this.onImagePickCallback}) : assert(icon != null), assert(controller != null), super(key: key); @@ -515,10 +515,10 @@ class _ImageButtonState extends State { final PickedFile pickedFile = await _picker.getImage(source: source); final File file = File(pickedFile.path); - if (file == null || widget.uploadFileCallback == null) return null; + if (file == null || widget.onImagePickCallback == null) return null; // We simply return the absolute path to selected file. try { - String url = await widget.uploadFileCallback(file); + String url = await widget.onImagePickCallback(file); print('Image uploaded and its url is $url'); return url; } catch (error) { @@ -891,7 +891,7 @@ class QuillToolbar extends StatefulWidget implements PreferredSizeWidget { bool showLink = true, bool showHistory = true, bool showHorizontalRule = false, - UploadFileCallback uploadFileCallback}) { + OnImagePickCallback onImageTapCallBack}) { iconSize = toolbarIconSize; return QuillToolbar(key: key, children: [ Visibility( @@ -974,22 +974,22 @@ class QuillToolbar extends StatefulWidget implements PreferredSizeWidget { ), SizedBox(width: 0.6), Visibility( - visible: uploadFileCallback != null, + visible: onImageTapCallBack != null, child: ImageButton( icon: Icons.image, controller: controller, imageSource: ImageSource.gallery, - uploadFileCallback: uploadFileCallback, + onImagePickCallback: onImageTapCallBack, ), ), SizedBox(width: 0.6), Visibility( - visible: uploadFileCallback != null, + visible: onImageTapCallBack != null, child: ImageButton( icon: Icons.photo_camera, controller: controller, imageSource: ImageSource.camera, - uploadFileCallback: uploadFileCallback, + onImagePickCallback: onImageTapCallBack, ), ), Visibility(