Skip to content

Commit 20ea765

Browse files
committed
visual delete and return
-Add Dismissible para deletar item de lista. - Add SnackBar para cancelar e retornar item deletado
1 parent 1315f8c commit 20ea765

File tree

2 files changed

+106
-53
lines changed

2 files changed

+106
-53
lines changed

finacash/lib/Widgets/CardMovimentacoesItem.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class CardMovimentacoesItem extends StatelessWidget {
9191

9292
return GestureDetector(
9393
onLongPress: (){
94-
_dialogConfimacao(context, width);
94+
//_dialogConfimacao(context, width);
9595

9696
},
9797
child: Container(

finacash/lib/screen/HomePage.dart

Lines changed: 105 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:ui';
2+
13
import 'package:finacash/Helper/Movimentacoes_helper.dart';
24
import 'package:finacash/Widgets/AnimatedBottomNavBar.dart';
35
import 'package:finacash/Widgets/CardMovimentacoesItem.dart';
@@ -21,12 +23,13 @@ class _HomePageState extends State<HomePage> {
2123
var width;
2224
var height;
2325
bool recDesp = false;
24-
26+
final GlobalKey<ScaffoldState> _scafoldKey = GlobalKey<ScaffoldState>();
27+
MovimentacoesHelper movHelper = MovimentacoesHelper();
2528
TextEditingController _valorController = TextEditingController();
2629
CalendarController calendarController;
2730
MovimentacoesHelper movimentacoesHelper = MovimentacoesHelper();
2831
List<Movimentacoes> listmovimentacoes = List();
29-
32+
List<Movimentacoes> ultimaTarefaRemovida = List();
3033

3134
var dataAtual = new DateTime.now();
3235
var formatter = new DateFormat('dd-MM-yyyy');
@@ -83,7 +86,6 @@ class _HomePageState extends State<HomePage> {
8386
total =
8487
listmovimentacoes.map((item) => item.valor).reduce((a, b) => a + b);
8588
saldoAtual = format(total).toString();
86-
8789
} else {
8890
setState(() {
8991
listmovimentacoes.clear();
@@ -113,75 +115,64 @@ class _HomePageState extends State<HomePage> {
113115
//_allMov();
114116
}
115117

116-
_dialogAddRecDesp(){
117-
118+
_dialogAddRecDesp() {
118119
showDialog(
119-
context: context,
120-
builder: (context){
121-
return CustomDialog();/*AlertDialog(
122-
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
123-
title: Text("Adicionar Valores",textAlign: TextAlign.center, style: TextStyle(
124-
fontWeight: FontWeight.bold,
125-
color: Colors.lightBlue
126-
),
127-
),
128-
backgroundColor: Colors.white,
129-
content: CustomDialog()
130-
);*/
131-
}
132-
);
120+
context: context,
121+
builder: (context) {
122+
return CustomDialog();
123+
});
133124
}
134125

135126
@override
136127
Widget build(BuildContext context) {
137128
width = MediaQuery.of(context).size.width;
138129
height = MediaQuery.of(context).size.height;
139-
130+
140131
_allMovMes(dataFormatada);
141-
return Scaffold(
132+
return Scaffold(
133+
key: _scafoldKey,
142134
body: SingleChildScrollView(
143135
primary: false,
144136
physics: NeverScrollableScrollPhysics(),
145137
//height: height,
146138
//width: width,
147139
child: Column(
148-
149140
children: <Widget>[
150141
Stack(
151142
children: <Widget>[
152-
153143
Container(
154144
width: double.infinity,
155-
height: height * 0.334,//300,
145+
height: height * 0.334, //300,
156146
color: Colors.white,
157147
),
158-
159148
Positioned(
160149
top: 0,
161150
left: 0,
162151
right: 0,
163152
child: Container(
164153
width: double.infinity,
165-
height:height * 0.28 ,//250,
154+
height: height * 0.28, //250,
166155
decoration: BoxDecoration(
167-
color:Colors.lightBlue[700], //Colors.indigo[400],
156+
color: Colors.lightBlue[700], //Colors.indigo[400],
168157
)),
169158
),
170159
Positioned(
171-
top: width * 0.18,//70
172-
left: width * 0.07,//30,
173-
child: Text("FinaCash",style: TextStyle(
174-
color: Colors.white,
175-
fontSize:width * 0.074//30
176-
),),
160+
top: width * 0.18, //70
161+
left: width * 0.07, //30,
162+
child: Text(
163+
"FinaCash",
164+
style: TextStyle(
165+
color: Colors.white, fontSize: width * 0.074 //30
166+
),
167+
),
177168
),
178169
Positioned(
179170
bottom: 0,
180-
left: width *0.07,// 30,
181-
right: width *0.07,// 30,
171+
left: width * 0.07, // 30,
172+
right: width * 0.07, // 30,
182173
child: Container(
183-
height:height * 0.16, //150,
184-
width: width * 0.1,// 70,
174+
height: height * 0.16, //150,
175+
width: width * 0.1, // 70,
185176
decoration: BoxDecoration(
186177
color: Colors.white,
187178
borderRadius: BorderRadius.circular(20),
@@ -197,7 +188,11 @@ class _HomePageState extends State<HomePage> {
197188
mainAxisSize: MainAxisSize.min,
198189
children: <Widget>[
199190
Padding(
200-
padding: EdgeInsets.only(left: width * 0.05,top: width * 0.04,bottom: width * 0.02,),
191+
padding: EdgeInsets.only(
192+
left: width * 0.05,
193+
top: width * 0.04,
194+
bottom: width * 0.02,
195+
),
201196
child: Text(
202197
"Total",
203198
style: TextStyle(
@@ -210,13 +205,15 @@ class _HomePageState extends State<HomePage> {
210205
mainAxisAlignment: MainAxisAlignment.spaceBetween,
211206
children: <Widget>[
212207
Padding(
213-
padding: EdgeInsets.only(left: width * 0.05),
208+
padding: EdgeInsets.only(left: width * 0.05),
214209
child: Text(
215210
saldoAtual,
216211
style: TextStyle(
217-
color: Colors.lightBlue[700], //Colors.indigo[400],
212+
color: Colors
213+
.lightBlue[700], //Colors.indigo[400],
218214
fontWeight: FontWeight.bold,
219-
fontSize: width * 0.1 //_saldoTamanho(saldoAtual)
215+
fontSize:
216+
width * 0.1 //_saldoTamanho(saldoAtual)
220217
),
221218
),
222219
),
@@ -225,7 +222,7 @@ class _HomePageState extends State<HomePage> {
225222
child: GestureDetector(
226223
onTap: () {
227224
_dialogAddRecDesp();
228-
/* Navigator.push(
225+
/* Navigator.push(
229226
context,
230227
MaterialPageRoute(
231228
builder: (context) => AddReceita()));
@@ -235,7 +232,8 @@ class _HomePageState extends State<HomePage> {
235232
width: width * 0.12,
236233
height: width * 0.12, //65,
237234
decoration: BoxDecoration(
238-
color: Colors.lightBlue[700], //Colors.indigo[400],
235+
color: Colors
236+
.lightBlue[700], //Colors.indigo[400],
239237
borderRadius: BorderRadius.circular(50),
240238
boxShadow: [
241239
BoxShadow(
@@ -254,7 +252,9 @@ class _HomePageState extends State<HomePage> {
254252
)
255253
],
256254
),
257-
SizedBox(height: height *0.008,)
255+
SizedBox(
256+
height: height * 0.008,
257+
)
258258
],
259259
),
260260
),
@@ -288,7 +288,8 @@ class _HomePageState extends State<HomePage> {
288288
},
289289
),
290290
Padding(
291-
padding: EdgeInsets.only(left: width * 0.04, right: width * 0.04),
291+
padding:
292+
EdgeInsets.only(left: width * 0.04, right: width * 0.04),
292293
child: Row(
293294
mainAxisAlignment: MainAxisAlignment.spaceBetween,
294295
children: <Widget>[
@@ -308,21 +309,73 @@ class _HomePageState extends State<HomePage> {
308309
],
309310
)),
310311
Padding(
311-
padding: EdgeInsets.only(left: width * 0.04, right: width * 0.04, top: 0),
312+
padding: EdgeInsets.only(
313+
left: width * 0.04, right: width * 0.04, top: 0),
312314
child: SizedBox(
313315
width: width,
314316
height: height * 0.47,
315317
child: ListView.builder(
316318
itemCount: listmovimentacoes.length,
317319
itemBuilder: (context, index) {
318320
Movimentacoes mov = listmovimentacoes[index];
319-
return CardMovimentacoesItem(
320-
mov: mov,
321+
Movimentacoes ultMov = listmovimentacoes[index];
322+
return Dismissible(
323+
direction: DismissDirection.endToStart,
324+
onDismissed: (direction) {
325+
//_dialogConfimacao(context, width, mov,index);
326+
327+
setState(() {
328+
listmovimentacoes.removeAt(index);
329+
});
330+
movHelper.deleteMovimentacao(mov);
331+
final snackBar = SnackBar(
332+
content: Container(
333+
padding: EdgeInsets.only(bottom: width * 0.025),
334+
alignment: Alignment.bottomLeft,
335+
height: height * 0.05,
336+
child: Text(
337+
"Desfazer Ação",
338+
style: TextStyle(
339+
color: Colors.white,
340+
//fontWeight: FontWeight.bold,
341+
fontSize: width * 0.05),
342+
),
343+
),
344+
duration: Duration(seconds: 2),
345+
backgroundColor: Colors.orange[800],
346+
shape: RoundedRectangleBorder(
347+
borderRadius: BorderRadius.only(
348+
topLeft: Radius.circular(15),
349+
topRight: Radius.circular(15))),
350+
action: SnackBarAction(
351+
label: "Desfazer",
352+
textColor: Colors.white,
353+
onPressed: () {
354+
setState(() {
355+
listmovimentacoes.insert(index, ultMov);
356+
});
357+
358+
movHelper.saveMovimentacao(ultMov);
359+
},
360+
),
361+
);
362+
_scafoldKey.currentState.showSnackBar(snackBar);
363+
},
364+
key: ValueKey(mov.id),
365+
background: Container(
366+
padding: EdgeInsets.only(right: 10),
367+
alignment: Alignment.centerRight,
368+
color: Colors.red,
369+
child: Icon(
370+
Icons.delete_outline,
371+
color: Colors.white,
372+
size: width * 0.07,
373+
),
374+
),
375+
child: CardMovimentacoesItem(
376+
mov: mov,
377+
),
321378
);
322-
/*return ListTile(
323-
title: Text(mov.valor.toString()),
324-
subtitle: Text(mov.tipo),
325-
);*/
326379
},
327380
),
328381
),

0 commit comments

Comments
 (0)