Migrate app to null safety

pull/87/head
Miller Adulu 4 years ago
parent d48abe8ea7
commit 378c9654d5
  1. 15
      app/lib/pages/home_page.dart
  2. 4
      app/lib/pages/read_only_page.dart
  3. 16
      app/lib/widgets/demo_scaffold.dart
  4. 50
      app/lib/widgets/field.dart
  5. 77
      app/pubspec.lock
  6. 2
      app/pubspec.yaml

@ -23,7 +23,7 @@ class HomePage extends StatefulWidget {
} }
class _HomePageState extends State<HomePage> { class _HomePageState extends State<HomePage> {
QuillController _controller; QuillController? _controller;
final FocusNode _focusNode = FocusNode(); final FocusNode _focusNode = FocusNode();
@override @override
@ -75,15 +75,15 @@ class _HomePageState extends State<HomePage> {
focusNode: FocusNode(), focusNode: FocusNode(),
onKey: (RawKeyEvent event) { onKey: (RawKeyEvent event) {
if (event.data.isControlPressed && event.character == 'b') { if (event.data.isControlPressed && event.character == 'b') {
if (_controller if (_controller!
.getSelectionStyle() .getSelectionStyle()
.attributes .attributes
.keys .keys
.contains("bold")) { .contains("bold")) {
_controller _controller!
.formatSelection(Attribute.clone(Attribute.bold, null)); .formatSelection(Attribute.clone(Attribute.bold, null));
} else { } else {
_controller.formatSelection(Attribute.bold); _controller!.formatSelection(Attribute.bold);
print("not bold"); print("not bold");
} }
} }
@ -104,7 +104,7 @@ class _HomePageState extends State<HomePage> {
color: Colors.white, color: Colors.white,
padding: const EdgeInsets.only(left: 16.0, right: 16.0), padding: const EdgeInsets.only(left: 16.0, right: 16.0),
child: QuillEditor( child: QuillEditor(
controller: _controller, controller: _controller!,
scrollController: ScrollController(), scrollController: ScrollController(),
scrollable: true, scrollable: true,
focusNode: _focusNode, focusNode: _focusNode,
@ -135,12 +135,12 @@ class _HomePageState extends State<HomePage> {
child: Container( child: Container(
padding: EdgeInsets.symmetric(vertical: 16, horizontal: 8), padding: EdgeInsets.symmetric(vertical: 16, horizontal: 8),
child: QuillToolbar.basic( child: QuillToolbar.basic(
controller: _controller, controller: _controller!,
onImagePickCallback: _onImagePickCallback), onImagePickCallback: _onImagePickCallback),
)) ))
: Container( : Container(
child: QuillToolbar.basic( child: QuillToolbar.basic(
controller: _controller, controller: _controller!,
onImagePickCallback: _onImagePickCallback), onImagePickCallback: _onImagePickCallback),
), ),
], ],
@ -151,7 +151,6 @@ class _HomePageState extends State<HomePage> {
// Renders the image picked by imagePicker from local file storage // 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 // You can also upload the picked image to any server (eg : AWS s3 or Firebase) and then return the uploaded image URL
Future<String> _onImagePickCallback(File file) async { Future<String> _onImagePickCallback(File file) async {
if (file == null) return null;
// Copies the picked file from temporary cache to applications directory // Copies the picked file from temporary cache to applications directory
Directory appDocDir = await getApplicationDocumentsDirectory(); Directory appDocDir = await getApplicationDocumentsDirectory();
File copiedFile = File copiedFile =

@ -27,7 +27,7 @@ class _ReadOnlyPageState extends State<ReadOnlyPage> {
); );
} }
Widget _buildContent(BuildContext context, QuillController controller) { Widget _buildContent(BuildContext context, QuillController? controller) {
return Padding( return Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: Container( child: Container(
@ -36,7 +36,7 @@ class _ReadOnlyPageState extends State<ReadOnlyPage> {
border: Border.all(color: Colors.grey.shade200), border: Border.all(color: Colors.grey.shade200),
), ),
child: QuillEditor( child: QuillEditor(
controller: controller, controller: controller!,
scrollController: ScrollController(), scrollController: ScrollController(),
scrollable: true, scrollable: true,
focusNode: _focusNode, focusNode: _focusNode,

@ -7,21 +7,21 @@ import 'package:flutter_quill/widgets/controller.dart';
import 'package:flutter_quill/widgets/toolbar.dart'; import 'package:flutter_quill/widgets/toolbar.dart';
typedef DemoContentBuilder = Widget Function( typedef DemoContentBuilder = Widget Function(
BuildContext context, QuillController controller); BuildContext context, QuillController? controller);
// Common scaffold for all examples. // Common scaffold for all examples.
class DemoScaffold extends StatefulWidget { class DemoScaffold extends StatefulWidget {
/// Filename of the document to load into the editor. /// Filename of the document to load into the editor.
final String documentFilename; final String documentFilename;
final DemoContentBuilder builder; final DemoContentBuilder builder;
final List<Widget> actions; final List<Widget>? actions;
final Widget floatingActionButton; final Widget? floatingActionButton;
final bool showToolbar; final bool showToolbar;
const DemoScaffold({ const DemoScaffold({
Key key, Key? key,
@required this.documentFilename, required this.documentFilename,
@required this.builder, required this.builder,
this.actions, this.actions,
this.showToolbar = true, this.showToolbar = true,
this.floatingActionButton, this.floatingActionButton,
@ -33,7 +33,7 @@ class DemoScaffold extends StatefulWidget {
class _DemoScaffoldState extends State<DemoScaffold> { class _DemoScaffoldState extends State<DemoScaffold> {
final _scaffoldKey = GlobalKey<ScaffoldState>(); final _scaffoldKey = GlobalKey<ScaffoldState>();
QuillController _controller; QuillController? _controller;
bool _loading = false; bool _loading = false;
@ -92,7 +92,7 @@ class _DemoScaffoldState extends State<DemoScaffold> {
), ),
title: _loading || widget.showToolbar == false title: _loading || widget.showToolbar == false
? null ? null
: QuillToolbar.basic(controller: _controller), : QuillToolbar.basic(controller: _controller!),
actions: actions, actions: actions,
), ),
floatingActionButton: widget.floatingActionButton, floatingActionButton: widget.floatingActionButton,

@ -6,28 +6,28 @@ import 'package:flutter_quill/widgets/editor.dart';
class QuillField extends StatefulWidget { class QuillField extends StatefulWidget {
final QuillController controller; final QuillController controller;
final FocusNode focusNode; final FocusNode? focusNode;
final ScrollController scrollController; final ScrollController? scrollController;
final bool scrollable; final bool scrollable;
final EdgeInsetsGeometry padding; final EdgeInsetsGeometry padding;
final bool autofocus; final bool autofocus;
final bool showCursor; final bool showCursor;
final bool readOnly; final bool readOnly;
final bool enableInteractiveSelection; final bool enableInteractiveSelection;
final double minHeight; final double? minHeight;
final double maxHeight; final double? maxHeight;
final bool expands; final bool expands;
final TextCapitalization textCapitalization; final TextCapitalization textCapitalization;
final Brightness keyboardAppearance; final Brightness keyboardAppearance;
final ScrollPhysics scrollPhysics; final ScrollPhysics? scrollPhysics;
final ValueChanged<String> onLaunchUrl; final ValueChanged<String>? onLaunchUrl;
final InputDecoration decoration; final InputDecoration? decoration;
final Widget toolbar; final Widget? toolbar;
final EmbedBuilder embedBuilder; final EmbedBuilder? embedBuilder;
QuillField({ QuillField({
Key key, Key? key,
@required this.controller, required this.controller,
this.focusNode, this.focusNode,
this.scrollController, this.scrollController,
this.scrollable = true, this.scrollable = true,
@ -53,28 +53,28 @@ class QuillField extends StatefulWidget {
} }
class _QuillFieldState extends State<QuillField> { class _QuillFieldState extends State<QuillField> {
bool _focused; late bool _focused;
void _editorFocusChanged() { void _editorFocusChanged() {
setState(() { setState(() {
_focused = widget.focusNode.hasFocus; _focused = widget.focusNode!.hasFocus;
}); });
} }
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_focused = widget.focusNode.hasFocus; _focused = widget.focusNode!.hasFocus;
widget.focusNode.addListener(_editorFocusChanged); widget.focusNode!.addListener(_editorFocusChanged);
} }
@override @override
void didUpdateWidget(covariant QuillField oldWidget) { void didUpdateWidget(covariant QuillField oldWidget) {
super.didUpdateWidget(oldWidget); super.didUpdateWidget(oldWidget);
if (widget.focusNode != oldWidget.focusNode) { if (widget.focusNode != oldWidget.focusNode) {
oldWidget.focusNode.removeListener(_editorFocusChanged); oldWidget.focusNode!.removeListener(_editorFocusChanged);
widget.focusNode.addListener(_editorFocusChanged); widget.focusNode!.addListener(_editorFocusChanged);
_focused = widget.focusNode.hasFocus; _focused = widget.focusNode!.hasFocus;
} }
} }
@ -82,8 +82,8 @@ class _QuillFieldState extends State<QuillField> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
Widget child = QuillEditor( Widget child = QuillEditor(
controller: widget.controller, controller: widget.controller,
focusNode: widget.focusNode, focusNode: widget.focusNode!,
scrollController: widget.scrollController, scrollController: widget.scrollController!,
scrollable: widget.scrollable, scrollable: widget.scrollable,
padding: widget.padding, padding: widget.padding,
autoFocus: widget.autofocus, autoFocus: widget.autofocus,
@ -97,7 +97,7 @@ class _QuillFieldState extends State<QuillField> {
keyboardAppearance: widget.keyboardAppearance, keyboardAppearance: widget.keyboardAppearance,
scrollPhysics: widget.scrollPhysics, scrollPhysics: widget.scrollPhysics,
onLaunchUrl: widget.onLaunchUrl, onLaunchUrl: widget.onLaunchUrl,
embedBuilder: widget.embedBuilder, embedBuilder: widget.embedBuilder!,
); );
if (widget.toolbar != null) { if (widget.toolbar != null) {
@ -105,7 +105,7 @@ class _QuillFieldState extends State<QuillField> {
children: [ children: [
child, child,
Visibility( Visibility(
child: widget.toolbar, child: widget.toolbar!,
visible: _focused, visible: _focused,
maintainSize: true, maintainSize: true,
maintainAnimation: true, maintainAnimation: true,
@ -117,11 +117,11 @@ class _QuillFieldState extends State<QuillField> {
return AnimatedBuilder( return AnimatedBuilder(
animation: animation:
Listenable.merge(<Listenable>[widget.focusNode, widget.controller]), Listenable.merge(<Listenable?>[widget.focusNode, widget.controller]),
builder: (BuildContext context, Widget child) { builder: (BuildContext context, Widget? child) {
return InputDecorator( return InputDecorator(
decoration: _getEffectiveDecoration(), 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 // TODO: Document should be considered empty of it has single empty line with no styles applied
isEmpty: widget.controller.document.length == 1, isEmpty: widget.controller.document.length == 1,
child: child, child: child,

@ -43,27 +43,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.15.0" 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: cupertino_icons:
dependency: "direct main" dependency: "direct main"
description: description:
@ -110,7 +89,7 @@ packages:
name: flutter_colorpicker name: flutter_colorpicker
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.3.5" version: "0.4.0-nullsafety.0"
flutter_keyboard_visibility: flutter_keyboard_visibility:
dependency: transitive dependency: transitive
description: description:
@ -156,13 +135,6 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
html:
dependency: transitive
description:
name: html
url: "https://pub.dartlang.org"
source: hosted
version: "0.14.0+4"
http: http:
dependency: transitive dependency: transitive
description: description:
@ -183,7 +155,7 @@ packages:
name: image_picker name: image_picker
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.7.2" version: "0.7.2+1"
image_picker_platform_interface: image_picker_platform_interface:
dependency: transitive dependency: transitive
description: description:
@ -267,7 +239,7 @@ packages:
name: photo_view name: photo_view
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.10.3" version: "0.11.1"
platform: platform:
dependency: transitive dependency: transitive
description: description:
@ -295,14 +267,7 @@ packages:
name: quiver name: quiver
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.5" version: "3.0.0"
quiver_hashcode:
dependency: transitive
description:
name: quiver_hashcode
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter
@ -342,7 +307,7 @@ packages:
name: string_validator name: string_validator
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.1.4" version: "0.2.0-nullsafety.0"
term_glyph: term_glyph:
dependency: transitive dependency: transitive
description: description:
@ -363,7 +328,7 @@ packages:
name: tuple name: tuple
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.3" version: "2.0.0"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:
@ -371,27 +336,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.3.0" 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: url_launcher:
dependency: transitive dependency: transitive
description: description:
@ -455,13 +399,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.2.0" version: "0.2.0"
zone_local:
dependency: transitive
description:
name: zone_local
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.2"
sdks: sdks:
dart: ">=2.12.0 <3.0.0" dart: ">=2.12.0 <3.0.0"
flutter: ">=1.22.0" flutter: ">=1.24.0-10.2.pre"

@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1 version: 1.0.0+1
environment: environment:
sdk: ">=2.7.0 <3.0.0" sdk: '>=2.12.0 <3.0.0'
dependencies: dependencies:
flutter: flutter:

Loading…
Cancel
Save