From 23cf5a724785ccb16332b61aef0df6b7e0fb52a1 Mon Sep 17 00:00:00 2001 From: Eduardo Folly Date: Thu, 11 Mar 2021 11:13:13 -0300 Subject: [PATCH] Better generics implementation. --- example/lib/advanced/base_consumer_mock.dart | 4 +-- example/lib/advanced/example_builder.dart | 2 +- example/lib/advanced/example_consumer.dart | 2 +- example/lib/advanced/example_edit.dart | 2 +- example/lib/advanced/example_list.dart | 2 +- example/lib/main.dart | 2 +- example/pubspec.lock | 2 +- example/pubspec.yaml | 2 +- lib/crud/abstract_consumer.dart | 2 +- lib/crud/abstract_edit.dart | 17 +++++------- lib/crud/abstract_list.dart | 28 +++++++++----------- lib/crud/abstract_ui_builder.dart | 2 +- lib/fields/list_field.dart | 13 ++++----- lib/fields/model_field.dart | 24 ++++++++--------- lib/fields/table_field.dart | 6 ++--- lib/folly_fields.dart | 19 ++++++++----- pubspec.yaml | 2 +- 17 files changed, 66 insertions(+), 65 deletions(-) diff --git a/example/lib/advanced/base_consumer_mock.dart b/example/lib/advanced/base_consumer_mock.dart index 309579c7..b6dfd15f 100644 --- a/example/lib/advanced/base_consumer_mock.dart +++ b/example/lib/advanced/base_consumer_mock.dart @@ -6,8 +6,8 @@ import 'package:folly_fields_example/example_model.dart'; /// /// /// -abstract class BaseConsumerMock> - extends AbstractConsumer { +abstract class BaseConsumerMock> + extends AbstractConsumer { /// /// /// diff --git a/example/lib/advanced/example_builder.dart b/example/lib/advanced/example_builder.dart index 234b8c30..7b05a5b0 100644 --- a/example/lib/advanced/example_builder.dart +++ b/example/lib/advanced/example_builder.dart @@ -7,7 +7,7 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; /// /// /// -class ExampleBuilder extends AbstractUIBuilder { +class ExampleBuilder extends AbstractUIBuilder { /// /// /// diff --git a/example/lib/advanced/example_consumer.dart b/example/lib/advanced/example_consumer.dart index d385cf45..fe60686c 100644 --- a/example/lib/advanced/example_consumer.dart +++ b/example/lib/advanced/example_consumer.dart @@ -4,7 +4,7 @@ import 'package:folly_fields_example/example_model.dart'; /// /// /// -class ExampleConsumer extends BaseConsumerMock { +class ExampleConsumer extends BaseConsumerMock { /// /// /// diff --git a/example/lib/advanced/example_edit.dart b/example/lib/advanced/example_edit.dart index c871c1cd..6faa0569 100644 --- a/example/lib/advanced/example_edit.dart +++ b/example/lib/advanced/example_edit.dart @@ -28,7 +28,7 @@ import 'package:folly_fields_example/example_model.dart'; /// /// class ExampleEdit - extends AbstractEdit { + extends AbstractEdit { /// /// /// diff --git a/example/lib/advanced/example_list.dart b/example/lib/advanced/example_list.dart index 3d858d5a..0d79acf6 100644 --- a/example/lib/advanced/example_list.dart +++ b/example/lib/advanced/example_list.dart @@ -9,7 +9,7 @@ import 'package:folly_fields_example/example_model.dart'; /// /// class ExampleList - extends AbstractList { + extends AbstractList { /// /// /// diff --git a/example/lib/main.dart b/example/lib/main.dart index 51cdfd5e..11484f9f 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -572,7 +572,7 @@ class _MyHomePageState extends State { 'blob/main/lib/fields/list_field.dart', child: // [ListField] - ListField( + ListField( enabled: edit, initialValue: list, uiBuilder: ExampleBuilder(prefix), diff --git a/example/pubspec.lock b/example/pubspec.lock index 6f7021d5..b73b3b99 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -134,7 +134,7 @@ packages: path: ".." relative: true source: path - version: "0.1.2+29" + version: "0.1.3+30" font_awesome_flutter: dependency: transitive description: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index a052b726..6b2b31ed 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -3,7 +3,7 @@ description: A new Flutter project. publish_to: 'none' -version: 0.1.2+29 +version: 0.1.3+30 environment: sdk: ">=2.12.0 <3.0.0" diff --git a/lib/crud/abstract_consumer.dart b/lib/crud/abstract_consumer.dart index 151c153b..8670a875 100644 --- a/lib/crud/abstract_consumer.dart +++ b/lib/crud/abstract_consumer.dart @@ -4,7 +4,7 @@ import 'package:folly_fields/crud/abstract_model.dart'; /// /// /// -abstract class AbstractConsumer> { +abstract class AbstractConsumer> { /// /// /// diff --git a/lib/crud/abstract_edit.dart b/lib/crud/abstract_edit.dart index e035499b..a14be2cb 100644 --- a/lib/crud/abstract_edit.dart +++ b/lib/crud/abstract_edit.dart @@ -14,10 +14,9 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; /// /// abstract class AbstractEdit< - A, - T extends AbstractModel, - UI extends AbstractUIBuilder, - C extends AbstractConsumer> extends StatefulWidget { + T extends AbstractModel, + UI extends AbstractUIBuilder, + C extends AbstractConsumer> extends StatefulWidget { final T model; final UI uiBuilder; final C? consumer; @@ -38,8 +37,7 @@ abstract class AbstractEdit< /// /// @override - _AbstractEditState createState() => - _AbstractEditState(); + _AbstractEditState createState() => _AbstractEditState(); /// /// @@ -89,10 +87,9 @@ abstract class AbstractEdit< /// /// class _AbstractEditState< - A, - T extends AbstractModel, - UI extends AbstractUIBuilder, - C extends AbstractConsumer> extends State> { + T extends AbstractModel, + UI extends AbstractUIBuilder, + C extends AbstractConsumer> extends State> { final GlobalKey _formKey = GlobalKey(); final StreamController _controller = StreamController(); diff --git a/lib/crud/abstract_list.dart b/lib/crud/abstract_list.dart index 85baab8d..738a7d50 100644 --- a/lib/crud/abstract_list.dart +++ b/lib/crud/abstract_list.dart @@ -18,10 +18,9 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; /// /// abstract class AbstractList< - A, - T extends AbstractModel, - UI extends AbstractUIBuilder, - C extends AbstractConsumer> extends AbstractRoute { + T extends AbstractModel, + UI extends AbstractUIBuilder, + C extends AbstractConsumer> extends AbstractRoute { final bool selection; final bool multipleSelection; final bool invertSelection; @@ -94,18 +93,16 @@ abstract class AbstractList< /// /// @override - _AbstractListState createState() => - _AbstractListState(); + _AbstractListState createState() => _AbstractListState(); } /// /// /// class _AbstractListState< - A, - T extends AbstractModel, - UI extends AbstractUIBuilder, - C extends AbstractConsumer> extends State> { + T extends AbstractModel, + UI extends AbstractUIBuilder, + C extends AbstractConsumer> extends State> { final GlobalKey _refreshIndicatorKey = GlobalKey(); @@ -120,7 +117,7 @@ class _AbstractListState< bool _update = false; bool _delete = false; - Map selections = {}; + Map selections = {}; final Map _qsParam = {}; @@ -293,7 +290,7 @@ class _AbstractListState< onPressed: () { showSearch( context: context, - delegate: InternalSearch( + delegate: InternalSearch( buildResultItem: _buildResultItem, canDelete: (T model) => _delete && @@ -647,10 +644,9 @@ class _AbstractListState< /// /// class InternalSearch< - A, - W extends AbstractModel, - UI extends AbstractUIBuilder, - C extends AbstractConsumer> extends SearchDelegate { + W extends AbstractModel, + UI extends AbstractUIBuilder, + C extends AbstractConsumer> extends SearchDelegate { final UI uiBuilder; final C consumer; diff --git a/lib/crud/abstract_ui_builder.dart b/lib/crud/abstract_ui_builder.dart index 4babe255..e50bac5f 100644 --- a/lib/crud/abstract_ui_builder.dart +++ b/lib/crud/abstract_ui_builder.dart @@ -5,7 +5,7 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; /// /// /// -abstract class AbstractUIBuilder> { +abstract class AbstractUIBuilder> { final String prefix; /// diff --git a/lib/fields/list_field.dart b/lib/fields/list_field.dart index f27d6fe1..ae88b79a 100644 --- a/lib/fields/list_field.dart +++ b/lib/fields/list_field.dart @@ -10,8 +10,8 @@ import 'package:sprintf/sprintf.dart'; /// /// TODO - Create controller. /// -class ListField, - UI extends AbstractUIBuilder> extends FormField> { +class ListField, + UI extends AbstractUIBuilder> extends FormField> { /// /// /// @@ -82,7 +82,7 @@ class ListField, .asMap() .entries .map( - (MapEntry entry) => _MyListTile( + (MapEntry entry) => _MyListTile( index: entry.key, model: entry.value, uiBuilder: uiBuilder, @@ -151,7 +151,8 @@ class ListField, } } } else { - if ((selected as AbstractModel).id == null || + if ((selected as AbstractModel).id == + null || !field.value!.any((T element) { return element.id == selected.id; })) { @@ -177,8 +178,8 @@ class ListField, /// /// /// -class _MyListTile, - UI extends AbstractUIBuilder> extends StatelessWidget { +class _MyListTile, + UI extends AbstractUIBuilder> extends StatelessWidget { final int index; final T model; final UI uiBuilder; diff --git a/lib/fields/model_field.dart b/lib/fields/model_field.dart index e37e25b1..ed2ed6ff 100644 --- a/lib/fields/model_field.dart +++ b/lib/fields/model_field.dart @@ -5,8 +5,8 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; /// /// /// -class ModelField> extends FormField { - final ModelEditingController? controller; +class ModelField> extends FormField { + final ModelEditingController? controller; /// /// @@ -40,7 +40,7 @@ class ModelField> extends FormField { enabled: enabled, autovalidateMode: autoValidateMode, builder: (FormFieldState field) { - final _ModelFieldState state = field as _ModelFieldState; + final _ModelFieldState state = field as _ModelFieldState; final InputDecoration effectiveDecoration = InputDecoration( border: OutlineInputBorder(), @@ -130,25 +130,25 @@ class ModelField> extends FormField { /// /// @override - _ModelFieldState createState() => _ModelFieldState(); + _ModelFieldState createState() => _ModelFieldState(); } /// /// /// -class _ModelFieldState> extends FormFieldState { - ModelEditingController? _controller; +class _ModelFieldState> extends FormFieldState { + ModelEditingController? _controller; /// /// /// @override - ModelField get widget => super.widget as ModelField; + ModelField get widget => super.widget as ModelField; /// /// /// - ModelEditingController get _effectiveController => + ModelEditingController get _effectiveController => widget.controller ?? _controller!; /// @@ -158,7 +158,7 @@ class _ModelFieldState> extends FormFieldState void initState() { super.initState(); if (widget.controller == null) { - _controller = ModelEditingController(model: widget.initialValue); + _controller = ModelEditingController(model: widget.initialValue); } else { widget.controller!.addListener(_handleControllerChanged); } @@ -168,7 +168,7 @@ class _ModelFieldState> extends FormFieldState /// /// @override - void didUpdateWidget(ModelField oldWidget) { + void didUpdateWidget(ModelField oldWidget) { super.didUpdateWidget(oldWidget); if (widget.controller != oldWidget.controller) { oldWidget.controller?.removeListener(_handleControllerChanged); @@ -176,7 +176,7 @@ class _ModelFieldState> extends FormFieldState widget.controller?.addListener(_handleControllerChanged); if (oldWidget.controller != null && widget.controller == null) { - _controller = ModelEditingController( + _controller = ModelEditingController( model: oldWidget.controller!.model, ); } @@ -233,7 +233,7 @@ class _ModelFieldState> extends FormFieldState /// /// /// -class ModelEditingController> +class ModelEditingController> extends TextEditingController { T? _model; diff --git a/lib/fields/table_field.dart b/lib/fields/table_field.dart index 50902bc3..7c783ead 100644 --- a/lib/fields/table_field.dart +++ b/lib/fields/table_field.dart @@ -11,15 +11,15 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; /// TODO - Customize messages. /// TODO - Create controller?? /// -class TableField> extends FormField> { +class TableField> extends FormField> { /// /// /// TableField({ Key? key, required List initialValue, - required AbstractUIBuilder uiBuilder, - required AbstractConsumer consumer, + required AbstractUIBuilder uiBuilder, + required AbstractConsumer consumer, required List columns, List columnsFlex = const [], required List Function( diff --git a/lib/folly_fields.dart b/lib/folly_fields.dart index eed11a09..80d1e857 100644 --- a/lib/folly_fields.dart +++ b/lib/folly_fields.dart @@ -188,14 +188,21 @@ abstract class AbstractConfig implements _InternalConfig { _platform = RunningPlatform.IOS; } - ConnectivityResult result = await Connectivity().checkConnectivity(); + // FIXME - Problem with connectivity plugin on web. + if (isWeb) { + _online = true; + } else { + ConnectivityResult result = await Connectivity().checkConnectivity(); - _online = result != ConnectivityResult.none; - - Connectivity().onConnectivityChanged.listen((ConnectivityResult result) { _online = result != ConnectivityResult.none; - if (debug) print('Connectivity Changed: $_online'); - }); + + Connectivity() + .onConnectivityChanged + .listen((ConnectivityResult result) { + _online = result != ConnectivityResult.none; + if (debug) print('Connectivity Changed: $_online'); + }); + } } } } diff --git a/pubspec.yaml b/pubspec.yaml index e6efb3f3..fe8632f3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: folly_fields description: Basic form fields and utilities. -version: 0.1.2+29 +version: 0.1.3+30 # author: homepage: https://edufolly.github.io/folly_fields/