Skip to content

Commit

Permalink
Merge pull request #76 from Ashish-AI/feat/add-snackbar
Browse files Browse the repository at this point in the history
[Feat] Add snackbar for multiple events
  • Loading branch information
Akshatji800 committed Dec 11, 2022
2 parents 29dd03d + 9474327 commit 83d65c6
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 32 deletions.
15 changes: 12 additions & 3 deletions lib/Components/add_torrent_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:io';
import 'package:clipboard/clipboard.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flood_mobile/Api/torrent_api.dart';
import 'package:flood_mobile/Components/flood_snackbar.dart';
import 'package:flood_mobile/Constants/theme_provider.dart';
import 'package:flood_mobile/Model/client_settings_model.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -273,6 +274,13 @@ class _AddTorrentSheetState extends State<AddTorrentSheet> {
Navigator.pop(context);
}
}
final addTorrentSnackbar = addFloodSnackBar(
SnackbarType.information,
'Torrent added successfully',
'Dismiss');

ScaffoldMessenger.of(context)
.showSnackBar(addTorrentSnackbar);
},
style: ElevatedButton.styleFrom(
elevation: 0,
Expand All @@ -285,9 +293,10 @@ class _AddTorrentSheetState extends State<AddTorrentSheet> {
child: Text(
"Add Torrent",
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.w600),
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
),
),
Expand Down
30 changes: 20 additions & 10 deletions lib/Components/delete_torrent_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'package:flood_mobile/Constants/theme_provider.dart';
import 'package:flood_mobile/Model/torrent_model.dart';
import 'package:flutter/material.dart';

import 'flood_snackbar.dart';

class DeleteTorrentSheet extends StatefulWidget {
final TorrentModel torrent;

Expand Down Expand Up @@ -86,10 +88,10 @@ class _DeleteTorrentSheetState extends State<DeleteTorrentSheet> {
child: Text(
"No",
style: TextStyle(
color:
ThemeProvider.theme.textTheme.bodyText1?.color,
fontSize: 16,
fontWeight: FontWeight.w900),
color: ThemeProvider.theme.textTheme.bodyText1?.color,
fontSize: 16,
fontWeight: FontWeight.w900,
),
),
),
),
Expand All @@ -101,15 +103,23 @@ class _DeleteTorrentSheetState extends State<DeleteTorrentSheet> {
Expanded(
child: Container(
height: MediaQuery.of(context).size.height * 0.06,
decoration:
BoxDecoration(borderRadius: BorderRadius.circular(20)),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
),
child: ElevatedButton(
onPressed: () {
TorrentApi.deleteTorrent(
hash: widget.torrent.hash,
deleteWithData: deleteWithData,
context: context);
Navigator.of(context).pop();

final deleteTorrentSnackBar = addFloodSnackBar(
SnackbarType.caution,
'Torrent deleted successfuly',
'Dismiss');
ScaffoldMessenger.of(context)
.showSnackBar(deleteTorrentSnackBar);
},
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
Expand All @@ -121,10 +131,10 @@ class _DeleteTorrentSheetState extends State<DeleteTorrentSheet> {
child: Text(
"Yes",
style: TextStyle(
color:
ThemeProvider.theme.textTheme.bodyText1?.color,
fontSize: 16,
fontWeight: FontWeight.w900),
color: ThemeProvider.theme.textTheme.bodyText1?.color,
fontSize: 16,
fontWeight: FontWeight.w900,
),
),
),
),
Expand Down
48 changes: 48 additions & 0 deletions lib/Components/flood_snackbar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import 'package:flutter/material.dart';

enum SnackbarType {
information,
caution,
success,
}

SnackBar addFloodSnackBar(
SnackbarType snackbarType,
String title,
String ctaText,
) {
return SnackBar(
backgroundColor: snackbarType == SnackbarType.success
? Colors.greenAccent
: snackbarType == SnackbarType.information
? Colors.lightBlueAccent
: Colors.orange,
content: Row(
children: [
Icon(
snackbarType == SnackbarType.success
? Icons.check_circle
: snackbarType == SnackbarType.information
? Icons.lightbulb_outline
: Icons.warning_outlined,
color: Colors.white,
size: 20,
),
SizedBox(
width: 8,
),
Text(
title,
style: TextStyle(
color: Colors.white,
),
),
],
),
action: SnackBarAction(
label: ctaText,
textColor: Colors.white,
onPressed: () {},
),
);
}
52 changes: 33 additions & 19 deletions lib/Pages/settings_screen.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:expansion_tile_card/expansion_tile_card.dart';
import 'package:flood_mobile/Api/auth_api.dart';
import 'package:flood_mobile/Api/client_api.dart';
import 'package:flood_mobile/Components/flood_snackbar.dart';
import 'package:flood_mobile/Components/settings_text_field.dart';
import 'package:flood_mobile/Components/text_size.dart';
import 'package:flood_mobile/Constants/theme_provider.dart';
Expand Down Expand Up @@ -193,6 +194,12 @@ class _SettingsScreenState extends State<SettingsScreen> {
.then((value) {
setState(() {});
});

final changeSettingsSnackBar = addFloodSnackBar(
SnackbarType.success, 'Settings changed', 'Dismiss');

ScaffoldMessenger.of(context)
.showSnackBar(changeSettingsSnackBar);
},
icon: Icon(
Icons.save,
Expand Down Expand Up @@ -741,23 +748,29 @@ class AuthenticationSection extends StatelessWidget {
AuthApi.registerUser(
context: context,
model: RegisterUserModel(
username: usernameController.text,
password: passwordController.text,
client: client,
type: (client == 'rTorrent')
? (socket)
? 'socket'
: 'tcp'
: "web",
version: 1,
url: urlController.text,
clientUsername: clientUsernameController.text,
clientPassword: clientPasswordController.text,
level: isAdmin ? 10 : 5,
path: pathController.text,
host: hostController.text,
port: int.parse(portController.text)),
username: usernameController.text,
password: passwordController.text,
client: client,
type: (client == 'rTorrent')
? (socket)
? 'socket'
: 'tcp'
: "web",
version: 1,
url: urlController.text,
clientUsername: clientUsernameController.text,
clientPassword: clientPasswordController.text,
level: isAdmin ? 10 : 5,
path: pathController.text,
host: hostController.text,
port: int.parse(portController.text),
),
);
final addNewUserSnackBar = addFloodSnackBar(
SnackbarType.success, 'New user added', 'Dismiss');

ScaffoldMessenger.of(context)
.showSnackBar(addNewUserSnackBar);
},
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
Expand All @@ -769,9 +782,10 @@ class AuthenticationSection extends StatelessWidget {
child: Text(
"Add",
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.w600),
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
),
),
Expand Down

0 comments on commit 83d65c6

Please sign in to comment.