From 651a4e2421145b33ce90b267f01f10cacd42835e Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Mon, 15 May 2023 14:31:35 -0600 Subject: [PATCH] added flush bar + moved widgets --- .../delete_keys_dialog.dart | 87 ------------ .../generated_keys.dart | 128 ------------------ .../key_exist_dialog.dart | 128 ------------------ .../keys_option_modal_bottom_sheet.dart | 34 ----- .../message_snack_bar.dart | 46 ------- .../ok_button_widget.dart | 34 ----- .../user_info_widget.dart | 97 ------------- .../animated_widgets/rotate_icon.dart | 0 lib/pages/widgets/flust_bar_type.dart | 1 + lib/pages/widgets/show_flush_bar.dart | 64 +++++++++ lib/theme/app_colors.dart | 8 ++ 11 files changed, 73 insertions(+), 554 deletions(-) delete mode 100644 lib/pages/profile_screen/profile_screen_widgets/delete_keys_dialog.dart delete mode 100644 lib/pages/profile_screen/profile_screen_widgets/generated_keys.dart delete mode 100644 lib/pages/profile_screen/profile_screen_widgets/key_exist_dialog.dart delete mode 100644 lib/pages/profile_screen/profile_screen_widgets/keys_option_modal_bottom_sheet.dart delete mode 100644 lib/pages/profile_screen/profile_screen_widgets/message_snack_bar.dart delete mode 100644 lib/pages/profile_screen/profile_screen_widgets/ok_button_widget.dart delete mode 100644 lib/pages/profile_screen/profile_screen_widgets/user_info_widget.dart rename lib/pages/{ => widgets}/animated_widgets/rotate_icon.dart (100%) create mode 100644 lib/pages/widgets/flust_bar_type.dart create mode 100644 lib/pages/widgets/show_flush_bar.dart diff --git a/lib/pages/profile_screen/profile_screen_widgets/delete_keys_dialog.dart b/lib/pages/profile_screen/profile_screen_widgets/delete_keys_dialog.dart deleted file mode 100644 index 8e4874f..0000000 --- a/lib/pages/profile_screen/profile_screen_widgets/delete_keys_dialog.dart +++ /dev/null @@ -1,87 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:drifter/theme/app_colors.dart'; - -import 'ok_button_widget.dart'; - -class DeleteKeysDialog extends StatelessWidget { - const DeleteKeysDialog({ - super.key, - required this.onNoPressed, - required this.onYesPressed, - }); - - final void Function()? onNoPressed; - final void Function()? onYesPressed; - - @override - Widget build(BuildContext context) { - return Dialog( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(12), - ), - child: Container( - constraints: const BoxConstraints(maxWidth: 600), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(12), - color: Colors.white, - ), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Container( - padding: const EdgeInsets.symmetric(vertical: 24), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(12), - color: Colors.redAccent, - ), - child: const Center( - child: Text( - 'Delete Keys!', - style: TextStyle( - fontSize: 28, - fontWeight: FontWeight.bold, - color: Colors.white, - ), - ), - ), - ), - const SizedBox(height: 24), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 24), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - 'Do you want to delete your keys?', - style: TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold, - color: Colors.grey[700], - ), - ), - const SizedBox(height: 16), - Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - TextButton( - onPressed: onNoPressed, - child: Text( - 'On', - style: TextStyle(color: AppColors.mainDarkBlue), - ), - ), - OkButton( - onPressed: onYesPressed, - label: 'YES', - ), - ], - ), - ], - ), - ) - ], - ), - ), - ); - } -} diff --git a/lib/pages/profile_screen/profile_screen_widgets/generated_keys.dart b/lib/pages/profile_screen/profile_screen_widgets/generated_keys.dart deleted file mode 100644 index 4049374..0000000 --- a/lib/pages/profile_screen/profile_screen_widgets/generated_keys.dart +++ /dev/null @@ -1,128 +0,0 @@ -import 'package:flutter/material.dart'; - -import 'ok_button_widget.dart'; - -class GeneratedKeys extends StatefulWidget { - const GeneratedKeys({ - super.key, - required this.npubEncoded, - required this.nsecEncoded, - required this.hexPriv, - required this.hexPub, - }); - - final String npubEncoded; - final String nsecEncoded; - final String hexPriv; - final String hexPub; - - @override - State createState() => _GeneratedKeysState(); -} - -class _GeneratedKeysState extends State { - bool _toHex = false; - - @override - Widget build(BuildContext context) { - return Dialog( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(12), - ), - child: Container( - constraints: const BoxConstraints(maxWidth: 600), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(12), - color: Colors.white, - ), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Container( - padding: const EdgeInsets.symmetric(vertical: 24), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(12), - color: Colors.indigo, - ), - child: const Center( - child: Text( - 'Keys', - style: TextStyle( - fontSize: 28, - fontWeight: FontWeight.bold, - color: Colors.white, - ), - ), - ), - ), - const SizedBox(height: 24), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 24), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - 'Public Key', - style: TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold, - color: Colors.grey[700], - ), - ), - const SizedBox(height: 12), - SelectableText( - _toHex ? widget.hexPub : widget.npubEncoded, - style: TextStyle( - fontSize: 16, - color: Colors.grey[800], - ), - ), - const SizedBox(height: 24), - Text( - 'Private Key', - style: TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold, - color: Colors.grey[700], - ), - ), - const SizedBox(height: 12), - SelectableText( - _toHex ? widget.hexPriv : widget.nsecEncoded, - style: const TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold, - color: Colors.redAccent, - ), - ), - const SizedBox(height: 24), - Row( - mainAxisAlignment: MainAxisAlignment - .spaceBetween, // Changed to space between to create space for icon buttons - children: [ - IconButton( - onPressed: () { - setState(() { - _toHex = !_toHex; - }); - }, - icon: const Icon(Icons.autorenew_outlined), - color: Colors.grey[700], - ), - OkButton( - onPressed: () { - Navigator.pop(context); - }, - label: 'OK', - ), - ], - ) - ], - ), - ), - ], - ), - ), - ); - } -} diff --git a/lib/pages/profile_screen/profile_screen_widgets/key_exist_dialog.dart b/lib/pages/profile_screen/profile_screen_widgets/key_exist_dialog.dart deleted file mode 100644 index d74e34f..0000000 --- a/lib/pages/profile_screen/profile_screen_widgets/key_exist_dialog.dart +++ /dev/null @@ -1,128 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:drifter/theme/app_colors.dart'; - -import 'ok_button_widget.dart'; - -class KeysExistDialog extends StatefulWidget { - const KeysExistDialog({ - super.key, - required this.npubEncoded, - required this.nsecEncoded, - required this.hexPriv, - required this.hexPub, - }); - - final String npubEncoded; - final String nsecEncoded; - final String hexPriv; - final String hexPub; - - @override - State createState() => _KeysExistDialogState(); -} - -class _KeysExistDialogState extends State { - bool _toHex = false; - - @override - Widget build(BuildContext context) { - return Dialog( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(12), - ), - child: Container( - constraints: const BoxConstraints(maxWidth: 600), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(12), - color: Colors.white, - ), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Container( - padding: const EdgeInsets.symmetric(vertical: 24), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(12), - color: AppColors.mainDarkBlue, - ), - child: const Center( - child: Text( - 'Keys', - style: TextStyle( - fontSize: 28, - fontWeight: FontWeight.bold, - color: Colors.white, - ), - ), - ), - ), - const SizedBox(height: 24), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 24), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - 'Public Key', - style: TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold, - color: Colors.grey[700], - ), - ), - const SizedBox(height: 12), - SelectableText( - _toHex ? widget.hexPub : widget.npubEncoded, - style: TextStyle( - fontSize: 16, - color: Colors.grey[800], - ), - ), - const SizedBox(height: 24), - Text( - 'Private Key', - style: TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold, - color: Colors.grey[700], - ), - ), - const SizedBox(height: 12), - SelectableText( - _toHex ? widget.hexPriv : widget.nsecEncoded, - style: TextStyle( - fontSize: 16, - color: Colors.grey[800], - ), - ), - const SizedBox(height: 24), - Row( - mainAxisAlignment: MainAxisAlignment - .spaceBetween, // Changed to space between to create space for icon buttons - children: [ - IconButton( - onPressed: () { - setState(() { - _toHex = !_toHex; - }); - }, - icon: const Icon(Icons.autorenew_outlined), - color: Colors.grey[700], - ), - OkButton( - onPressed: () { - Navigator.pop(context); - }, - label: 'OK', - ), - ], - ) - ], - ), - ), - ], - ), - ), - ); - } -} diff --git a/lib/pages/profile_screen/profile_screen_widgets/keys_option_modal_bottom_sheet.dart b/lib/pages/profile_screen/profile_screen_widgets/keys_option_modal_bottom_sheet.dart deleted file mode 100644 index 25ad2e5..0000000 --- a/lib/pages/profile_screen/profile_screen_widgets/keys_option_modal_bottom_sheet.dart +++ /dev/null @@ -1,34 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:drifter/theme/app_colors.dart'; - -class KeysOptionModalBottomSheet extends StatelessWidget { - const KeysOptionModalBottomSheet({ - super.key, - required this.generateNewKeyPressed, - }); - - final void Function()? generateNewKeyPressed; - - @override - Widget build(BuildContext context) { - return Container( - padding: const EdgeInsets.all(20), - decoration: BoxDecoration(color: AppColors.mainDarkBlue), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - ElevatedButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all(Colors.white)), - onPressed: generateNewKeyPressed, - child: Text( - 'Generate New Key', - style: TextStyle(color: AppColors.mainDarkBlue), - ), - ), - const SizedBox(height: 10), - ], - ), - ); - } -} diff --git a/lib/pages/profile_screen/profile_screen_widgets/message_snack_bar.dart b/lib/pages/profile_screen/profile_screen_widgets/message_snack_bar.dart deleted file mode 100644 index d5c4fd1..0000000 --- a/lib/pages/profile_screen/profile_screen_widgets/message_snack_bar.dart +++ /dev/null @@ -1,46 +0,0 @@ -import 'package:flutter/material.dart'; - -class MessageSnackBar extends SnackBar { - MessageSnackBar({Key? key, required this.label, this.isWarning = false}) - : super( - key: key, - content: _GenericErrorSnackBarMessage( - label: label, - isWarning: isWarning, - ), - backgroundColor: isWarning! ? Colors.red : Colors.white, - elevation: 6.0, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10.0), - ), - behavior: SnackBarBehavior.fixed, - ); - - final String label; - final bool? isWarning; -} - -class _GenericErrorSnackBarMessage extends StatelessWidget { - const _GenericErrorSnackBarMessage({ - Key? key, - required this.label, - this.isWarning, - }) : super(key: key); - - final String label; - final bool? isWarning; - - @override - Widget build(BuildContext context) { - return Container( - padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0), - child: Text( - label, - style: TextStyle( - color: isWarning! ? Colors.white : Colors.black, - fontSize: 16.0, - ), - ), - ); - } -} diff --git a/lib/pages/profile_screen/profile_screen_widgets/ok_button_widget.dart b/lib/pages/profile_screen/profile_screen_widgets/ok_button_widget.dart deleted file mode 100644 index 6dbaad7..0000000 --- a/lib/pages/profile_screen/profile_screen_widgets/ok_button_widget.dart +++ /dev/null @@ -1,34 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:drifter/theme/app_colors.dart'; - -class OkButton extends StatelessWidget { - const OkButton({ - super.key, - required this.onPressed, - required this.label, - }); - - final void Function()? onPressed; - final String label; - - @override - Widget build(BuildContext context) { - return ElevatedButton( - onPressed: onPressed, - style: ElevatedButton.styleFrom( - backgroundColor: AppColors.mainDarkBlue, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(8), - ), - ), - child: Text( - label, - style: const TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold, - color: Colors.white, - ), - ), - ); - } -} diff --git a/lib/pages/profile_screen/profile_screen_widgets/user_info_widget.dart b/lib/pages/profile_screen/profile_screen_widgets/user_info_widget.dart deleted file mode 100644 index 53c47f4..0000000 --- a/lib/pages/profile_screen/profile_screen_widgets/user_info_widget.dart +++ /dev/null @@ -1,97 +0,0 @@ -import 'package:drifter/theme/app_colors.dart'; -import 'package:flutter/material.dart'; - -class UserInfo extends StatelessWidget { - const UserInfo({super.key}); - - @override - Widget build(BuildContext context) { - return Container( - child: Column( - children: [ - AvatarWidget(), - SizedBox( - height: 10, - ), - UserNameWidget(), - ], - ), - ); - } -} - -class AvatarWidget extends StatelessWidget { - const AvatarWidget({super.key}); - - @override - Widget build(BuildContext context) { - return Container( - decoration: BoxDecoration( - border: Border.all(color: Colors.black), - borderRadius: BorderRadius.all(Radius.circular(75))), - width: 150, - height: 150, - ); - } -} - -class UserNameWidget extends StatefulWidget { - const UserNameWidget({super.key}); - - @override - State createState() => _UserNameWidgetState(); -} - -class _UserNameWidgetState extends State { - late final TextEditingController messageController; - late final FocusNode messageFocusNode; - - @override - void initState() { - messageController = TextEditingController(); - messageFocusNode = FocusNode(); - - super.initState(); - } - - @override - void dispose() { - messageController.dispose(); - messageFocusNode.dispose(); - - super.dispose(); - } - - @override - Widget build(BuildContext context) { - return Padding( - padding: const EdgeInsets.all(4.0), - child: ClipRRect( - borderRadius: const BorderRadius.all( - Radius.circular( - 0.0, - ), - ), - child: TextField( - controller: messageController, - focusNode: messageFocusNode, - style: const TextStyle( - fontSize: 14, - ), - decoration: InputDecoration( - hintText: 'Username', - hintStyle: const TextStyle(fontSize: 14), - suffixIcon: IconButton( - icon: const Icon( - Icons.send, - color: AppColors.mainDarkBlue, - size: 30, - ), - onPressed: () {}, - ), - ), - ), - ), - ); - } -} diff --git a/lib/pages/animated_widgets/rotate_icon.dart b/lib/pages/widgets/animated_widgets/rotate_icon.dart similarity index 100% rename from lib/pages/animated_widgets/rotate_icon.dart rename to lib/pages/widgets/animated_widgets/rotate_icon.dart diff --git a/lib/pages/widgets/flust_bar_type.dart b/lib/pages/widgets/flust_bar_type.dart new file mode 100644 index 0000000..e356991 --- /dev/null +++ b/lib/pages/widgets/flust_bar_type.dart @@ -0,0 +1 @@ +enum FlushBarType { success, info, warning } diff --git a/lib/pages/widgets/show_flush_bar.dart b/lib/pages/widgets/show_flush_bar.dart new file mode 100644 index 0000000..0b3140c --- /dev/null +++ b/lib/pages/widgets/show_flush_bar.dart @@ -0,0 +1,64 @@ +import 'package:another_flushbar/flushbar.dart'; +import 'package:another_flushbar/flushbar_route.dart' as flushRoute; +import 'package:drifter/pages/widgets/flust_bar_type.dart'; +import 'package:drifter/theme/app_colors.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_svg/svg.dart'; + +Future showFloatingFlushBar({ + required FlushBarType type, + required String message, + String? iconAsset, + required BuildContext context, + Duration? duration = const Duration(milliseconds: 1500), + FlushbarPosition flushbarPosition = FlushbarPosition.TOP, + VoidCallback? onTap, +}) { + Color bg; + Color fg; + switch (type) { + case FlushBarType.success: + fg = AppColors.snackBarTextSuccess; + bg = AppColors.snackBarBackSuccess; + break; + case FlushBarType.info: + fg = AppColors.snackBarTextInfo; + bg = AppColors.snackBarBackInfo; + break; + case FlushBarType.warning: + fg = AppColors.snackBarTextError; + bg = AppColors.snackBarBackError; + break; + } + final bar = Flushbar( + onTap: (_) { + onTap?.call(); + }, + icon: iconAsset != null + ? SvgPicture.asset( + iconAsset, + height: 16, + width: 16, + // color: fg, + ) + : null, + message: message, + messageColor: fg, + flushbarPosition: flushbarPosition, + backgroundColor: bg, + duration: duration, + flushbarStyle: FlushbarStyle.FLOATING, + borderRadius: BorderRadius.circular( + 8.0, + ), + margin: const EdgeInsets.all(20), + maxWidth: MediaQuery.of(context).size.width - 50, + ); + + final _route = flushRoute.showFlushbar( + context: context, + flushbar: bar, + ); + + return Navigator.of(context, rootNavigator: true).push(_route); +} diff --git a/lib/theme/app_colors.dart b/lib/theme/app_colors.dart index f1b06ae..6a27d43 100644 --- a/lib/theme/app_colors.dart +++ b/lib/theme/app_colors.dart @@ -5,6 +5,14 @@ abstract class AppColors { static const mainAccent = const Color(0xFFFFCC11); static const mainBackground = const Color(0xFFF2EFFF); + // snack bar + static const snackBarBackSuccess = const Color(0xFFB9E9D4); + static const snackBarBackError = const Color(0xFFFFDAD4); + static const snackBarBackInfo = const Color(0xFFDAE2FF); + static const snackBarTextSuccess = const Color(0xFF006C4D); + static const snackBarTextError = const Color(0xFF930006); + static const snackBarTextInfo = const Color(0xFF002A78); + static const mainDarkBlue = Color.fromRGBO(3, 37, 65, 1); static const mainLightBlue = Color.fromRGBO(48, 86, 117, 1); }