From 378c9654d5098f30d76d13462cf51517275a2cc9 Mon Sep 17 00:00:00 2001 From: Miller Adulu Date: Sat, 13 Mar 2021 14:20:58 +0300 Subject: [PATCH] Migrate app to null safety --- app/lib/pages/home_page.dart | 15 +++--- app/lib/pages/read_only_page.dart | 4 +- app/lib/widgets/demo_scaffold.dart | 16 +++---- app/lib/widgets/field.dart | 50 +++++++++---------- app/pubspec.lock | 77 +++--------------------------- app/pubspec.yaml | 2 +- 6 files changed, 50 insertions(+), 114 deletions(-) diff --git a/app/lib/pages/home_page.dart b/app/lib/pages/home_page.dart index 60a42a64..f7299805 100644 --- a/app/lib/pages/home_page.dart +++ b/app/lib/pages/home_page.dart @@ -23,7 +23,7 @@ class HomePage extends StatefulWidget { } class _HomePageState extends State { - QuillController _controller; + QuillController? _controller; final FocusNode _focusNode = FocusNode(); @override @@ -75,15 +75,15 @@ class _HomePageState extends State { focusNode: FocusNode(), onKey: (RawKeyEvent event) { if (event.data.isControlPressed && event.character == 'b') { - if (_controller + if (_controller! .getSelectionStyle() .attributes .keys .contains("bold")) { - _controller + _controller! .formatSelection(Attribute.clone(Attribute.bold, null)); } else { - _controller.formatSelection(Attribute.bold); + _controller!.formatSelection(Attribute.bold); print("not bold"); } } @@ -104,7 +104,7 @@ class _HomePageState extends State { color: Colors.white, padding: const EdgeInsets.only(left: 16.0, right: 16.0), child: QuillEditor( - controller: _controller, + controller: _controller!, scrollController: ScrollController(), scrollable: true, focusNode: _focusNode, @@ -135,12 +135,12 @@ class _HomePageState extends State { child: Container( padding: EdgeInsets.symmetric(vertical: 16, horizontal: 8), child: QuillToolbar.basic( - controller: _controller, + controller: _controller!, onImagePickCallback: _onImagePickCallback), )) : Container( child: QuillToolbar.basic( - controller: _controller, + controller: _controller!, onImagePickCallback: _onImagePickCallback), ), ], @@ -151,7 +151,6 @@ class _HomePageState extends State { // Renders the image picked by imagePicker from local file storage // You can also upload the picked image to any server (eg : AWS s3 or Firebase) and then return the uploaded image URL Future _onImagePickCallback(File file) async { - if (file == null) return null; // Copies the picked file from temporary cache to applications directory Directory appDocDir = await getApplicationDocumentsDirectory(); File copiedFile = diff --git a/app/lib/pages/read_only_page.dart b/app/lib/pages/read_only_page.dart index c72313ad..8f03d45c 100644 --- a/app/lib/pages/read_only_page.dart +++ b/app/lib/pages/read_only_page.dart @@ -27,7 +27,7 @@ class _ReadOnlyPageState extends State { ); } - Widget _buildContent(BuildContext context, QuillController controller) { + Widget _buildContent(BuildContext context, QuillController? controller) { return Padding( padding: const EdgeInsets.all(8.0), child: Container( @@ -36,7 +36,7 @@ class _ReadOnlyPageState extends State { border: Border.all(color: Colors.grey.shade200), ), child: QuillEditor( - controller: controller, + controller: controller!, scrollController: ScrollController(), scrollable: true, focusNode: _focusNode, diff --git a/app/lib/widgets/demo_scaffold.dart b/app/lib/widgets/demo_scaffold.dart index 3caa00d5..1533da28 100644 --- a/app/lib/widgets/demo_scaffold.dart +++ b/app/lib/widgets/demo_scaffold.dart @@ -7,21 +7,21 @@ import 'package:flutter_quill/widgets/controller.dart'; import 'package:flutter_quill/widgets/toolbar.dart'; typedef DemoContentBuilder = Widget Function( - BuildContext context, QuillController controller); + BuildContext context, QuillController? controller); // Common scaffold for all examples. class DemoScaffold extends StatefulWidget { /// Filename of the document to load into the editor. final String documentFilename; final DemoContentBuilder builder; - final List actions; - final Widget floatingActionButton; + final List? actions; + final Widget? floatingActionButton; final bool showToolbar; const DemoScaffold({ - Key key, - @required this.documentFilename, - @required this.builder, + Key? key, + required this.documentFilename, + required this.builder, this.actions, this.showToolbar = true, this.floatingActionButton, @@ -33,7 +33,7 @@ class DemoScaffold extends StatefulWidget { class _DemoScaffoldState extends State { final _scaffoldKey = GlobalKey(); - QuillController _controller; + QuillController? _controller; bool _loading = false; @@ -92,7 +92,7 @@ class _DemoScaffoldState extends State { ), title: _loading || widget.showToolbar == false ? null - : QuillToolbar.basic(controller: _controller), + : QuillToolbar.basic(controller: _controller!), actions: actions, ), floatingActionButton: widget.floatingActionButton, diff --git a/app/lib/widgets/field.dart b/app/lib/widgets/field.dart index dd8b4bf4..35e710f2 100644 --- a/app/lib/widgets/field.dart +++ b/app/lib/widgets/field.dart @@ -6,28 +6,28 @@ import 'package:flutter_quill/widgets/editor.dart'; class QuillField extends StatefulWidget { final QuillController controller; - final FocusNode focusNode; - final ScrollController scrollController; + final FocusNode? focusNode; + final ScrollController? scrollController; final bool scrollable; final EdgeInsetsGeometry padding; final bool autofocus; final bool showCursor; final bool readOnly; final bool enableInteractiveSelection; - final double minHeight; - final double maxHeight; + final double? minHeight; + final double? maxHeight; final bool expands; final TextCapitalization textCapitalization; final Brightness keyboardAppearance; - final ScrollPhysics scrollPhysics; - final ValueChanged onLaunchUrl; - final InputDecoration decoration; - final Widget toolbar; - final EmbedBuilder embedBuilder; + final ScrollPhysics? scrollPhysics; + final ValueChanged? onLaunchUrl; + final InputDecoration? decoration; + final Widget? toolbar; + final EmbedBuilder? embedBuilder; QuillField({ - Key key, - @required this.controller, + Key? key, + required this.controller, this.focusNode, this.scrollController, this.scrollable = true, @@ -53,28 +53,28 @@ class QuillField extends StatefulWidget { } class _QuillFieldState extends State { - bool _focused; + late bool _focused; void _editorFocusChanged() { setState(() { - _focused = widget.focusNode.hasFocus; + _focused = widget.focusNode!.hasFocus; }); } @override void initState() { super.initState(); - _focused = widget.focusNode.hasFocus; - widget.focusNode.addListener(_editorFocusChanged); + _focused = widget.focusNode!.hasFocus; + widget.focusNode!.addListener(_editorFocusChanged); } @override void didUpdateWidget(covariant QuillField oldWidget) { super.didUpdateWidget(oldWidget); if (widget.focusNode != oldWidget.focusNode) { - oldWidget.focusNode.removeListener(_editorFocusChanged); - widget.focusNode.addListener(_editorFocusChanged); - _focused = widget.focusNode.hasFocus; + oldWidget.focusNode!.removeListener(_editorFocusChanged); + widget.focusNode!.addListener(_editorFocusChanged); + _focused = widget.focusNode!.hasFocus; } } @@ -82,8 +82,8 @@ class _QuillFieldState extends State { Widget build(BuildContext context) { Widget child = QuillEditor( controller: widget.controller, - focusNode: widget.focusNode, - scrollController: widget.scrollController, + focusNode: widget.focusNode!, + scrollController: widget.scrollController!, scrollable: widget.scrollable, padding: widget.padding, autoFocus: widget.autofocus, @@ -97,7 +97,7 @@ class _QuillFieldState extends State { keyboardAppearance: widget.keyboardAppearance, scrollPhysics: widget.scrollPhysics, onLaunchUrl: widget.onLaunchUrl, - embedBuilder: widget.embedBuilder, + embedBuilder: widget.embedBuilder!, ); if (widget.toolbar != null) { @@ -105,7 +105,7 @@ class _QuillFieldState extends State { children: [ child, Visibility( - child: widget.toolbar, + child: widget.toolbar!, visible: _focused, maintainSize: true, maintainAnimation: true, @@ -117,11 +117,11 @@ class _QuillFieldState extends State { return AnimatedBuilder( animation: - Listenable.merge([widget.focusNode, widget.controller]), - builder: (BuildContext context, Widget child) { + Listenable.merge([widget.focusNode, widget.controller]), + builder: (BuildContext context, Widget? child) { return InputDecorator( decoration: _getEffectiveDecoration(), - isFocused: widget.focusNode.hasFocus, + isFocused: widget.focusNode!.hasFocus, // TODO: Document should be considered empty of it has single empty line with no styles applied isEmpty: widget.controller.document.length == 1, child: child, diff --git a/app/pubspec.lock b/app/pubspec.lock index 116d24bf..730ceb0d 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -43,27 +43,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.15.0" - convert: - dependency: transitive - description: - name: convert - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.1" - crypto: - dependency: transitive - description: - name: crypto - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.5" - csslib: - dependency: transitive - description: - name: csslib - url: "https://pub.dartlang.org" - source: hosted - version: "0.16.2" cupertino_icons: dependency: "direct main" description: @@ -110,7 +89,7 @@ packages: name: flutter_colorpicker url: "https://pub.dartlang.org" source: hosted - version: "0.3.5" + version: "0.4.0-nullsafety.0" flutter_keyboard_visibility: dependency: transitive description: @@ -156,13 +135,6 @@ packages: description: flutter source: sdk version: "0.0.0" - html: - dependency: transitive - description: - name: html - url: "https://pub.dartlang.org" - source: hosted - version: "0.14.0+4" http: dependency: transitive description: @@ -183,7 +155,7 @@ packages: name: image_picker url: "https://pub.dartlang.org" source: hosted - version: "0.7.2" + version: "0.7.2+1" image_picker_platform_interface: dependency: transitive description: @@ -267,7 +239,7 @@ packages: name: photo_view url: "https://pub.dartlang.org" source: hosted - version: "0.10.3" + version: "0.11.1" platform: dependency: transitive description: @@ -295,14 +267,7 @@ packages: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "2.1.5" - quiver_hashcode: - dependency: transitive - description: - name: quiver_hashcode - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.0" + version: "3.0.0" sky_engine: dependency: transitive description: flutter @@ -342,7 +307,7 @@ packages: name: string_validator url: "https://pub.dartlang.org" source: hosted - version: "0.1.4" + version: "0.2.0-nullsafety.0" term_glyph: dependency: transitive description: @@ -363,7 +328,7 @@ packages: name: tuple url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "2.0.0" typed_data: dependency: transitive description: @@ -371,27 +336,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.0" - universal_html: - dependency: transitive - description: - name: universal_html - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.4" - universal_io: - dependency: transitive - description: - name: universal_io - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.2" - universal_ui: - dependency: transitive - description: - name: universal_ui - url: "https://pub.dartlang.org" - source: hosted - version: "0.0.8" url_launcher: dependency: transitive description: @@ -455,13 +399,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.2.0" - zone_local: - dependency: transitive - description: - name: zone_local - url: "https://pub.dartlang.org" - source: hosted - version: "0.1.2" sdks: dart: ">=2.12.0 <3.0.0" - flutter: ">=1.22.0" + flutter: ">=1.24.0-10.2.pre" diff --git a/app/pubspec.yaml b/app/pubspec.yaml index 8858a8dc..3a31d347 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev version: 1.0.0+1 environment: - sdk: ">=2.7.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: flutter: