From 9d4ac739c2d6738b8951dccacef1293310c02364 Mon Sep 17 00:00:00 2001 From: andrei Date: Sat, 20 Nov 2021 17:51:29 -0500 Subject: [PATCH] took care of compiler warnings --- lib/add_form.dart | 19 ++++++++----------- lib/box_checker.dart | 2 +- lib/check_list.dart | 16 ++++++++-------- lib/data_util.dart | 16 ++++++++-------- 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/lib/add_form.dart b/lib/add_form.dart index b70013d..9efd367 100644 --- a/lib/add_form.dart +++ b/lib/add_form.dart @@ -7,20 +7,17 @@ class AddForm extends StatefulWidget { final data.Page type; @override - State createState() => _AddFormState(type); + State createState() => _AddFormState(); } class _AddFormState extends State { - _AddFormState(this.type); final _formKey = GlobalKey(); - - final data.Page type; int _templatChoice = -1; String _listLabel = ""; String _listDesc = ""; List templates = []; - final FocusNode _TemplateFocusNode = FocusNode(); + final FocusNode _templateFocusNode = FocusNode(); void loadTemplates() async { var rows = await DBHelper.dbHelper.getAllLists(data.Page.templates); @@ -36,7 +33,7 @@ class _AddFormState extends State { List> generateDropdown() { loadTemplates(); List> items = [ - DropdownMenuItem(child: Text("None"), value: -1) + const DropdownMenuItem(child: Text("None"), value: -1) ]; templates.asMap().forEach((index, value) { items.add(DropdownMenuItem( @@ -53,9 +50,9 @@ class _AddFormState extends State { appBar: AppBar( title: Text( 'Add ' + - ((type == data.Page.lists) + ((widget.type == data.Page.lists) ? 'Check List' - : (type == data.Page.templates) + : (widget.type == data.Page.templates) ? 'Template' : ''), ), @@ -89,7 +86,7 @@ class _AddFormState extends State { }, ), DropdownButtonFormField( - focusNode: _TemplateFocusNode, + focusNode: _templateFocusNode, value: _templatChoice, onChanged: (value) => setState(() { _templatChoice = value!; @@ -103,13 +100,13 @@ class _AddFormState extends State { ), ), floatingActionButton: FloatingActionButton( - child: Icon(Icons.save_alt), + child: const Icon(Icons.save_alt), onPressed: () async { if (_formKey.currentState!.validate()) { int id = await DBHelper.dbHelper.insertList( data.List( _listLabel, - isTemplate: type.index == 1, + isTemplate: widget.type.index == 1, description: _listDesc, ), ); diff --git a/lib/box_checker.dart b/lib/box_checker.dart index 3dbaaf8..2252f6b 100644 --- a/lib/box_checker.dart +++ b/lib/box_checker.dart @@ -15,7 +15,7 @@ class BoxChecker extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', - theme: ThemeData.from(colorScheme: ColorScheme.dark()).copyWith( + theme: ThemeData.from(colorScheme: const ColorScheme.dark()).copyWith( canvasColor: Colors.blueGrey[900], cardColor: Colors.grey[800], scaffoldBackgroundColor: Colors.black12, diff --git a/lib/check_list.dart b/lib/check_list.dart index 05c29a0..b6e9199 100644 --- a/lib/check_list.dart +++ b/lib/check_list.dart @@ -7,18 +7,16 @@ class CheckList extends StatefulWidget { final int id; @override - State createState() => _CheckList(id); + State createState() => _CheckList(); } class _CheckList extends State { - _CheckList(this.id); - final int id; bool _editable = false; data.List? listData; List list = []; void _loadList() async { - var rows = await DBHelper.dbHelper.getList(id); + var rows = await DBHelper.dbHelper.getList(widget.id); list.clear(); setState(() { @@ -29,7 +27,7 @@ class _CheckList extends State { } void _loadListData() async { - var rows = await DBHelper.dbHelper.getListData(id); + var rows = await DBHelper.dbHelper.getListData(widget.id); listData = (rows.isNotEmpty) ? data.List.fromMap(rows[0]) : null; } @@ -76,7 +74,8 @@ class _CheckList extends State { onTap: () => FocusScope.of(context).unfocus(), child: Scaffold( appBar: AppBar( - title: Text((listData != null) ? listData!.name : 'Check List: $id'), + title: Text( + (listData != null) ? listData!.name : 'Check List: ${widget.id}'), actions: (listData != null && listData!.isTemplate!) ? [iconButton()] : [], ), @@ -128,7 +127,7 @@ class _CheckList extends State { title: TextFormField( enabled: (listData != null && (!listData!.isTemplate! || _editable)), - decoration: InputDecoration(border: InputBorder.none), + decoration: const InputDecoration(border: InputBorder.none), initialValue: list[index].text, onChanged: (value) { list[index].text = value; @@ -156,7 +155,8 @@ class _CheckList extends State { if (listData!.isTemplate! && !_editable) { ScaffoldMessenger.of(context) ..clearSnackBars() - ..showSnackBar(SnackBar(content: Text("Template is locked"))); + ..showSnackBar( + const SnackBar(content: Text("Template is locked"))); return; } _addItem(); diff --git a/lib/data_util.dart b/lib/data_util.dart index 181aeec..8d6bb40 100644 --- a/lib/data_util.dart +++ b/lib/data_util.dart @@ -9,9 +9,9 @@ class List { bool? isTemplate; Map toMap() { - var map = Map(); - if (id != null) map["id"] = this.id; - map["list_name"] = this.name; + var map = {}; + if (id != null) map["id"] = id; + map["list_name"] = name; if (description != null) map["list_desc"] = description; if (isTemplate != null) map["is_template"] = isTemplate! ? 1 : 0; return map; @@ -36,11 +36,11 @@ class Check { int? listID; Map toMap() { - var map = Map(); - if (id != null) map["id"] = this.id; - map["check_text"] = this.text; - map["status"] = this.value ? 1 : 0; - if (listID != null) map["list_id"] = this.listID! as int; + var map = {}; + if (id != null) map["id"] = id; + map["check_text"] = text; + map["status"] = value ? 1 : 0; + if (listID != null) map["list_id"] = listID!; return map; }