From 0b4380d4497638f082298248899118c0c830c6d8 Mon Sep 17 00:00:00 2001 From: Eduardo Folly Date: Sun, 5 Sep 2021 20:48:53 -0300 Subject: [PATCH] Update example to flutter_lints. --- analysis_options.yaml | 10 +- example/analysis_options.yaml | 29 +++++- example/lib/advanced/base_consumer_mock.dart | 10 +- example/lib/advanced/example_builder.dart | 3 +- example/lib/advanced/example_consumer.dart | 5 + example/lib/advanced/example_edit.dart | 1 - example/lib/advanced/example_list.dart | 2 +- example/lib/code_link.dart | 16 +-- example/lib/example_table.dart | 15 ++- example/lib/main.dart | 32 +++--- example/pubspec.lock | 16 ++- example/pubspec.yaml | 6 +- lib/crud/abstract_consumer.dart | 49 ++++----- lib/crud/abstract_edit.dart | 6 +- lib/crud/abstract_list.dart | 104 +++++++++---------- lib/crud/abstract_ui_builder.dart | 8 +- lib/fields/bool_field.dart | 2 +- lib/fields/date_field.dart | 6 +- lib/fields/date_time_field.dart | 6 +- lib/fields/decimal_field.dart | 4 +- lib/fields/dropdown_field.dart | 2 +- lib/fields/icon_data_field.dart | 5 +- lib/fields/integer_field.dart | 2 +- lib/fields/list_field.dart | 6 +- lib/fields/model_field.dart | 6 +- lib/fields/multiline_field.dart | 2 +- lib/fields/password_field.dart | 4 +- lib/fields/string_field.dart | 4 +- lib/fields/table_field.dart | 8 +- lib/fields/time_field.dart | 6 +- lib/folly_fields.dart | 20 ++-- lib/widgets/add_button.dart | 2 +- lib/widgets/animated_search.dart | 4 +- lib/widgets/circular_waiting.dart | 4 +- lib/widgets/delete_button.dart | 2 +- lib/widgets/empty_button.dart | 7 +- lib/widgets/folly_dialogs.dart | 2 +- lib/widgets/folly_table.dart | 70 ++++++++----- lib/widgets/home_card.dart | 4 +- lib/widgets/waiting_message.dart | 4 +- 40 files changed, 277 insertions(+), 217 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index d1157fd7..f862b58c 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -21,14 +21,12 @@ linter: always_use_package_imports: true annotate_overrides: true # avoid_annotating_with_dynamic: true - # avoid_multiple_declarations_per_line: true - # avoid_print: true + avoid_multiple_declarations_per_line: true avoid_types_as_parameter_names: true - # camel_case_types: true + camel_case_types: true empty_constructor_bodies: true lines_longer_than_80_chars: false - # no_logic_in_create_state: true + no_logic_in_create_state: true omit_local_variable_types: false prefer_if_null_operators: true - prefer_typing_uninitialized_variables: true - # throw_in_finally: true \ No newline at end of file + prefer_typing_uninitialized_variables: true \ No newline at end of file diff --git a/example/analysis_options.yaml b/example/analysis_options.yaml index 3042a919..291c5465 100644 --- a/example/analysis_options.yaml +++ b/example/analysis_options.yaml @@ -1,14 +1,33 @@ -include: package:pedantic/analysis_options.yaml +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +analizer: + exclude: [ example/** ] + strong-mode: + implicit-casts: false linter: rules: - always_specify_types: true always_declare_return_types: true - omit_local_variable_types: false - prefer_typing_uninitialized_variables: true + always_specify_types: true always_use_package_imports: true - avoid_types_as_parameter_names: true annotate_overrides: true + # avoid_annotating_with_dynamic: true + avoid_multiple_declarations_per_line: true + avoid_print: false + avoid_types_as_parameter_names: true + camel_case_types: true empty_constructor_bodies: true lines_longer_than_80_chars: false + no_logic_in_create_state: true + omit_local_variable_types: false prefer_if_null_operators: true + prefer_typing_uninitialized_variables: true \ No newline at end of file diff --git a/example/lib/advanced/base_consumer_mock.dart b/example/lib/advanced/base_consumer_mock.dart index b6dfd15f..99a6b843 100644 --- a/example/lib/advanced/base_consumer_mock.dart +++ b/example/lib/advanced/base_consumer_mock.dart @@ -6,8 +6,14 @@ import 'package:folly_fields_example/example_model.dart'; /// /// /// +@immutable abstract class BaseConsumerMock> extends AbstractConsumer { + /// + /// + /// + const BaseConsumerMock(); + /// /// /// @@ -17,7 +23,7 @@ abstract class BaseConsumerMock> List? paths, ) => Future.value( - ConsumerPermission( + const ConsumerPermission( name: 'mock', iconName: 'question', view: true, @@ -43,7 +49,7 @@ abstract class BaseConsumerMock> int qtd = int.tryParse(qsParam['q'] ?? '50') ?? 50; return Future>.delayed( - Duration(seconds: 2), + const Duration(seconds: 2), () => List.generate( qtd, (int index) => (ExampleModel.generate(seed: first + index) as T), diff --git a/example/lib/advanced/example_builder.dart b/example/lib/advanced/example_builder.dart index 3bfcc90a..591fae4f 100644 --- a/example/lib/advanced/example_builder.dart +++ b/example/lib/advanced/example_builder.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter/src/widgets/framework.dart'; import 'package:folly_fields/crud/abstract_ui_builder.dart'; import 'package:folly_fields_example/example_model.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -11,7 +10,7 @@ class ExampleBuilder extends AbstractUIBuilder { /// /// /// - ExampleBuilder([String prefix = '']) : super(prefix); + const ExampleBuilder([String prefix = '']) : super(prefix); /// /// diff --git a/example/lib/advanced/example_consumer.dart b/example/lib/advanced/example_consumer.dart index 288ca4c2..78414b21 100644 --- a/example/lib/advanced/example_consumer.dart +++ b/example/lib/advanced/example_consumer.dart @@ -5,6 +5,11 @@ import 'package:folly_fields_example/example_model.dart'; /// /// class ExampleConsumer extends BaseConsumerMock { + /// + /// + /// + const ExampleConsumer(); + /// /// /// diff --git a/example/lib/advanced/example_edit.dart b/example/lib/advanced/example_edit.dart index 07a2e5e5..a9e686d0 100644 --- a/example/lib/advanced/example_edit.dart +++ b/example/lib/advanced/example_edit.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter/src/widgets/framework.dart'; import 'package:folly_fields/crud/abstract_edit.dart'; import 'package:folly_fields/fields/bool_field.dart'; import 'package:folly_fields/fields/cep_field.dart'; diff --git a/example/lib/advanced/example_list.dart b/example/lib/advanced/example_list.dart index 0d79acf6..c11ec5a8 100644 --- a/example/lib/advanced/example_list.dart +++ b/example/lib/advanced/example_list.dart @@ -23,7 +23,7 @@ class ExampleList selection: selection, multipleSelection: multipleSelection, forceOffline: false, - consumer: ExampleConsumer(), + consumer: const ExampleConsumer(), uiBuilder: ExampleBuilder(prefix), onAdd: ( BuildContext context, diff --git a/example/lib/code_link.dart b/example/lib/code_link.dart index 3b694380..822e8bad 100644 --- a/example/lib/code_link.dart +++ b/example/lib/code_link.dart @@ -39,7 +39,7 @@ class CodeLink extends StatelessWidget { child: child, ), IconButton( - icon: Text( + icon: const Text( '?', style: TextStyle( fontSize: 18.0, @@ -73,7 +73,7 @@ class CodeLink extends StatelessWidget { content: ClipRRect( borderRadius: BorderRadius.circular(12.0), child: Container( - padding: EdgeInsets.all(12.0), + padding: const EdgeInsets.all(12.0), color: Colors.black38, child: SingleChildScrollView( child: HighlightView( @@ -87,12 +87,12 @@ class CodeLink extends StatelessWidget { ), actions: [ ElevatedButton.icon( - label: Text('Copiar'), - icon: Icon(Icons.copy), + label: const Text('Copiar'), + icon: const Icon(Icons.copy), onPressed: () async { await Clipboard.setData(ClipboardData(text: example)); ScaffoldMessenger.of(context).showSnackBar( - SnackBar( + const SnackBar( content: Text( 'Código copiado para a área de transferência.', ), @@ -101,8 +101,8 @@ class CodeLink extends StatelessWidget { }, ), ElevatedButton.icon( - label: Text('Código Fonte'), - icon: Icon(FontAwesomeIcons.github), + label: const Text('Código Fonte'), + icon: const Icon(FontAwesomeIcons.github), onPressed: () async { if (await canLaunch(source)) { await launch(source); @@ -116,7 +116,7 @@ class CodeLink extends StatelessWidget { ), ElevatedButton( onPressed: () => Navigator.of(context).pop(), - child: Text('Fechar'), + child: const Text('Fechar'), ), ], ); diff --git a/example/lib/example_table.dart b/example/lib/example_table.dart index df4efc5c..a97196d2 100644 --- a/example/lib/example_table.dart +++ b/example/lib/example_table.dart @@ -16,6 +16,11 @@ import 'package:url_launcher/url_launcher.dart'; /// /// class ExampleTable extends StatefulWidget { + /// + /// + /// + const ExampleTable({Key? key}) : super(key: key); + /// /// /// @@ -44,11 +49,11 @@ class _ExampleTableState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: Text('Tabela'), + title: const Text('Tabela'), actions: [ /// Github IconButton( - icon: Icon(FontAwesomeIcons.github), + icon: const Icon(FontAwesomeIcons.github), onPressed: () async { const String url = 'https://github.com/edufolly/folly_fields/' 'blob/main/example/lib/example_table.dart'; @@ -72,7 +77,7 @@ class _ExampleTableState extends State { headerHeight: rowHeight, rowHeight: rowHeight, freezeColumns: 2, - columnsSize: [ + columnsSize: const [ 160.0, 230.0, 150.0, @@ -138,8 +143,8 @@ class _ExampleTableState extends State { MaterialPageRoute( builder: (_) => ExampleEdit( list[row], - ExampleBuilder(), - ExampleConsumer(), + const ExampleBuilder(), + const ExampleConsumer(), false, ), ), diff --git a/example/lib/main.dart b/example/lib/main.dart index d0a9eba1..672138e9 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -52,13 +52,19 @@ void main() { FollyFields.start(Config(), debug: debug); - runApp(MyApp()); + runApp(const MyApp()); } /// /// /// class MyApp extends StatelessWidget { + + /// + /// + /// + const MyApp({Key? key}) : super(key: key); + /// /// /// @@ -71,7 +77,7 @@ class MyApp extends StatelessWidget { brightness: Brightness.dark, snackBarTheme: ThemeData.dark().snackBarTheme.copyWith( backgroundColor: Colors.deepOrange, - contentTextStyle: TextStyle( + contentTextStyle: const TextStyle( color: Colors.white, fontSize: 16.0, ), @@ -79,11 +85,11 @@ class MyApp extends StatelessWidget { ), // home: MyHomePage(), routes: { - '/': (_) => MyHomePage(), - '/table': (_) => ExampleTable(), + '/': (_) => const MyHomePage(), + '/table': (_) => const ExampleTable(), '/list': (_) => ExampleList(), }, - localizationsDelegates: >[ + localizationsDelegates: const >[ GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, ], @@ -101,7 +107,7 @@ class MyHomePage extends StatefulWidget { /// /// /// - MyHomePage({Key? key}) : super(key: key); + const MyHomePage({Key? key}) : super(key: key); /// /// @@ -136,11 +142,11 @@ class _MyHomePageState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: Text('Exemplo - Folly Fields'), + title: const Text('Exemplo - Folly Fields'), actions: [ /// Github IconButton( - icon: Icon(FontAwesomeIcons.github), + icon: const Icon(FontAwesomeIcons.github), onPressed: () async { const String url = 'https://github.com/edufolly/folly_fields'; if (await canLaunch(url)) { @@ -157,14 +163,14 @@ class _MyHomePageState extends State { /// Table IconButton( - icon: Icon(FontAwesomeIcons.table), + icon: const Icon(FontAwesomeIcons.table), onPressed: () => Navigator.of(context).pushNamed('/table'), tooltip: 'Tabela', ), /// AbstractList IconButton( - icon: Icon(FontAwesomeIcons.list), + icon: const Icon(FontAwesomeIcons.list), onPressed: () => Navigator.of(context).pushNamed('/list'), tooltip: 'Lista', ), @@ -683,8 +689,8 @@ class _MyHomePageState extends State { horizontal: 8.0, ), child: ElevatedButton.icon( - icon: Icon(Icons.send), - label: Text('ENVIAR'), + icon: const Icon(Icons.send), + label: const Text('ENVIAR'), onPressed: _send, ), ), @@ -694,7 +700,7 @@ class _MyHomePageState extends State { ); } - return WaitingMessage(); + return const WaitingMessage(); }, ), ), diff --git a/example/pubspec.lock b/example/pubspec.lock index a53c7e90..c9fb6383 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -132,6 +132,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.7.0" + flutter_lints: + dependency: "direct dev" + description: + name: flutter_lints + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" flutter_localizations: dependency: transitive description: flutter @@ -203,6 +210,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.6.3" + lints: + dependency: transitive + description: + name: lints + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" matcher: dependency: transitive description: @@ -260,7 +274,7 @@ packages: source: hosted version: "2.0.0" pedantic: - dependency: "direct dev" + dependency: transitive description: name: pedantic url: "https://pub.dartlang.org" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index fc5ccb0a..410c1149 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -3,7 +3,7 @@ description: A new Flutter project. publish_to: 'none' -version: 0.2.18+63 +version: 0.2.19+64 environment: sdk: ">=2.12.0 <3.0.0" @@ -31,8 +31,8 @@ dev_dependencies: flutter_test: sdk: flutter - # https://pub.dev/packages/pedantic - pedantic: 1.11.1 + # https://pub.dev/packages/flutter_lints + flutter_lints: ^1.0.0 flutter: uses-material-design: true diff --git a/lib/crud/abstract_consumer.dart b/lib/crud/abstract_consumer.dart index 5ff3402a..75d5faac 100644 --- a/lib/crud/abstract_consumer.dart +++ b/lib/crud/abstract_consumer.dart @@ -4,46 +4,33 @@ import 'package:folly_fields/crud/abstract_model.dart'; /// /// /// +@immutable abstract class AbstractConsumer> { - /// - /// - /// - List get routeName; - - /// - /// - /// - T fromJson(Map map); + final List routeName; + final String? offlineTableName; + final String? offlineWhere; + final List? offlineWhereArgs; + final String offlineOrderBy; + final String? offlineTerms; + final bool returnLog; /// /// /// - String? get offlineTableName => null; - - /// - /// - /// - String? get offlineWhere => null; - - /// - /// - /// - List? get offlineWhereArgs => null; - - /// - /// - /// - String get offlineOrderBy => 'id'; - - /// - /// - /// - String? get offlineTerms => null; + const AbstractConsumer({ + this.routeName = const [], + this.offlineTableName, + this.offlineWhere, + this.offlineWhereArgs, + this.offlineOrderBy = 'id', + this.offlineTerms, + this.returnLog = false, + }); /// /// /// - bool get returnLog => false; + T fromJson(Map map); /// /// diff --git a/lib/crud/abstract_edit.dart b/lib/crud/abstract_edit.dart index 308f790a..f509711c 100644 --- a/lib/crud/abstract_edit.dart +++ b/lib/crud/abstract_edit.dart @@ -194,10 +194,10 @@ class _AbstractEditState< } }, ) - : Container(width: 0, height: 0); + : const SizedBox(width: 0, height: 0); } - return Container(width: 0, height: 0); + return const SizedBox(width: 0, height: 0); }, ), ), @@ -249,7 +249,7 @@ class _AbstractEditState< ); } - return WaitingMessage(message: 'Consultando...'); + return const WaitingMessage(message: 'Consultando...'); }, ), ), diff --git a/lib/crud/abstract_list.dart b/lib/crud/abstract_list.dart index 67bb12bc..623fad94 100644 --- a/lib/crud/abstract_list.dart +++ b/lib/crud/abstract_list.dart @@ -61,7 +61,7 @@ abstract class AbstractList< /// /// /// - static final TextStyle SUGGESTION_STYLE = const TextStyle( + static const TextStyle suggestionStyle = TextStyle( fontStyle: FontStyle.italic, ); @@ -303,7 +303,7 @@ class _AbstractListState< _actions.add( IconButton( tooltip: 'Inverter seleção', - icon: Icon(Icons.select_all), + icon: const Icon(Icons.select_all), onPressed: () { for (T model in _globalItems) { if (selections.containsKey(model.id)) { @@ -323,7 +323,7 @@ class _AbstractListState< _actions.add( IconButton( tooltip: 'Pesquisar ${widget.uiBuilder.getSuperSingle()}', - icon: Icon(Icons.search), + icon: const Icon(Icons.search), onPressed: () { showSearch( context: context, @@ -364,7 +364,7 @@ class _AbstractListState< _actions.add( IconButton( tooltip: 'Selecionar ${widget.uiBuilder.getSuperPlural()}', - icon: FaIcon(FontAwesomeIcons.check), + icon: const FaIcon(FontAwesomeIcons.check), onPressed: () => Navigator.of(context) .pop(List.from(selections.values)), ), @@ -372,38 +372,36 @@ class _AbstractListState< } } else { /// Action Routes - widget.actionRoutes.forEach( - (AbstractRoute route) { - _actions.add( - // TODO - Create an Action Route component. - FutureBuilder( - future: widget.consumer.checkPermission( - context, - route.routeName, - ), - builder: ( - BuildContext context, - AsyncSnapshot snapshot, - ) { - if (snapshot.hasData) { - ConsumerPermission permission = snapshot.data!; - - return permission.view - ? IconButton( - tooltip: permission.name, - icon: IconHelper.faIcon(permission.iconName), - onPressed: () => - Navigator.of(context).pushNamed(route.path), - ) - : Container(width: 0, height: 0); - } - - return Container(width: 0, height: 0); - }, + for (AbstractRoute route in widget.actionRoutes) { + _actions.add( + // TODO - Create an Action Route component. + FutureBuilder( + future: widget.consumer.checkPermission( + context, + route.routeName, ), - ); - }, - ); + builder: ( + BuildContext context, + AsyncSnapshot snapshot, + ) { + if (snapshot.hasData) { + ConsumerPermission permission = snapshot.data!; + + return permission.view + ? IconButton( + tooltip: permission.name, + icon: IconHelper.faIcon(permission.iconName), + onPressed: () => + Navigator.of(context).pushNamed(route.path), + ) + : const SizedBox(width: 0, height: 0); + } + + return const SizedBox(width: 0, height: 0); + }, + ), + ); + } /// Botão Adicionar if (_insert) { @@ -411,7 +409,7 @@ class _AbstractListState< _actions.add( IconButton( tooltip: 'Adicionar ${widget.uiBuilder.getSuperSingle()}', - icon: FaIcon(FontAwesomeIcons.plus), + icon: const FaIcon(FontAwesomeIcons.plus), onPressed: _addEntity, ), ); @@ -419,7 +417,7 @@ class _AbstractListState< _fabAdd = FloatingActionButton( tooltip: 'Adicionar ${widget.uiBuilder.getSuperSingle()}', onPressed: _addEntity, - child: FaIcon(FontAwesomeIcons.plus), + child: const FaIcon(FontAwesomeIcons.plus), ); } } @@ -448,12 +446,12 @@ class _AbstractListState< isAlwaysShown: FollyFields().isWeb, child: ListView.separated( physics: const AlwaysScrollableScrollPhysics(), - padding: EdgeInsets.all(16.0), + padding: const EdgeInsets.all(16.0), controller: _scrollController, itemBuilder: (BuildContext context, int index) { /// Atualizando... if (index >= _globalItems.length) { - return Container( + return const SizedBox( height: 80, child: Center( child: CircularProgressIndicator(), @@ -500,7 +498,7 @@ class _AbstractListState< ); } }, - separatorBuilder: (_, __) => FollyDivider(), + separatorBuilder: (_, __) => const FollyDivider(), itemCount: itemCount, ), ), @@ -518,7 +516,7 @@ class _AbstractListState< widget.uiBuilder.buildBottomNavigationBar(context), body: widget.uiBuilder.buildBackgroundContainer( context, - WaitingMessage(message: 'Consultando...'), + const WaitingMessage(message: 'Consultando...'), ), ); }, @@ -581,14 +579,14 @@ class _AbstractListState< }, ); } - return Container(width: 0, height: 0); + return const SizedBox(width: 0, height: 0); }, ); }, ), if (canDelete) IconButton( - icon: Icon(FontAwesomeIcons.trashAlt), + icon: const Icon(FontAwesomeIcons.trashAlt), onPressed: () async { bool refresh = await _deleteEntity(model, ask: true); if (afterDeleteRefresh != null && refresh) { @@ -794,7 +792,7 @@ class InternalSearch< List buildActions(BuildContext context) { return [ IconButton( - icon: Icon(Icons.clear), + icon: const Icon(Icons.clear), onPressed: () { query = ''; }, @@ -808,7 +806,7 @@ class InternalSearch< @override Widget buildLeading(BuildContext context) { return IconButton( - icon: Icon(Icons.arrow_back), + icon: const Icon(Icons.arrow_back), onPressed: () { close(context, null); }, @@ -826,7 +824,7 @@ class InternalSearch< Expanded( child: uiBuilder.buildBackgroundContainer( context, - Center( + const Center( child: Text( 'Começe a sua pesquisa.\n' 'Digite ao menos 3 caracteres.', @@ -864,7 +862,7 @@ class InternalSearch< if (snapshot.data!.isNotEmpty) { return ListView.separated( physics: const AlwaysScrollableScrollPhysics(), - padding: EdgeInsets.all(16.0), + padding: const EdgeInsets.all(16.0), itemBuilder: (BuildContext context, int index) { return buildResultItem( model: snapshot.data![index], @@ -874,11 +872,11 @@ class InternalSearch< afterDeleteRefresh: () async => query += '%', ); }, - separatorBuilder: (_, __) => FollyDivider(), + separatorBuilder: (_, __) => const FollyDivider(), itemCount: snapshot.data!.length, ); } else { - return Center( + return const Center( child: Text('Nenhum documento.'), ); } @@ -886,7 +884,7 @@ class InternalSearch< // TODO - Tratar erro. - return WaitingMessage(message: 'Consultando...'); + return const WaitingMessage(message: 'Consultando...'); }, ), ), @@ -908,7 +906,7 @@ class InternalSearch< Expanded( child: uiBuilder.buildBackgroundContainer( context, - Center( + const Center( child: Text( 'Começe a sua pesquisa.\n' 'Digite ao menos 3 caracteres.', @@ -983,7 +981,7 @@ class InternalSearch< ], ); } else { - return Center( + return const Center( child: Text('Nenhum documento.'), ); } @@ -991,7 +989,7 @@ class InternalSearch< // TODO - Tratar erro. - return WaitingMessage(message: 'Consultando...'); + return const WaitingMessage(message: 'Consultando...'); }, ), ), diff --git a/lib/crud/abstract_ui_builder.dart b/lib/crud/abstract_ui_builder.dart index e50bac5f..6df90767 100644 --- a/lib/crud/abstract_ui_builder.dart +++ b/lib/crud/abstract_ui_builder.dart @@ -38,7 +38,7 @@ abstract class AbstractUIBuilder> { /// /// /// Widget do leading do ListTile da lista e da pesquisa. - Widget getLeading(T model) => FaIcon(FontAwesomeIcons.solidCircle); + Widget getLeading(T model) => const FaIcon(FontAwesomeIcons.solidCircle); /// /// @@ -69,8 +69,6 @@ abstract class AbstractUIBuilder> { /// /// /// - Widget buildBottomNavigationBar(BuildContext context) => Container( - height: 0, - width: 0, - ); + Widget buildBottomNavigationBar(BuildContext context) => + const SizedBox(height: 0, width: 0); } diff --git a/lib/fields/bool_field.dart b/lib/fields/bool_field.dart index 954c0826..08310068 100644 --- a/lib/fields/bool_field.dart +++ b/lib/fields/bool_field.dart @@ -44,7 +44,7 @@ class BoolField extends FormField { final InputDecoration effectiveDecoration = (decoration ?? InputDecoration( - border: OutlineInputBorder(), + border: const OutlineInputBorder(), filled: filled, fillColor: fillColor, labelText: null, diff --git a/lib/fields/date_field.dart b/lib/fields/date_field.dart index 9fb1105b..4f562a44 100644 --- a/lib/fields/date_field.dart +++ b/lib/fields/date_field.dart @@ -39,7 +39,7 @@ class DateField extends StatefulWidget { /// /// /// - DateField({ + const DateField({ Key? key, this.prefix = '', this.label = '', @@ -159,7 +159,7 @@ class _DateFieldState extends State { Widget build(BuildContext context) { final InputDecoration effectiveDecoration = (widget.decoration ?? InputDecoration( - border: OutlineInputBorder(), + border: const OutlineInputBorder(), filled: widget.filled, fillColor: widget.fillColor, labelText: widget.prefix.isEmpty @@ -170,7 +170,7 @@ class _DateFieldState extends State { .applyDefaults(Theme.of(context).inputDecorationTheme) .copyWith( suffixIcon: IconButton( - icon: Icon(FontAwesomeIcons.solidCalendarAlt), + icon: const Icon(FontAwesomeIcons.solidCalendarAlt), onPressed: widget.enabled && !widget.readOnly ? () async { try { diff --git a/lib/fields/date_time_field.dart b/lib/fields/date_time_field.dart index eb0a014b..f0a2fb02 100644 --- a/lib/fields/date_time_field.dart +++ b/lib/fields/date_time_field.dart @@ -39,7 +39,7 @@ class DateTimeField extends StatefulWidget { /// /// /// - DateTimeField({ + const DateTimeField({ Key? key, this.prefix = '', this.label = '', @@ -159,7 +159,7 @@ class _DateTimeFieldState extends State { Widget build(BuildContext context) { final InputDecoration effectiveDecoration = (widget.decoration ?? InputDecoration( - border: OutlineInputBorder(), + border: const OutlineInputBorder(), filled: widget.filled, fillColor: widget.fillColor, labelText: widget.prefix.isEmpty @@ -170,7 +170,7 @@ class _DateTimeFieldState extends State { .applyDefaults(Theme.of(context).inputDecorationTheme) .copyWith( suffixIcon: IconButton( - icon: Icon(FontAwesomeIcons.calendarDay), + icon: const Icon(FontAwesomeIcons.calendarDay), onPressed: widget.enabled && !widget.readOnly ? () async { try { diff --git a/lib/fields/decimal_field.dart b/lib/fields/decimal_field.dart index 6345976a..742d4266 100644 --- a/lib/fields/decimal_field.dart +++ b/lib/fields/decimal_field.dart @@ -32,7 +32,7 @@ class DecimalField extends StatefulWidget { /// /// /// - DecimalField({ + const DecimalField({ Key? key, this.prefix = '', this.label = '', @@ -136,7 +136,7 @@ class _DecimalFieldState extends State { Widget build(BuildContext context) { final InputDecoration effectiveDecoration = (widget.decoration ?? InputDecoration( - border: OutlineInputBorder(), + border: const OutlineInputBorder(), filled: widget.filled, fillColor: widget.fillColor, labelText: widget.prefix.isEmpty diff --git a/lib/fields/dropdown_field.dart b/lib/fields/dropdown_field.dart index 10da0cd3..6fc6a282 100644 --- a/lib/fields/dropdown_field.dart +++ b/lib/fields/dropdown_field.dart @@ -63,7 +63,7 @@ class DropdownField extends FormField { final InputDecoration effectiveDecoration = (decoration ?? InputDecoration( - border: OutlineInputBorder(), + border: const OutlineInputBorder(), filled: filled, fillColor: fillColor, labelText: prefix.isEmpty ? label : '$prefix - $label', diff --git a/lib/fields/icon_data_field.dart b/lib/fields/icon_data_field.dart index 740606de..f74c1772 100644 --- a/lib/fields/icon_data_field.dart +++ b/lib/fields/icon_data_field.dart @@ -35,6 +35,7 @@ class IconDataField extends FormField { EdgeInsets padding = const EdgeInsets.all(8.0), }) : assert(initialValue == null || controller == null), super( + key: key, initialValue: controller != null ? controller.value : initialValue, onSaved: onSaved, validator: enabled ? validator : (_) => null, @@ -45,12 +46,12 @@ class IconDataField extends FormField { final InputDecoration effectiveDecoration = (decoration ?? InputDecoration( - border: OutlineInputBorder(), + border: const OutlineInputBorder(), filled: filled, fillColor: fillColor, labelText: prefix.isEmpty ? label : '$prefix - $label', counterText: '', - contentPadding: EdgeInsets.fromLTRB(12, 0, 8, 12), + contentPadding: const EdgeInsets.fromLTRB(12, 0, 8, 12), )) .applyDefaults(Theme.of(field.context).inputDecorationTheme); diff --git a/lib/fields/integer_field.dart b/lib/fields/integer_field.dart index b086e931..04d4112b 100644 --- a/lib/fields/integer_field.dart +++ b/lib/fields/integer_field.dart @@ -60,7 +60,7 @@ class IntegerField extends StringField { return onSaved(int.tryParse(value ?? '0')); } }, - initialValue: initialValue == null ? null : initialValue.toString(), + initialValue: initialValue?.toString(), enabled: enabled, autoValidateMode: autoValidateMode, onChanged: onChanged, diff --git a/lib/fields/list_field.dart b/lib/fields/list_field.dart index b861f8e1..687bc46d 100644 --- a/lib/fields/list_field.dart +++ b/lib/fields/list_field.dart @@ -50,7 +50,7 @@ class ListField, InputDecoration effectiveDecoration = (decoration ?? InputDecoration( labelText: uiBuilder.getSuperPlural(), - border: OutlineInputBorder(), + border: const OutlineInputBorder(), counterText: '', enabled: enabled, errorText: field.errorText, @@ -64,7 +64,7 @@ class ListField, if (field.value!.isEmpty) /// Lista vazia. - Container( + SizedBox( height: 75.0, child: Center( child: Text( @@ -246,7 +246,7 @@ class _MyListTile, trailing: Visibility( visible: FollyFields().isWeb, child: IconButton( - icon: Icon(FontAwesomeIcons.trashAlt), + icon: const Icon(FontAwesomeIcons.trashAlt), onPressed: enabled ? () => _delete(context, model, ask: true) : null, ), ), diff --git a/lib/fields/model_field.dart b/lib/fields/model_field.dart index cf7ac961..b650885a 100644 --- a/lib/fields/model_field.dart +++ b/lib/fields/model_field.dart @@ -48,7 +48,7 @@ class ModelField> extends FormField { final InputDecoration effectiveDecoration = (decoration ?? InputDecoration( - border: OutlineInputBorder(), + border: const OutlineInputBorder(), filled: filled, fillColor: fillColor, labelText: prefix.isEmpty ? label : '$prefix - $label', @@ -60,9 +60,9 @@ class ModelField> extends FormField { mainAxisAlignment: MainAxisAlignment.center, children: [ enabled && routeBuilder != null - ? FaIcon(FontAwesomeIcons.search) + ? const FaIcon(FontAwesomeIcons.search) : tapToVisualize != null - ? FaIcon(FontAwesomeIcons.chevronRight) + ? const FaIcon(FontAwesomeIcons.chevronRight) : Container(width: 0), ], ), diff --git a/lib/fields/multiline_field.dart b/lib/fields/multiline_field.dart index 6d73a535..7b00bda4 100644 --- a/lib/fields/multiline_field.dart +++ b/lib/fields/multiline_field.dart @@ -9,7 +9,7 @@ class MultilineField extends StringField { /// /// /// - MultilineField({ + const MultilineField({ Key? key, String prefix = '', String label = '', diff --git a/lib/fields/password_field.dart b/lib/fields/password_field.dart index 0b77facc..c9fd0e4b 100644 --- a/lib/fields/password_field.dart +++ b/lib/fields/password_field.dart @@ -9,7 +9,7 @@ class PasswordField extends StringField { /// /// /// - PasswordField({ + const PasswordField({ Key? key, String prefix = '', String label = '', @@ -19,7 +19,6 @@ class PasswordField extends StringField { TextAlign textAlign = TextAlign.start, int? maxLength, void Function(String value)? onSaved, - // String? initialValue, bool enabled = true, AutovalidateMode autoValidateMode = AutovalidateMode.disabled, ValueChanged? onChanged, @@ -51,7 +50,6 @@ class PasswordField extends StringField { textAlign: textAlign, maxLength: maxLength, onSaved: onSaved, - // initialValue: initialValue, enabled: enabled, autoValidateMode: autoValidateMode, onChanged: onChanged, diff --git a/lib/fields/string_field.dart b/lib/fields/string_field.dart index 99747b11..e8622c10 100644 --- a/lib/fields/string_field.dart +++ b/lib/fields/string_field.dart @@ -40,7 +40,7 @@ class StringField extends StatelessWidget { /// /// /// - StringField({ + const StringField({ Key? key, this.prefix = '', this.label = '', @@ -92,7 +92,7 @@ class StringField extends StatelessWidget { InputDecoration effectiveDecoration = (decoration ?? InputDecoration( labelText: prefix.isEmpty ? label : '$prefix - $label', - border: OutlineInputBorder(), + border: const OutlineInputBorder(), counterText: '', enabled: enabled, filled: filled, diff --git a/lib/fields/table_field.dart b/lib/fields/table_field.dart index 692cadab..4eb5e8a2 100644 --- a/lib/fields/table_field.dart +++ b/lib/fields/table_field.dart @@ -71,7 +71,7 @@ class TableField> extends FormField> { InputDecoration effectiveDecoration = (decoration ?? InputDecoration( labelText: uiBuilder.getSuperPlural(), - border: OutlineInputBorder(), + border: const OutlineInputBorder(), counterText: '', enabled: enabled, errorText: field.errorText, @@ -85,7 +85,7 @@ class TableField> extends FormField> { if (field.value!.isEmpty) /// Empty table - Container( + SizedBox( height: 75.0, child: Center( child: Text( @@ -96,7 +96,7 @@ class TableField> extends FormField> { else /// Table - Container( + SizedBox( width: double.infinity, child: Column( children: [ @@ -120,7 +120,7 @@ class TableField> extends FormField> { .toList(), /// Empty column to delete button - if (removeRow != null) EmptyButton(), + if (removeRow != null) const EmptyButton(), ], ), diff --git a/lib/fields/time_field.dart b/lib/fields/time_field.dart index 63d15e97..2eed28d0 100644 --- a/lib/fields/time_field.dart +++ b/lib/fields/time_field.dart @@ -33,7 +33,7 @@ class TimeField extends StatefulWidget { /// /// /// - TimeField({ + const TimeField({ Key? key, this.prefix = '', this.label = '', @@ -142,7 +142,7 @@ class _TimeFieldState extends State { Widget build(BuildContext context) { final InputDecoration effectiveDecoration = (widget.decoration ?? InputDecoration( - border: OutlineInputBorder(), + border: const OutlineInputBorder(), filled: widget.filled, fillColor: widget.fillColor, labelText: widget.prefix.isEmpty @@ -153,7 +153,7 @@ class _TimeFieldState extends State { .applyDefaults(Theme.of(context).inputDecorationTheme) .copyWith( suffixIcon: IconButton( - icon: Icon(FontAwesomeIcons.clock), + icon: const Icon(FontAwesomeIcons.clock), onPressed: widget.enabled && !widget.readOnly ? () async { try { diff --git a/lib/folly_fields.dart b/lib/folly_fields.dart index fcbb58d7..f3e73090 100644 --- a/lib/folly_fields.dart +++ b/lib/folly_fields.dart @@ -9,10 +9,10 @@ import 'package:flutter/foundation.dart'; /// /// enum RunningPlatform { - UNKNOWN, - WEB, - ANDROID, - IOS, + unknown, + web, + android, + ios, } /// @@ -188,7 +188,7 @@ abstract class AbstractConfig implements _InternalConfig { bool _started = false; bool _debug = false; bool _online = false; - RunningPlatform _platform = RunningPlatform.UNKNOWN; + RunningPlatform _platform = RunningPlatform.unknown; String _modelIdKey = 'id'; String _modelUpdatedAtKey = 'updatedAt'; String _modelDeletedAtKey = 'deletedAt'; @@ -216,14 +216,14 @@ abstract class AbstractConfig implements _InternalConfig { /// /// @override - bool get isWeb => _platform == RunningPlatform.WEB; + bool get isWeb => _platform == RunningPlatform.web; /// /// /// @override bool get isMobile => - _platform == RunningPlatform.ANDROID || _platform == RunningPlatform.IOS; + _platform == RunningPlatform.android || _platform == RunningPlatform.ios; /// /// @@ -280,11 +280,11 @@ abstract class AbstractConfig implements _InternalConfig { _modelParseDates = modelParseDates; if (kIsWeb) { - _platform = RunningPlatform.WEB; + _platform = RunningPlatform.web; } else if (Platform.isAndroid) { - _platform = RunningPlatform.ANDROID; + _platform = RunningPlatform.android; } else if (Platform.isIOS) { - _platform = RunningPlatform.IOS; + _platform = RunningPlatform.ios; } ConnectivityResult result = await Connectivity().checkConnectivity(); diff --git a/lib/widgets/add_button.dart b/lib/widgets/add_button.dart index a8a601d5..960a22a0 100644 --- a/lib/widgets/add_button.dart +++ b/lib/widgets/add_button.dart @@ -30,7 +30,7 @@ class AddButton extends StatelessWidget { style: ElevatedButton.styleFrom( padding: const EdgeInsets.all(12.0), ), - icon: FaIcon( + icon: const FaIcon( FontAwesomeIcons.plus, ), label: Text( diff --git a/lib/widgets/animated_search.dart b/lib/widgets/animated_search.dart index 63c6c789..8f297c8a 100644 --- a/lib/widgets/animated_search.dart +++ b/lib/widgets/animated_search.dart @@ -36,7 +36,7 @@ class _AnimatedSearchState extends State { @override Widget build(BuildContext context) { return AnimatedContainer( - duration: Duration(milliseconds: 300), + duration: const Duration(milliseconds: 300), width: expanded ? widget.maxSize : 40, decoration: BoxDecoration( borderRadius: BorderRadius.circular(8.0), @@ -53,7 +53,7 @@ class _AnimatedSearchState extends State { padding: const EdgeInsets.symmetric(horizontal: 8.0), child: TextField( controller: widget.controller, - decoration: InputDecoration( + decoration: const InputDecoration( border: InputBorder.none, ), autofocus: expanded, diff --git a/lib/widgets/circular_waiting.dart b/lib/widgets/circular_waiting.dart index c16aea4c..d0e08600 100644 --- a/lib/widgets/circular_waiting.dart +++ b/lib/widgets/circular_waiting.dart @@ -63,10 +63,10 @@ class CircularWaiting { value: dbl, ), Padding( - padding: EdgeInsets.only(top: 12.0), + padding: const EdgeInsets.only(top: 12.0), child: Text( msg, - style: TextStyle( + style: const TextStyle( fontSize: 20.0, ), ), diff --git a/lib/widgets/delete_button.dart b/lib/widgets/delete_button.dart index 4b7202d8..58afb65f 100644 --- a/lib/widgets/delete_button.dart +++ b/lib/widgets/delete_button.dart @@ -42,7 +42,7 @@ class DeleteButton extends StatelessWidget { return Flexible( flex: 0, child: Padding( - padding: EdgeInsets.only( + padding: const EdgeInsets.only( top: 12.0, ), child: IconButton( diff --git a/lib/widgets/empty_button.dart b/lib/widgets/empty_button.dart index dbe4084a..494c54ba 100644 --- a/lib/widgets/empty_button.dart +++ b/lib/widgets/empty_button.dart @@ -5,12 +5,17 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; /// /// class EmptyButton extends StatelessWidget { + /// + /// + /// + const EmptyButton({Key? key}) : super(key: key); + /// /// /// @override Widget build(BuildContext context) { - return Flexible( + return const Flexible( flex: 0, child: IconButton( icon: FaIcon( diff --git a/lib/widgets/folly_dialogs.dart b/lib/widgets/folly_dialogs.dart index 4a9f1878..10dbc174 100644 --- a/lib/widgets/folly_dialogs.dart +++ b/lib/widgets/folly_dialogs.dart @@ -72,7 +72,7 @@ class FollyDialogs { ), child: Text( message, - style: TextStyle(fontSize: 18.0), + style: const TextStyle(fontSize: 18.0), ), ), Padding( diff --git a/lib/widgets/folly_table.dart b/lib/widgets/folly_table.dart index ff949d4d..a0855ba7 100644 --- a/lib/widgets/folly_table.dart +++ b/lib/widgets/folly_table.dart @@ -140,7 +140,7 @@ class _FollyTableState extends State { Flexible( flex: 1, child: ScrollConfiguration( - behavior: ScrollBehavior().copyWith( + behavior: const ScrollBehavior().copyWith( dragDevices: widget.dragDevices, ), child: Scrollbar( @@ -163,7 +163,7 @@ class _FollyTableState extends State { /// Vertical Scrollbar Column( children: [ - Container( + SizedBox( width: widget.scrollBarThickness, height: widget.headerHeight + widget.dividerHeight + 4.0, ), @@ -174,7 +174,7 @@ class _FollyTableState extends State { thickness: widget.scrollBarThickness, child: SingleChildScrollView( controller: _verticalController, - child: Container( + child: SizedBox( width: widget.scrollBarThickness, height: (widget.rowHeight + widget.dividerHeight + 4.0) * widget.rowsCount, @@ -220,7 +220,7 @@ class _FollyTableState extends State { ) .toList(), ), - Container( + SizedBox( width: width, child: FollyDivider( height: widget.dividerHeight, @@ -230,7 +230,7 @@ class _FollyTableState extends State { child: SizedBox( width: width, child: ScrollConfiguration( - behavior: ScrollBehavior().copyWith( + behavior: const ScrollBehavior().copyWith( scrollbars: false, dragDevices: widget.dragDevices, ), @@ -324,32 +324,37 @@ class FollyCell extends StatelessWidget { /// /// FollyCell.empty({ + Key? key, this.color = Colors.transparent, }) : align = Alignment.centerLeft, - child = Container(); + child = Container(), + super(key: key); /// /// /// FollyCell.textHeader( String text, { + Key? key, this.align = Alignment.bottomLeft, this.color = Colors.transparent, TextAlign textAlign = TextAlign.start, TextStyle style = const TextStyle( fontWeight: FontWeight.bold, ), - }) : child = Text( + }) : child = Text( text, textAlign: textAlign, style: style, - ); + ), + super(key: key); /// /// /// FollyCell.textHeaderCenter( String text, { + Key? key, this.color = Colors.transparent, TextStyle style = const TextStyle( fontWeight: FontWeight.bold, @@ -359,28 +364,32 @@ class FollyCell extends StatelessWidget { text, textAlign: TextAlign.center, style: style, - ); + ), + super(key: key); /// /// /// FollyCell.text( String text, { + Key? key, this.align = Alignment.centerLeft, this.color = Colors.transparent, TextAlign textAlign = TextAlign.start, TextStyle? style, - }) : child = Text( + }) : child = Text( text, textAlign: textAlign, style: style, - ); + ), + super(key: key); /// /// /// FollyCell.center( String text, { + Key? key, this.color = Colors.transparent, TextStyle? style, }) : align = Alignment.center, @@ -388,107 +397,120 @@ class FollyCell extends StatelessWidget { text, textAlign: TextAlign.center, style: style, - ); + ), + super(key: key); /// /// /// FollyCell.number( num number, { + Key? key, this.align = Alignment.centerRight, this.color = Colors.transparent, TextAlign textAlign = TextAlign.end, TextStyle? style, String locale = 'pt_br', String pattern = '#,##0.00', - }) : child = Text( + }) : child = Text( NumberFormat(pattern, locale).format(number), textAlign: textAlign, style: style, - ); + ), + super(key: key); /// /// /// FollyCell.integer( num number, { + Key? key, this.align = Alignment.centerRight, this.color = Colors.transparent, TextAlign textAlign = TextAlign.end, TextStyle? style, String locale = 'pt_br', String pattern = '#,##0', - }) : child = Text( + }) : child = Text( NumberFormat(pattern, locale).format(number), textAlign: textAlign, style: style, - ); + ), + super(key: key); /// /// /// FollyCell.date( DateTime date, { + Key? key, this.align = Alignment.center, this.color = Colors.transparent, TextAlign textAlign = TextAlign.center, TextStyle? style, String locale = 'pt_br', String pattern = 'dd/MM/yyyy', - }) : child = Text( + }) : child = Text( DateFormat(pattern, locale).format(date), textAlign: textAlign, style: style, - ); + ), + super(key: key); /// /// /// FollyCell.time( DateTime date, { + Key? key, this.align = Alignment.center, this.color = Colors.transparent, TextAlign textAlign = TextAlign.center, TextStyle? style, String locale = 'pt_br', String pattern = 'HH:mm', - }) : child = Text( + }) : child = Text( DateFormat(pattern, locale).format(date), textAlign: textAlign, style: style, - ); + ), + super(key: key); /// /// /// FollyCell.dateTime( DateTime date, { + Key? key, this.align = Alignment.center, this.color = Colors.transparent, TextAlign textAlign = TextAlign.center, TextStyle? style, String locale = 'pt_br', String pattern = 'dd/MM/yyyy HH:mm', - }) : child = Text( + }) : child = Text( DateFormat(pattern, locale).format(date), textAlign: textAlign, style: style, - ); + ), + super(key: key); /// /// /// FollyCell.iconButton( IconData iconData, { + Key? key, Function()? onPressed, this.align = Alignment.center, this.color = Colors.transparent, - }) : child = FittedBox( + }) : child = FittedBox( child: IconButton( icon: Icon(iconData), onPressed: onPressed, ), - ); + ), + super(key: key); /// /// diff --git a/lib/widgets/home_card.dart b/lib/widgets/home_card.dart index 00ef2f44..89790807 100644 --- a/lib/widgets/home_card.dart +++ b/lib/widgets/home_card.dart @@ -45,7 +45,7 @@ class HomeCard extends StatelessWidget { decoration: BoxDecoration( color: Theme.of(context).colorScheme.surface, borderRadius: BorderRadius.circular(16.0), - boxShadow: [ + boxShadow: const [ BoxShadow( color: Colors.black26, offset: Offset(1.0, 0.5), @@ -84,7 +84,7 @@ class HomeCard extends StatelessWidget { padding: const EdgeInsets.only(top: 8.0), child: PopupMenuButton( tooltip: tooltip ?? 'Opções do Favorito', - icon: FaIcon( + icon: const FaIcon( FontAwesomeIcons.ellipsisV, color: Colors.black12, ), diff --git a/lib/widgets/waiting_message.dart b/lib/widgets/waiting_message.dart index 499d6a4f..04fbaa37 100644 --- a/lib/widgets/waiting_message.dart +++ b/lib/widgets/waiting_message.dart @@ -24,8 +24,8 @@ class WaitingMessage extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ - Padding( - padding: const EdgeInsets.all(12.0), + const Padding( + padding: EdgeInsets.all(12.0), child: CircularProgressIndicator(), ), Center(