From ead308740fa647382f6543c3a3ae8a63a60d7c2c Mon Sep 17 00:00:00 2001 From: Aunali321 Date: Fri, 23 Sep 2022 13:00:30 +0530 Subject: [PATCH] refactor: move custom button to shared dir. --- lib/ui/views/home/home_viewmodel.dart | 2 +- lib/ui/views/installer/installer_view.dart | 2 +- .../views/installer/installer_viewmodel.dart | 2 +- lib/ui/views/patcher/patcher_viewmodel.dart | 2 +- lib/ui/views/settings/settings_viewmodel.dart | 2 +- .../appInfoView/app_info_viewmodel.dart | 2 +- .../widgets/homeView/latest_commit_card.dart | 2 +- .../installerView/custom_material_button.dart | 49 ------- .../patchesSelectorView/patch_item.dart | 2 +- lib/ui/widgets/shared/application_item.dart | 2 +- .../shared/custom_material_button.dart | 129 ++++++++++++++++++ 11 files changed, 138 insertions(+), 58 deletions(-) delete mode 100644 lib/ui/widgets/installerView/custom_material_button.dart create mode 100644 lib/ui/widgets/shared/custom_material_button.dart diff --git a/lib/ui/views/home/home_viewmodel.dart b/lib/ui/views/home/home_viewmodel.dart index 62a90c23..e28c864f 100644 --- a/lib/ui/views/home/home_viewmodel.dart +++ b/lib/ui/views/home/home_viewmodel.dart @@ -15,7 +15,7 @@ import 'package:revanced_manager/services/patcher_api.dart'; import 'package:revanced_manager/services/toast.dart'; import 'package:revanced_manager/ui/views/navigation/navigation_viewmodel.dart'; import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart'; -import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart'; +import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart'; import 'package:stacked/stacked.dart'; import 'package:stacked_services/stacked_services.dart'; import 'package:timezone/timezone.dart' as tz; diff --git a/lib/ui/views/installer/installer_view.dart b/lib/ui/views/installer/installer_view.dart index 10a1f365..e9cccb71 100644 --- a/lib/ui/views/installer/installer_view.dart +++ b/lib/ui/views/installer/installer_view.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_i18n/flutter_i18n.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:revanced_manager/ui/views/installer/installer_viewmodel.dart'; -import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart'; +import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart'; import 'package:revanced_manager/ui/widgets/installerView/gradient_progress_indicator.dart'; import 'package:revanced_manager/ui/widgets/shared/custom_card.dart'; import 'package:revanced_manager/ui/widgets/shared/custom_popup_menu.dart'; diff --git a/lib/ui/views/installer/installer_viewmodel.dart b/lib/ui/views/installer/installer_viewmodel.dart index 10a90a17..70b51347 100644 --- a/lib/ui/views/installer/installer_viewmodel.dart +++ b/lib/ui/views/installer/installer_viewmodel.dart @@ -11,7 +11,7 @@ import 'package:revanced_manager/services/manager_api.dart'; import 'package:revanced_manager/services/patcher_api.dart'; import 'package:revanced_manager/services/toast.dart'; import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart'; -import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart'; +import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart'; import 'package:stacked/stacked.dart'; import 'package:wakelock/wakelock.dart'; diff --git a/lib/ui/views/patcher/patcher_viewmodel.dart b/lib/ui/views/patcher/patcher_viewmodel.dart index a1a5e4a4..9052e084 100644 --- a/lib/ui/views/patcher/patcher_viewmodel.dart +++ b/lib/ui/views/patcher/patcher_viewmodel.dart @@ -7,7 +7,7 @@ import 'package:revanced_manager/app/app.router.dart'; import 'package:revanced_manager/models/patch.dart'; import 'package:revanced_manager/models/patched_application.dart'; import 'package:revanced_manager/services/patcher_api.dart'; -import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart'; +import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart'; import 'package:stacked/stacked.dart'; import 'package:stacked_services/stacked_services.dart'; diff --git a/lib/ui/views/settings/settings_viewmodel.dart b/lib/ui/views/settings/settings_viewmodel.dart index be9b9c56..8a22036f 100644 --- a/lib/ui/views/settings/settings_viewmodel.dart +++ b/lib/ui/views/settings/settings_viewmodel.dart @@ -10,7 +10,7 @@ import 'package:path_provider/path_provider.dart'; import 'package:revanced_manager/app/app.locator.dart'; import 'package:revanced_manager/app/app.router.dart'; import 'package:revanced_manager/services/manager_api.dart'; -import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart'; +import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart'; import 'package:revanced_manager/ui/widgets/settingsView/custom_text_field.dart'; import 'package:share_extend/share_extend.dart'; import 'package:stacked/stacked.dart'; diff --git a/lib/ui/widgets/appInfoView/app_info_viewmodel.dart b/lib/ui/widgets/appInfoView/app_info_viewmodel.dart index a9533104..880acfe7 100644 --- a/lib/ui/widgets/appInfoView/app_info_viewmodel.dart +++ b/lib/ui/widgets/appInfoView/app_info_viewmodel.dart @@ -11,7 +11,7 @@ import 'package:revanced_manager/services/root_api.dart'; import 'package:revanced_manager/ui/views/home/home_viewmodel.dart'; import 'package:revanced_manager/ui/views/navigation/navigation_viewmodel.dart'; import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart'; -import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart'; +import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart'; import 'package:revanced_manager/utils/string.dart'; import 'package:stacked/stacked.dart'; diff --git a/lib/ui/widgets/homeView/latest_commit_card.dart b/lib/ui/widgets/homeView/latest_commit_card.dart index 41a1afd9..0f95625a 100644 --- a/lib/ui/widgets/homeView/latest_commit_card.dart +++ b/lib/ui/widgets/homeView/latest_commit_card.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_i18n/flutter_i18n.dart'; import 'package:revanced_manager/app/app.locator.dart'; import 'package:revanced_manager/ui/views/home/home_viewmodel.dart'; -import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart'; +import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart'; import 'package:revanced_manager/ui/widgets/shared/custom_card.dart'; class LatestCommitCard extends StatefulWidget { diff --git a/lib/ui/widgets/installerView/custom_material_button.dart b/lib/ui/widgets/installerView/custom_material_button.dart deleted file mode 100644 index b8b0690e..00000000 --- a/lib/ui/widgets/installerView/custom_material_button.dart +++ /dev/null @@ -1,49 +0,0 @@ -import 'package:flutter/material.dart'; - -class CustomMaterialButton extends StatelessWidget { - final Widget label; - final bool isFilled; - final bool isExpanded; - final Function()? onPressed; - - const CustomMaterialButton({ - Key? key, - required this.label, - this.isFilled = true, - this.isExpanded = false, - required this.onPressed, - }) : super(key: key); - - @override - Widget build(BuildContext context) { - return TextButton( - style: ButtonStyle( - padding: MaterialStateProperty.all( - isExpanded - ? const EdgeInsets.symmetric(horizontal: 24, vertical: 12) - : const EdgeInsets.symmetric(horizontal: 20, vertical: 12), - ), - shape: MaterialStateProperty.all( - StadiumBorder( - side: isFilled - ? BorderSide.none - : BorderSide( - width: 1, - color: Theme.of(context).colorScheme.primary, - ), - ), - ), - backgroundColor: MaterialStateProperty.all( - isFilled ? Theme.of(context).colorScheme.primary : Colors.transparent, - ), - foregroundColor: MaterialStateProperty.all( - isFilled - ? Theme.of(context).colorScheme.surface - : Theme.of(context).colorScheme.primary, - ), - ), - onPressed: onPressed, - child: label, - ); - } -} diff --git a/lib/ui/widgets/patchesSelectorView/patch_item.dart b/lib/ui/widgets/patchesSelectorView/patch_item.dart index 84dd1b13..29585090 100644 --- a/lib/ui/widgets/patchesSelectorView/patch_item.dart +++ b/lib/ui/widgets/patchesSelectorView/patch_item.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_i18n/flutter_i18n.dart'; -import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart'; +import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart'; import 'package:revanced_manager/ui/widgets/shared/custom_card.dart'; // ignore: must_be_immutable diff --git a/lib/ui/widgets/shared/application_item.dart b/lib/ui/widgets/shared/application_item.dart index d59faec6..16881623 100644 --- a/lib/ui/widgets/shared/application_item.dart +++ b/lib/ui/widgets/shared/application_item.dart @@ -1,7 +1,7 @@ import 'dart:typed_data'; import 'package:flutter/material.dart'; import 'package:flutter_i18n/flutter_i18n.dart'; -import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart'; +import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart'; import 'package:revanced_manager/ui/widgets/shared/custom_card.dart'; import 'package:expandable/expandable.dart'; import 'package:timeago/timeago.dart'; diff --git a/lib/ui/widgets/shared/custom_material_button.dart b/lib/ui/widgets/shared/custom_material_button.dart new file mode 100644 index 00000000..db1a3078 --- /dev/null +++ b/lib/ui/widgets/shared/custom_material_button.dart @@ -0,0 +1,129 @@ +import 'package:flutter/material.dart'; + +class CustomMaterialButton extends StatelessWidget { + final Widget label; + final bool isFilled; + final bool isExpanded; + final Function()? onPressed; + + const CustomMaterialButton({ + Key? key, + required this.label, + this.isFilled = true, + this.isExpanded = false, + required this.onPressed, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return TextButton( + style: ButtonStyle( + padding: MaterialStateProperty.all( + isExpanded + ? const EdgeInsets.symmetric(horizontal: 24, vertical: 12) + : const EdgeInsets.symmetric(horizontal: 20, vertical: 12), + ), + shape: MaterialStateProperty.all( + StadiumBorder( + side: isFilled + ? BorderSide.none + : BorderSide( + width: 1, + color: Theme.of(context).colorScheme.primary, + ), + ), + ), + backgroundColor: MaterialStateProperty.all( + isFilled ? Theme.of(context).colorScheme.primary : Colors.transparent, + ), + foregroundColor: MaterialStateProperty.all( + isFilled + ? Theme.of(context).colorScheme.surface + : Theme.of(context).colorScheme.primary, + ), + ), + onPressed: onPressed, + child: label, + ); + } +} + +class TimerButton extends StatefulWidget { + Widget label; + bool isFilled; + int seconds; + final bool isRunning; + final Function()? onTimerEnd; + + TimerButton({ + Key? key, + required this.seconds, + required this.isRunning, + required this.onTimerEnd, + this.label = const Text(''), + this.isFilled = true, + }) : super(key: key); + + @override + State createState() => _TimerButtonState(); +} + +class _TimerButtonState extends State { + void timer(int seconds) { + Future.delayed(const Duration(seconds: 1), () { + if (seconds > 0) { + setState(() { + seconds--; + }); + timer(seconds); + } else { + widget.onTimerEnd!(); + } + }); + } + + @override + void initState() { + //decrement seconds + if (widget.isRunning) { + timer(widget.seconds); + } + super.initState(); + } + + @override + Widget build(BuildContext build) { + return TextButton( + style: ButtonStyle( + shape: MaterialStateProperty.all( + StadiumBorder( + side: widget.isFilled + ? BorderSide.none + : BorderSide( + width: 1, + color: Theme.of(context).colorScheme.primary, + ), + ), + ), + backgroundColor: MaterialStateProperty.all( + widget.isFilled + ? Theme.of(context).colorScheme.primary + : Colors.transparent, + ), + foregroundColor: MaterialStateProperty.all( + widget.isFilled + ? Theme.of(context).colorScheme.surface + : Theme.of(context).colorScheme.primary, + ), + ), + onPressed: widget.isRunning ? null : widget.onTimerEnd, + child: Text( + widget.isRunning ? '${widget.seconds}' : 'Install', + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w600, + ), + ), + ); + } +}