-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.dart
131 lines (117 loc) · 3.88 KB
/
home.dart
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
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
@override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
late String _userDaily;
List dailyList = [];
void initFarebase() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
}
@override
void initState() {
super.initState();
initFarebase();
dailyList.addAll(['Пресс','Скакалка']);
}
void _menuOpen() {
Navigator.of(context).push(
MaterialPageRoute(builder: (BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Меню'),),
body: Row(
children: [
ElevatedButton(onPressed: () {
Navigator.pop(context);
Navigator.pushNamedAndRemoveUntil(context, '/', (route) => false);
}, child: Text('На главную')),
Padding(padding: EdgeInsets.only(left: 25)),
Text('Хочу на курсы AVADA Media')
],
)
);
})
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.pink[900],
appBar: AppBar(
title: Text('Тренировочка'),
centerTitle: true,
actions: [
IconButton(
onPressed: _menuOpen,
icon: Icon(Icons.menu),
)
],
),
body: StreamBuilder(
stream: FirebaseFirestore.instance.collection('items').snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if(!snapshot.hasData) return Text('Нет записей');
return ListView.builder(
itemCount: snapshot.data?.docs.length,
itemBuilder: (BuildContext text, int index) {
return Dismissible(
key: Key(snapshot.data!.docs[index].id),
child: Card(
child: ListTile(
title: Text(snapshot.data?.docs[index].get('item')),
trailing: IconButton(
icon: Icon(
Icons.delete_forever,
color: Colors.black,
),
onPressed: () {
setState(() {
dailyList.removeAt(index);
});
},
),
),
),
onDismissed: (direction) {
setState(() {
dailyList.removeAt(index);
});
},
);
}
);
}
),
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.yellowAccent,
onPressed: () {
showDialog(context: context, builder: (BuildContext context) {
return AlertDialog(
title: Text('Добавить задание'),
content: TextField(
onChanged: (String value) {
_userDaily = value;
},
),
actions: [
ElevatedButton(onPressed: () {
FirebaseFirestore.instance.collection('items').add({'item': _userDaily});
Navigator.of(context).pop();
}, child: Text('Добавить'))
],
);
});
},
child: Icon(
Icons.add_box,
color: Colors.black,
),
),
);
}
}