Skip to content

Commit 83d65c6

Browse files
authored
Merge pull request #76 from Ashish-AI/feat/add-snackbar
[Feat] Add snackbar for multiple events
2 parents 29dd03d + 9474327 commit 83d65c6

File tree

4 files changed

+113
-32
lines changed

4 files changed

+113
-32
lines changed

lib/Components/add_torrent_sheet.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'dart:io';
44
import 'package:clipboard/clipboard.dart';
55
import 'package:file_picker/file_picker.dart';
66
import 'package:flood_mobile/Api/torrent_api.dart';
7+
import 'package:flood_mobile/Components/flood_snackbar.dart';
78
import 'package:flood_mobile/Constants/theme_provider.dart';
89
import 'package:flood_mobile/Model/client_settings_model.dart';
910
import 'package:flutter/material.dart';
@@ -273,6 +274,13 @@ class _AddTorrentSheetState extends State<AddTorrentSheet> {
273274
Navigator.pop(context);
274275
}
275276
}
277+
final addTorrentSnackbar = addFloodSnackBar(
278+
SnackbarType.information,
279+
'Torrent added successfully',
280+
'Dismiss');
281+
282+
ScaffoldMessenger.of(context)
283+
.showSnackBar(addTorrentSnackbar);
276284
},
277285
style: ElevatedButton.styleFrom(
278286
elevation: 0,
@@ -285,9 +293,10 @@ class _AddTorrentSheetState extends State<AddTorrentSheet> {
285293
child: Text(
286294
"Add Torrent",
287295
style: TextStyle(
288-
color: Colors.white,
289-
fontSize: 16,
290-
fontWeight: FontWeight.w600),
296+
color: Colors.white,
297+
fontSize: 16,
298+
fontWeight: FontWeight.w600,
299+
),
291300
),
292301
),
293302
),

lib/Components/delete_torrent_sheet.dart

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import 'package:flood_mobile/Constants/theme_provider.dart';
33
import 'package:flood_mobile/Model/torrent_model.dart';
44
import 'package:flutter/material.dart';
55

6+
import 'flood_snackbar.dart';
7+
68
class DeleteTorrentSheet extends StatefulWidget {
79
final TorrentModel torrent;
810

@@ -86,10 +88,10 @@ class _DeleteTorrentSheetState extends State<DeleteTorrentSheet> {
8688
child: Text(
8789
"No",
8890
style: TextStyle(
89-
color:
90-
ThemeProvider.theme.textTheme.bodyText1?.color,
91-
fontSize: 16,
92-
fontWeight: FontWeight.w900),
91+
color: ThemeProvider.theme.textTheme.bodyText1?.color,
92+
fontSize: 16,
93+
fontWeight: FontWeight.w900,
94+
),
9395
),
9496
),
9597
),
@@ -101,15 +103,23 @@ class _DeleteTorrentSheetState extends State<DeleteTorrentSheet> {
101103
Expanded(
102104
child: Container(
103105
height: MediaQuery.of(context).size.height * 0.06,
104-
decoration:
105-
BoxDecoration(borderRadius: BorderRadius.circular(20)),
106+
decoration: BoxDecoration(
107+
borderRadius: BorderRadius.circular(20),
108+
),
106109
child: ElevatedButton(
107110
onPressed: () {
108111
TorrentApi.deleteTorrent(
109112
hash: widget.torrent.hash,
110113
deleteWithData: deleteWithData,
111114
context: context);
112115
Navigator.of(context).pop();
116+
117+
final deleteTorrentSnackBar = addFloodSnackBar(
118+
SnackbarType.caution,
119+
'Torrent deleted successfuly',
120+
'Dismiss');
121+
ScaffoldMessenger.of(context)
122+
.showSnackBar(deleteTorrentSnackBar);
113123
},
114124
style: ElevatedButton.styleFrom(
115125
shape: RoundedRectangleBorder(
@@ -121,10 +131,10 @@ class _DeleteTorrentSheetState extends State<DeleteTorrentSheet> {
121131
child: Text(
122132
"Yes",
123133
style: TextStyle(
124-
color:
125-
ThemeProvider.theme.textTheme.bodyText1?.color,
126-
fontSize: 16,
127-
fontWeight: FontWeight.w900),
134+
color: ThemeProvider.theme.textTheme.bodyText1?.color,
135+
fontSize: 16,
136+
fontWeight: FontWeight.w900,
137+
),
128138
),
129139
),
130140
),

lib/Components/flood_snackbar.dart

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import 'package:flutter/material.dart';
2+
3+
enum SnackbarType {
4+
information,
5+
caution,
6+
success,
7+
}
8+
9+
SnackBar addFloodSnackBar(
10+
SnackbarType snackbarType,
11+
String title,
12+
String ctaText,
13+
) {
14+
return SnackBar(
15+
backgroundColor: snackbarType == SnackbarType.success
16+
? Colors.greenAccent
17+
: snackbarType == SnackbarType.information
18+
? Colors.lightBlueAccent
19+
: Colors.orange,
20+
content: Row(
21+
children: [
22+
Icon(
23+
snackbarType == SnackbarType.success
24+
? Icons.check_circle
25+
: snackbarType == SnackbarType.information
26+
? Icons.lightbulb_outline
27+
: Icons.warning_outlined,
28+
color: Colors.white,
29+
size: 20,
30+
),
31+
SizedBox(
32+
width: 8,
33+
),
34+
Text(
35+
title,
36+
style: TextStyle(
37+
color: Colors.white,
38+
),
39+
),
40+
],
41+
),
42+
action: SnackBarAction(
43+
label: ctaText,
44+
textColor: Colors.white,
45+
onPressed: () {},
46+
),
47+
);
48+
}

lib/Pages/settings_screen.dart

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:expansion_tile_card/expansion_tile_card.dart';
22
import 'package:flood_mobile/Api/auth_api.dart';
33
import 'package:flood_mobile/Api/client_api.dart';
4+
import 'package:flood_mobile/Components/flood_snackbar.dart';
45
import 'package:flood_mobile/Components/settings_text_field.dart';
56
import 'package:flood_mobile/Components/text_size.dart';
67
import 'package:flood_mobile/Constants/theme_provider.dart';
@@ -193,6 +194,12 @@ class _SettingsScreenState extends State<SettingsScreen> {
193194
.then((value) {
194195
setState(() {});
195196
});
197+
198+
final changeSettingsSnackBar = addFloodSnackBar(
199+
SnackbarType.success, 'Settings changed', 'Dismiss');
200+
201+
ScaffoldMessenger.of(context)
202+
.showSnackBar(changeSettingsSnackBar);
196203
},
197204
icon: Icon(
198205
Icons.save,
@@ -741,23 +748,29 @@ class AuthenticationSection extends StatelessWidget {
741748
AuthApi.registerUser(
742749
context: context,
743750
model: RegisterUserModel(
744-
username: usernameController.text,
745-
password: passwordController.text,
746-
client: client,
747-
type: (client == 'rTorrent')
748-
? (socket)
749-
? 'socket'
750-
: 'tcp'
751-
: "web",
752-
version: 1,
753-
url: urlController.text,
754-
clientUsername: clientUsernameController.text,
755-
clientPassword: clientPasswordController.text,
756-
level: isAdmin ? 10 : 5,
757-
path: pathController.text,
758-
host: hostController.text,
759-
port: int.parse(portController.text)),
751+
username: usernameController.text,
752+
password: passwordController.text,
753+
client: client,
754+
type: (client == 'rTorrent')
755+
? (socket)
756+
? 'socket'
757+
: 'tcp'
758+
: "web",
759+
version: 1,
760+
url: urlController.text,
761+
clientUsername: clientUsernameController.text,
762+
clientPassword: clientPasswordController.text,
763+
level: isAdmin ? 10 : 5,
764+
path: pathController.text,
765+
host: hostController.text,
766+
port: int.parse(portController.text),
767+
),
760768
);
769+
final addNewUserSnackBar = addFloodSnackBar(
770+
SnackbarType.success, 'New user added', 'Dismiss');
771+
772+
ScaffoldMessenger.of(context)
773+
.showSnackBar(addNewUserSnackBar);
761774
},
762775
style: ElevatedButton.styleFrom(
763776
shape: RoundedRectangleBorder(
@@ -769,9 +782,10 @@ class AuthenticationSection extends StatelessWidget {
769782
child: Text(
770783
"Add",
771784
style: TextStyle(
772-
color: Colors.white,
773-
fontSize: 16,
774-
fontWeight: FontWeight.w600),
785+
color: Colors.white,
786+
fontSize: 16,
787+
fontWeight: FontWeight.w600,
788+
),
775789
),
776790
),
777791
),

0 commit comments

Comments
 (0)