-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.dart
More file actions
169 lines (157 loc) · 4.93 KB
/
main.dart
File metadata and controls
169 lines (157 loc) · 4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:studypoints/avatar/data/avatar.dart';
import 'package:studypoints/avatar/data/repository.dart';
import 'package:studypoints/avatar/widgets/avatar_screen.dart';
import 'package:studypoints/avatar/widgets/avatar_view.dart';
import 'package:studypoints/services/user.dart';
import 'package:studypoints/tasks/widgets/new_task_dialog.dart';
import 'package:studypoints/tasks/widgets/task_dashboard_view.dart';
import 'package:studypoints/tasks/widgets/tasks_screen.dart';
import 'tasks/data/task.dart';
/// The heart of the operation.
/// Instead of conventional navigation,
/// the app uses the [BottomNavigationBar]
/// to set the [Scaffold]'s body.
/// All children have a parent attribute which accepts a [State]
/// in order to alert the root [Scaffold] if shared data has changed.
void main() => runApp(StudyPointsApp());
class StudyPointsApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
Provider<ShopItemRepository>(
builder: (_) => ShopItemRepository(),
),
ProxyProvider<ShopItemRepository, UserService>(
builder: (_, items, __) => UserService(
avatar: Avatar(
name: 'Nina',
body: items.firstOfType('body').id,
face: items.firstOfType('face').id,
hair: items.firstOfType('hair').id,
skin: items.firstOfType('skin').id,
hairEffect: items.firstOfType('hairEffect').id,
)),
),
],
child: MaterialApp(
title: 'StudyPoints',
theme: ThemeData(
primarySwatch: Colors.lime,
),
home: HomePage()),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int _currentIndex = 0;
List<Widget> _children;
@override
initState() {
_children = [
DashboardView(
parent: this,
),
TasksScreen(
parent: this,
),
AvatarScreen(
parent: this,
),
Center(
child: FlutterLogo(),
),
];
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Row(
children: <Widget>[
Text('${Provider.of<UserService>(context).hcCount} HC'),
Spacer(),
Text('StudyPoints'),
],
),
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
elevation: 0.0,
),
bottomNavigationBar: BottomNavigationBar(
onTap: (index) => setState(() => _currentIndex = index),
currentIndex: _currentIndex,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.dashboard), title: Text('Dashboard')),
BottomNavigationBarItem(icon: Icon(Icons.list), title: Text('Tasks')),
BottomNavigationBarItem(
icon: Icon(Icons.person), title: Text('Avatar')),
],
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () => Navigator.of(context)
.push(MaterialPageRoute<Task>(
builder: (context) => NewTaskDialog(),
))
.then((val) => val != null
? Provider.of<UserService>(context).tasks.add(val)
: null),
),
body: _children[_currentIndex],
);
}
}
class DashboardView extends StatefulWidget {
/// This is most of what you see when opening the app.
/// It is mostly justt a [Column] coontaining the
/// dashboard elements. Other modules should provide a
/// widget [ModuleNameView] that can be included here.
final State parent;
const DashboardView({Key key, this.parent}) : super(key: key);
@override
_DashboardViewState createState() => _DashboardViewState();
}
class _DashboardViewState extends State<DashboardView> {
@override
Widget build(BuildContext context) {
return ListView(
children: <Widget>[
Center(
child: AvatarView(
avatar: Provider.of<UserService>(context).avatar,
height: 400,
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
// TODO: Add study/no distractions mode
FlatButton(
color: Theme.of(context).backgroundColor,
child: Text('I want to study now'),
),
FlatButton(
child: Text('I did some work'),
color: Theme.of(context).backgroundColor,
onPressed: () {
setState(() {
Provider.of<UserService>(context).hcCount += 20;
});
widget.parent.setState(() {});
},
)
],
),
TaskDashboardView(),
],
);
}
}