Compare commits
2 Commits
d914b8bcae
...
a613292095
| Author | SHA1 | Date |
|---|---|---|
|
|
a613292095 | |
|
|
b8c49132d7 |
|
|
@ -76,15 +76,14 @@ class _AddFormState extends State<AddForm> {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
onFieldSubmitted: (value) {
|
textInputAction: TextInputAction.next,
|
||||||
if (_formKey.currentState!.validate()) {
|
onFieldSubmitted: (value) =>
|
||||||
FocusScope.of(context).requestFocus(_TemplateFocusNode);
|
_formKey.currentState!.validate(),
|
||||||
}
|
|
||||||
},
|
|
||||||
decoration: const InputDecoration(labelText: 'Label')),
|
decoration: const InputDecoration(labelText: 'Label')),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
decoration:
|
decoration:
|
||||||
const InputDecoration(labelText: 'Description(optional)'),
|
const InputDecoration(labelText: 'Description(optional)'),
|
||||||
|
textInputAction: TextInputAction.next,
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
_listDesc = value;
|
_listDesc = value;
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,9 @@ class _MainListPageState extends State<MainListPage> {
|
||||||
int _selectedPage = data.Page.lists.index;
|
int _selectedPage = data.Page.lists.index;
|
||||||
List<data.List> lists = [];
|
List<data.List> lists = [];
|
||||||
|
|
||||||
|
final double _marginHorizontal = 10;
|
||||||
|
final double _cardSpacing = 4;
|
||||||
|
|
||||||
Future<void> _loadData(data.Page listType) async {
|
Future<void> _loadData(data.Page listType) async {
|
||||||
lists.clear();
|
lists.clear();
|
||||||
var res = await DBHelper.dbHelper.getAllLists(listType);
|
var res = await DBHelper.dbHelper.getAllLists(listType);
|
||||||
|
|
@ -66,6 +69,9 @@ class _MainListPageState extends State<MainListPage> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final EdgeInsets cardMargin =
|
||||||
|
EdgeInsets.symmetric(vertical: _cardSpacing, horizontal: 0);
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(widget.title),
|
title: Text(widget.title),
|
||||||
|
|
@ -83,76 +89,80 @@ class _MainListPageState extends State<MainListPage> {
|
||||||
tooltip: 'Add List',
|
tooltip: 'Add List',
|
||||||
child: const Icon(Icons.add),
|
child: const Icon(Icons.add),
|
||||||
),
|
),
|
||||||
body: RefreshIndicator(
|
body: Container(
|
||||||
onRefresh: () => _loadData(data.Page.values[_selectedPage]),
|
padding: EdgeInsets.symmetric(horizontal: _marginHorizontal),
|
||||||
child: ListView.builder(
|
child: RefreshIndicator(
|
||||||
itemCount: lists.length,
|
onRefresh: () => _loadData(data.Page.values[_selectedPage]),
|
||||||
itemBuilder: (context, index) {
|
child: ListView.builder(
|
||||||
return Dismissible(
|
itemCount: lists.length,
|
||||||
direction: DismissDirection.startToEnd,
|
itemBuilder: (context, index) {
|
||||||
key: Key(lists[index].id.toString()),
|
return Dismissible(
|
||||||
background: Card(
|
direction: DismissDirection.startToEnd,
|
||||||
color: Colors.red,
|
key: Key(lists[index].id.toString()),
|
||||||
child: Row(
|
background: Card(
|
||||||
children: const [
|
margin: cardMargin,
|
||||||
Padding(
|
color: Colors.red,
|
||||||
padding: EdgeInsets.all(10),
|
child: Row(
|
||||||
child: Icon(Icons.delete),
|
children: const [
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.all(10),
|
||||||
|
child: Icon(Icons.delete),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
confirmDismiss: (direction) async {
|
||||||
),
|
if (direction != DismissDirection.startToEnd) {
|
||||||
confirmDismiss: (direction) async {
|
return false;
|
||||||
if (direction != DismissDirection.startToEnd) {
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: const Text('Are you sure?'),
|
title: const Text('Are you sure?'),
|
||||||
content: const Text(
|
content: const Text(
|
||||||
'You are about to delete this permently'),
|
'You are about to delete this permently'),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () =>
|
onPressed: () =>
|
||||||
Navigator.pop(context, false),
|
Navigator.pop(context, false),
|
||||||
child: const Text('Cancel')),
|
child: const Text('Cancel')),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () =>
|
onPressed: () =>
|
||||||
Navigator.pop(context, true),
|
Navigator.pop(context, true),
|
||||||
child: const Text('OK')),
|
child: const Text('OK')),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}).then((value) {
|
}).then((value) {
|
||||||
if (value) {
|
if (value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_removeList(lists[index]);
|
_removeList(lists[index]);
|
||||||
lists.removeAt(index);
|
lists.removeAt(index);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
child: Card(
|
|
||||||
child: ListTile(
|
|
||||||
onTap: () {
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) =>
|
|
||||||
CheckList(id: lists[index].id!)));
|
|
||||||
},
|
},
|
||||||
title: Text(lists[index].name),
|
child: Card(
|
||||||
subtitle: Text((lists[index].description != null)
|
margin: cardMargin,
|
||||||
? lists[index].description!
|
child: ListTile(
|
||||||
: ""),
|
onTap: () {
|
||||||
),
|
Navigator.push(
|
||||||
),
|
context,
|
||||||
);
|
MaterialPageRoute(
|
||||||
})),
|
builder: (context) =>
|
||||||
|
CheckList(id: lists[index].id!)));
|
||||||
|
},
|
||||||
|
title: Text(lists[index].name),
|
||||||
|
subtitle: Text((lists[index].description != null)
|
||||||
|
? lists[index].description!
|
||||||
|
: ""),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}))),
|
||||||
bottomNavigationBar: BottomNavigationBar(
|
bottomNavigationBar: BottomNavigationBar(
|
||||||
elevation: 4,
|
elevation: 4,
|
||||||
currentIndex: _selectedPage,
|
currentIndex: _selectedPage,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue