From 7d913530e56479aa045e687f9e3da9d419512662 Mon Sep 17 00:00:00 2001 From: Ashish Chaubey Date: Wed, 9 Mar 2022 11:47:46 +0530 Subject: [PATCH 1/4] add torrent snackbar --- lib/Components/add_torrent_sheet.dart | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/Components/add_torrent_sheet.dart b/lib/Components/add_torrent_sheet.dart index 3a5b8700..1a482925 100644 --- a/lib/Components/add_torrent_sheet.dart +++ b/lib/Components/add_torrent_sheet.dart @@ -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'; @@ -267,6 +268,13 @@ class _AddTorrentSheetState extends State { Navigator.pop(context); } } + final addTorrentSnackbar = addFloodSnackBar( + SnackbarType.information, + 'Torrent added successfully', + 'Dismiss'); + + ScaffoldMessenger.of(context) + .showSnackBar(addTorrentSnackbar); }, style: ElevatedButton.styleFrom( elevation: 0, @@ -279,9 +287,10 @@ class _AddTorrentSheetState extends State { child: Text( "Add Torrent", style: TextStyle( - color: Colors.white, - fontSize: 16, - fontWeight: FontWeight.w600), + color: Colors.white, + fontSize: 16, + fontWeight: FontWeight.w600, + ), ), ), ), From b0950e881efd806412b84c234c0ac1e5e17b7a83 Mon Sep 17 00:00:00 2001 From: Ashish Chaubey Date: Wed, 9 Mar 2022 11:48:14 +0530 Subject: [PATCH 2/4] delete torrent snackbar --- lib/Components/delete_torrent_sheet.dart | 30 ++++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/Components/delete_torrent_sheet.dart b/lib/Components/delete_torrent_sheet.dart index 4e7cff18..38e23d4c 100644 --- a/lib/Components/delete_torrent_sheet.dart +++ b/lib/Components/delete_torrent_sheet.dart @@ -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; @@ -85,10 +87,10 @@ class _DeleteTorrentSheetState extends State { 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, + ), ), ), ), @@ -100,8 +102,9 @@ class _DeleteTorrentSheetState extends State { 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( @@ -109,6 +112,13 @@ class _DeleteTorrentSheetState extends State { 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( @@ -120,10 +130,10 @@ class _DeleteTorrentSheetState extends State { 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, + ), ), ), ), From dfa020a047cf0574de03a24a38b9287911553d0e Mon Sep 17 00:00:00 2001 From: Ashish Chaubey Date: Wed, 9 Mar 2022 11:48:27 +0530 Subject: [PATCH 3/4] add snackbar component --- lib/Components/flood_snackbar.dart | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 lib/Components/flood_snackbar.dart diff --git a/lib/Components/flood_snackbar.dart b/lib/Components/flood_snackbar.dart new file mode 100644 index 00000000..70ef7efc --- /dev/null +++ b/lib/Components/flood_snackbar.dart @@ -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: () {}, + ), + ); +} From 9474327202b5e9bb8fa4d0feecf81c64043649ca Mon Sep 17 00:00:00 2001 From: Ashish Chaubey Date: Wed, 9 Mar 2022 11:49:42 +0530 Subject: [PATCH 4/4] add torrent on adding a user and saving settings --- lib/Pages/settings_screen.dart | 52 +++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/lib/Pages/settings_screen.dart b/lib/Pages/settings_screen.dart index d5c4ce81..e720d903 100644 --- a/lib/Pages/settings_screen.dart +++ b/lib/Pages/settings_screen.dart @@ -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'; @@ -194,6 +195,12 @@ class _SettingsScreenState extends State { .then((value) { setState(() {}); }); + + final changeSettingsSnackBar = addFloodSnackBar( + SnackbarType.success, 'Settings changed', 'Dismiss'); + + ScaffoldMessenger.of(context) + .showSnackBar(changeSettingsSnackBar); }, icon: Icon( Icons.save, @@ -735,23 +742,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( @@ -763,9 +776,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, + ), ), ), ),