Skip to content

Commit

Permalink
Better generics implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
edufolly committed Mar 11, 2021
1 parent 42fd418 commit 23cf5a7
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 65 deletions.
4 changes: 2 additions & 2 deletions example/lib/advanced/base_consumer_mock.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import 'package:folly_fields_example/example_model.dart';
///
///
///
abstract class BaseConsumerMock<A, T extends AbstractModel<A>>
extends AbstractConsumer<A, T> {
abstract class BaseConsumerMock<T extends AbstractModel<Object>>
extends AbstractConsumer<T> {
///
///
///
Expand Down
2 changes: 1 addition & 1 deletion example/lib/advanced/example_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
///
///
///
class ExampleBuilder extends AbstractUIBuilder<int, ExampleModel> {
class ExampleBuilder extends AbstractUIBuilder<ExampleModel> {
///
///
///
Expand Down
2 changes: 1 addition & 1 deletion example/lib/advanced/example_consumer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:folly_fields_example/example_model.dart';
///
///
///
class ExampleConsumer extends BaseConsumerMock<int, ExampleModel> {
class ExampleConsumer extends BaseConsumerMock<ExampleModel> {
///
///
///
Expand Down
2 changes: 1 addition & 1 deletion example/lib/advanced/example_edit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import 'package:folly_fields_example/example_model.dart';
///
///
class ExampleEdit
extends AbstractEdit<int, ExampleModel, ExampleBuilder, ExampleConsumer> {
extends AbstractEdit<ExampleModel, ExampleBuilder, ExampleConsumer> {
///
///
///
Expand Down
2 changes: 1 addition & 1 deletion example/lib/advanced/example_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:folly_fields_example/example_model.dart';
///
///
class ExampleList
extends AbstractList<int, ExampleModel, ExampleBuilder, ExampleConsumer> {
extends AbstractList<ExampleModel, ExampleBuilder, ExampleConsumer> {
///
///
///
Expand Down
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ class _MyHomePageState extends State<MyHomePage> {
'blob/main/lib/fields/list_field.dart',
child:
// [ListField]
ListField<int, ExampleModel, ExampleBuilder>(
ListField<ExampleModel, ExampleBuilder>(
enabled: edit,
initialValue: list,
uiBuilder: ExampleBuilder(prefix),
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lib/crud/abstract_consumer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:folly_fields/crud/abstract_model.dart';
///
///
///
abstract class AbstractConsumer<A, T extends AbstractModel<A>> {
abstract class AbstractConsumer<T extends AbstractModel<Object>> {
///
///
///
Expand Down
17 changes: 7 additions & 10 deletions lib/crud/abstract_edit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
///
///
abstract class AbstractEdit<
A,
T extends AbstractModel<A>,
UI extends AbstractUIBuilder<A, T>,
C extends AbstractConsumer<A, T>> extends StatefulWidget {
T extends AbstractModel<Object>,
UI extends AbstractUIBuilder<T>,
C extends AbstractConsumer<T>> extends StatefulWidget {
final T model;
final UI uiBuilder;
final C? consumer;
Expand All @@ -38,8 +37,7 @@ abstract class AbstractEdit<
///
///
@override
_AbstractEditState<A, T, UI, C> createState() =>
_AbstractEditState<A, T, UI, C>();
_AbstractEditState<T, UI, C> createState() => _AbstractEditState<T, UI, C>();

///
///
Expand Down Expand Up @@ -89,10 +87,9 @@ abstract class AbstractEdit<
///
///
class _AbstractEditState<
A,
T extends AbstractModel<A>,
UI extends AbstractUIBuilder<A, T>,
C extends AbstractConsumer<A, T>> extends State<AbstractEdit<A, T, UI, C>> {
T extends AbstractModel<Object>,
UI extends AbstractUIBuilder<T>,
C extends AbstractConsumer<T>> extends State<AbstractEdit<T, UI, C>> {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();

final StreamController<bool> _controller = StreamController<bool>();
Expand Down
28 changes: 12 additions & 16 deletions lib/crud/abstract_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
///
///
abstract class AbstractList<
A,
T extends AbstractModel<A>,
UI extends AbstractUIBuilder<A, T>,
C extends AbstractConsumer<A, T>> extends AbstractRoute {
T extends AbstractModel<Object>,
UI extends AbstractUIBuilder<T>,
C extends AbstractConsumer<T>> extends AbstractRoute {
final bool selection;
final bool multipleSelection;
final bool invertSelection;
Expand Down Expand Up @@ -94,18 +93,16 @@ abstract class AbstractList<
///
///
@override
_AbstractListState<A, T, UI, C> createState() =>
_AbstractListState<A, T, UI, C>();
_AbstractListState<T, UI, C> createState() => _AbstractListState<T, UI, C>();
}

///
///
///
class _AbstractListState<
A,
T extends AbstractModel<A>,
UI extends AbstractUIBuilder<A, T>,
C extends AbstractConsumer<A, T>> extends State<AbstractList<A, T, UI, C>> {
T extends AbstractModel<Object>,
UI extends AbstractUIBuilder<T>,
C extends AbstractConsumer<T>> extends State<AbstractList<T, UI, C>> {
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
GlobalKey<RefreshIndicatorState>();

Expand All @@ -120,7 +117,7 @@ class _AbstractListState<
bool _update = false;
bool _delete = false;

Map<A, T> selections = <A, T>{};
Map<Object, T> selections = <Object, T>{};

final Map<String, String> _qsParam = <String, String>{};

Expand Down Expand Up @@ -293,7 +290,7 @@ class _AbstractListState<
onPressed: () {
showSearch<T?>(
context: context,
delegate: InternalSearch<A, T, UI, C>(
delegate: InternalSearch<T, UI, C>(
buildResultItem: _buildResultItem,
canDelete: (T model) =>
_delete &&
Expand Down Expand Up @@ -647,10 +644,9 @@ class _AbstractListState<
///
///
class InternalSearch<
A,
W extends AbstractModel<A>,
UI extends AbstractUIBuilder<A, W>,
C extends AbstractConsumer<A, W>> extends SearchDelegate<W?> {
W extends AbstractModel<Object>,
UI extends AbstractUIBuilder<W>,
C extends AbstractConsumer<W>> extends SearchDelegate<W?> {
final UI uiBuilder;
final C consumer;

Expand Down
2 changes: 1 addition & 1 deletion lib/crud/abstract_ui_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
///
///
///
abstract class AbstractUIBuilder<A, T extends AbstractModel<A>> {
abstract class AbstractUIBuilder<T extends AbstractModel<Object>> {
final String prefix;

///
Expand Down
13 changes: 7 additions & 6 deletions lib/fields/list_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import 'package:sprintf/sprintf.dart';
///
/// TODO - Create controller.
///
class ListField<A, T extends AbstractModel<A>,
UI extends AbstractUIBuilder<A, T>> extends FormField<List<T>> {
class ListField<T extends AbstractModel<Object>,
UI extends AbstractUIBuilder<T>> extends FormField<List<T>> {
///
///
///
Expand Down Expand Up @@ -82,7 +82,7 @@ class ListField<A, T extends AbstractModel<A>,
.asMap()
.entries
.map(
(MapEntry<int, T> entry) => _MyListTile<A, T, UI>(
(MapEntry<int, T> entry) => _MyListTile<T, UI>(
index: entry.key,
model: entry.value,
uiBuilder: uiBuilder,
Expand Down Expand Up @@ -151,7 +151,8 @@ class ListField<A, T extends AbstractModel<A>,
}
}
} else {
if ((selected as AbstractModel<A>).id == null ||
if ((selected as AbstractModel<Object>).id ==
null ||
!field.value!.any((T element) {
return element.id == selected.id;
})) {
Expand All @@ -177,8 +178,8 @@ class ListField<A, T extends AbstractModel<A>,
///
///
///
class _MyListTile<A, T extends AbstractModel<A>,
UI extends AbstractUIBuilder<A, T>> extends StatelessWidget {
class _MyListTile<T extends AbstractModel<Object>,
UI extends AbstractUIBuilder<T>> extends StatelessWidget {
final int index;
final T model;
final UI uiBuilder;
Expand Down
24 changes: 12 additions & 12 deletions lib/fields/model_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
///
///
///
class ModelField<A, T extends AbstractModel<A>> extends FormField<T?> {
final ModelEditingController<A, T>? controller;
class ModelField<T extends AbstractModel<Object>> extends FormField<T?> {
final ModelEditingController<T>? controller;

///
///
Expand Down Expand Up @@ -40,7 +40,7 @@ class ModelField<A, T extends AbstractModel<A>> extends FormField<T?> {
enabled: enabled,
autovalidateMode: autoValidateMode,
builder: (FormFieldState<T?> field) {
final _ModelFieldState<A, T> state = field as _ModelFieldState<A, T>;
final _ModelFieldState<T> state = field as _ModelFieldState<T>;

final InputDecoration effectiveDecoration = InputDecoration(
border: OutlineInputBorder(),
Expand Down Expand Up @@ -130,25 +130,25 @@ class ModelField<A, T extends AbstractModel<A>> extends FormField<T?> {
///
///
@override
_ModelFieldState<A, T> createState() => _ModelFieldState<A, T>();
_ModelFieldState<T> createState() => _ModelFieldState<T>();
}

///
///
///
class _ModelFieldState<A, T extends AbstractModel<A>> extends FormFieldState<T?> {
ModelEditingController<A, T>? _controller;
class _ModelFieldState<T extends AbstractModel<Object>> extends FormFieldState<T?> {
ModelEditingController<T>? _controller;

///
///
///
@override
ModelField<A, T> get widget => super.widget as ModelField<A, T>;
ModelField<T> get widget => super.widget as ModelField<T>;

///
///
///
ModelEditingController<A, T> get _effectiveController =>
ModelEditingController<T> get _effectiveController =>
widget.controller ?? _controller!;

///
Expand All @@ -158,7 +158,7 @@ class _ModelFieldState<A, T extends AbstractModel<A>> extends FormFieldState<T?>
void initState() {
super.initState();
if (widget.controller == null) {
_controller = ModelEditingController<A, T>(model: widget.initialValue);
_controller = ModelEditingController<T>(model: widget.initialValue);
} else {
widget.controller!.addListener(_handleControllerChanged);
}
Expand All @@ -168,15 +168,15 @@ class _ModelFieldState<A, T extends AbstractModel<A>> extends FormFieldState<T?>
///
///
@override
void didUpdateWidget(ModelField<A, T> oldWidget) {
void didUpdateWidget(ModelField<T> oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.controller != oldWidget.controller) {
oldWidget.controller?.removeListener(_handleControllerChanged);

widget.controller?.addListener(_handleControllerChanged);

if (oldWidget.controller != null && widget.controller == null) {
_controller = ModelEditingController<A, T>(
_controller = ModelEditingController<T>(
model: oldWidget.controller!.model,
);
}
Expand Down Expand Up @@ -233,7 +233,7 @@ class _ModelFieldState<A, T extends AbstractModel<A>> extends FormFieldState<T?>
///
///
///
class ModelEditingController<A, T extends AbstractModel<A>>
class ModelEditingController<T extends AbstractModel<Object>>
extends TextEditingController {
T? _model;

Expand Down
6 changes: 3 additions & 3 deletions lib/fields/table_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
/// TODO - Customize messages.
/// TODO - Create controller??
///
class TableField<A, T extends AbstractModel<A>> extends FormField<List<T>> {
class TableField<T extends AbstractModel<Object>> extends FormField<List<T>> {
///
///
///
TableField({
Key? key,
required List<T> initialValue,
required AbstractUIBuilder<A, T> uiBuilder,
required AbstractConsumer<A, T> consumer,
required AbstractUIBuilder<T> uiBuilder,
required AbstractConsumer<T> consumer,
required List<String> columns,
List<int> columnsFlex = const <int>[],
required List<Widget> Function(
Expand Down
19 changes: 13 additions & 6 deletions lib/folly_fields.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
}
}
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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/

Expand Down

0 comments on commit 23cf5a7

Please sign in to comment.