took care of compiler warnings

This commit is contained in:
andrei 2021-11-20 17:51:29 -05:00
parent d6dbe5234e
commit 9d4ac739c2
4 changed files with 25 additions and 28 deletions

View File

@ -7,20 +7,17 @@ class AddForm extends StatefulWidget {
final data.Page type;
@override
State<StatefulWidget> createState() => _AddFormState(type);
State<StatefulWidget> createState() => _AddFormState();
}
class _AddFormState extends State<AddForm> {
_AddFormState(this.type);
final _formKey = GlobalKey<FormState>();
final data.Page type;
int _templatChoice = -1;
String _listLabel = "";
String _listDesc = "";
List<data.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<AddForm> {
List<DropdownMenuItem<int>> generateDropdown() {
loadTemplates();
List<DropdownMenuItem<int>> items = [
DropdownMenuItem<int>(child: Text("None"), value: -1)
const DropdownMenuItem<int>(child: Text("None"), value: -1)
];
templates.asMap().forEach((index, value) {
items.add(DropdownMenuItem<int>(
@ -53,9 +50,9 @@ class _AddFormState extends State<AddForm> {
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<AddForm> {
},
),
DropdownButtonFormField<int>(
focusNode: _TemplateFocusNode,
focusNode: _templateFocusNode,
value: _templatChoice,
onChanged: (value) => setState(() {
_templatChoice = value!;
@ -103,13 +100,13 @@ class _AddFormState extends State<AddForm> {
),
),
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,
),
);

View File

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

View File

@ -7,18 +7,16 @@ class CheckList extends StatefulWidget {
final int id;
@override
State<StatefulWidget> createState() => _CheckList(id);
State<StatefulWidget> createState() => _CheckList();
}
class _CheckList extends State<CheckList> {
_CheckList(this.id);
final int id;
bool _editable = false;
data.List? listData;
List<data.Check> 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<CheckList> {
}
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<CheckList> {
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<CheckList> {
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<CheckList> {
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();

View File

@ -9,9 +9,9 @@ class List {
bool? isTemplate;
Map<String, dynamic> toMap() {
var map = Map<String, dynamic>();
if (id != null) map["id"] = this.id;
map["list_name"] = this.name;
var map = <String, dynamic>{};
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<String, dynamic> toMap() {
var map = Map<String, dynamic>();
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 = <String, dynamic>{};
if (id != null) map["id"] = id;
map["check_text"] = text;
map["status"] = value ? 1 : 0;
if (listID != null) map["list_id"] = listID!;
return map;
}