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> {
QuillController _controller;
QuillController? _controller;
final FocusNode _focusNode = FocusNode();
@override
@ -75,15 +75,15 @@ class _HomePageState extends State<HomePage> {
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<HomePage> {
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<HomePage> {
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<HomePage> {
// 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<String> _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 =

@ -27,7 +27,7 @@ class _ReadOnlyPageState extends State<ReadOnlyPage> {
);
}
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<ReadOnlyPage> {
border: Border.all(color: Colors.grey.shade200),
),
child: QuillEditor(
controller: controller,
controller: controller!,
scrollController: ScrollController(),
scrollable: true,
focusNode: _focusNode,

@ -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<Widget> actions;
final Widget floatingActionButton;
final List<Widget>? 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<DemoScaffold> {
final _scaffoldKey = GlobalKey<ScaffoldState>();
QuillController _controller;
QuillController? _controller;
bool _loading = false;
@ -92,7 +92,7 @@ class _DemoScaffoldState extends State<DemoScaffold> {
),
title: _loading || widget.showToolbar == false
? null
: QuillToolbar.basic(controller: _controller),
: QuillToolbar.basic(controller: _controller!),
actions: actions,
),
floatingActionButton: widget.floatingActionButton,

@ -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<String> onLaunchUrl;
final InputDecoration decoration;
final Widget toolbar;
final EmbedBuilder embedBuilder;
final ScrollPhysics? scrollPhysics;
final ValueChanged<String>? 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<QuillField> {
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<QuillField> {
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<QuillField> {
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<QuillField> {
children: [
child,
Visibility(
child: widget.toolbar,
child: widget.toolbar!,
visible: _focused,
maintainSize: true,
maintainAnimation: true,
@ -117,11 +117,11 @@ class _QuillFieldState extends State<QuillField> {
return AnimatedBuilder(
animation:
Listenable.merge(<Listenable>[widget.focusNode, widget.controller]),
builder: (BuildContext context, Widget child) {
Listenable.merge(<Listenable?>[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,

@ -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"

@ -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:

Loading…
Cancel
Save