Skip to content

Commit 06f77f4

Browse files
committed
Make checklist manager a change notifier
1 parent 99fce3b commit 06f77f4

5 files changed

Lines changed: 39 additions & 27 deletions

File tree

note_app/lib/main.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
import 'package:flutter/material.dart';
22
import 'package:note_app/model/NotesList.dart';
3+
import 'package:note_app/model/checklist/ChecklistManager.dart';
34
import 'package:provider/provider.dart';
45

56
import 'screen/LoadingPage.dart';
67
import 'util/constant/app_theme.dart';
78

89
void main() {
9-
runApp(
10-
ChangeNotifierProvider(create: (context) => NotesList(), child: MyApp()));
10+
runApp(MultiProvider(
11+
providers: [
12+
ChangeNotifierProvider(create: (_) => NotesList()),
13+
ChangeNotifierProvider(create: (_) => ChecklistManager()),
14+
],
15+
child: MyApp(),
16+
));
1117
}
1218

1319
class MyApp extends StatelessWidget {

note_app/lib/model/checklist/ChecklistManager.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import 'package:flutter/material.dart';
12
import 'package:note_app/model/NotesList.dart';
23
import 'package:note_app/model/checklist/ChecklistElement.dart';
34

45
import 'Checklist.dart';
56

6-
class ChecklistManager {
7+
class ChecklistManager extends ChangeNotifier {
78
static final ChecklistManager _manager = ChecklistManager._internal();
89
late int id;
910
late String title;
@@ -32,6 +33,7 @@ class ChecklistManager {
3233
void removeElement(int idx) {
3334
elems.removeAt(idx);
3435
updateChecklist();
36+
notifyListeners();
3537
}
3638

3739
void modifyElement(int idx, ChecklistElement newElem) {

note_app/lib/util/DatabaseHelper.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ class DatabaseHelper {
117117
getPathForOrdering().then((file) {
118118
String enc = ordering.toString();
119119
file.writeAsString(enc);
120-
print('writing ordering: ' + enc.toString());
121120
});
122121
}
123122
}

note_app/lib/widget/ChecklistTile.dart

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'dart:async';
33
import 'package:flutter/material.dart';
44
import 'package:note_app/model/checklist/ChecklistElement.dart';
55
import 'package:note_app/model/checklist/ChecklistManager.dart';
6+
import 'package:provider/provider.dart';
67

78
class ChecklistTile extends StatefulWidget {
89
final int idx;
@@ -33,29 +34,33 @@ class _ChecklistTileState extends State<ChecklistTile> {
3334

3435
@override
3536
Widget build(BuildContext context) {
36-
return ListTile(
37-
leading: IconButton(
38-
icon: _ticked
39-
? Icon(Icons.check_box_rounded)
40-
: Icon(Icons.check_box_outline_blank_rounded),
41-
onPressed: _onTapCheckbox,
42-
),
43-
title: TextField(
44-
controller: _controller,
45-
maxLength: 100,
46-
maxLines: null,
47-
onChanged: _onContentModified,
48-
onSubmitted: _onContentSubmitted,
49-
textInputAction: TextInputAction.done,
50-
style: TextStyle(fontSize: 20),
51-
decoration: InputDecoration(
52-
hintText: 'Item',
53-
border: InputBorder.none,
54-
counterText: '',
37+
return Consumer<ChecklistManager>(builder: (context, manager, child) {
38+
_controller.text = manager.elems[widget.idx].content;
39+
_ticked = manager.elems[widget.idx].isChecked;
40+
return ListTile(
41+
leading: IconButton(
42+
icon: _ticked
43+
? Icon(Icons.check_box_rounded)
44+
: Icon(Icons.check_box_outline_blank_rounded),
45+
onPressed: _onTapCheckbox,
5546
),
56-
),
57-
horizontalTitleGap: 0,
58-
);
47+
title: TextField(
48+
controller: _controller,
49+
maxLength: 100,
50+
maxLines: null,
51+
onChanged: _onContentModified,
52+
onSubmitted: _onContentSubmitted,
53+
textInputAction: TextInputAction.done,
54+
style: TextStyle(fontSize: 20),
55+
decoration: InputDecoration(
56+
hintText: 'Item',
57+
border: InputBorder.none,
58+
counterText: '',
59+
),
60+
),
61+
horizontalTitleGap: 0,
62+
);
63+
});
5964
}
6065

6166
void _onTapCheckbox() {

note_app/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
1515
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
1616
# Read more about iOS versioning at
1717
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
18-
version: 2.0.2+6
18+
version: 2.0.3+7
1919

2020
environment:
2121
sdk: ">=2.12.0 <3.0.0"

0 commit comments

Comments
 (0)