From c0b164ec2677ae99fbf3748f4f7219577c560463 Mon Sep 17 00:00:00 2001 From: Aunali321 Date: Tue, 30 Aug 2022 19:23:37 +0530 Subject: [PATCH] feat: custom buttons for installer screen. --- assets/i18n/en.json | 1 + lib/ui/views/installer/installer_view.dart | 81 +++---------------- .../installerView/custom_material_button.dart | 68 ++++++++++++++++ 3 files changed, 79 insertions(+), 71 deletions(-) create mode 100644 lib/ui/widgets/installerView/custom_material_button.dart diff --git a/assets/i18n/en.json b/assets/i18n/en.json index 50edefc6..c89b023c 100644 --- a/assets/i18n/en.json +++ b/assets/i18n/en.json @@ -61,6 +61,7 @@ "widgetTitle": "Installer", "installButton": "Install", "openButton": "Open", + "shareButton": "Share file", "notificationTitle": "ReVanced Manager is patching", "notificationText": "Tap to return to the installer" }, diff --git a/lib/ui/views/installer/installer_view.dart b/lib/ui/views/installer/installer_view.dart index a5606a54..65abe254 100644 --- a/lib/ui/views/installer/installer_view.dart +++ b/lib/ui/views/installer/installer_view.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:flutter_i18n/flutter_i18n.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:revanced_manager/theme.dart'; import 'package:revanced_manager/ui/views/installer/installer_viewmodel.dart'; +import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart'; import 'package:stacked/stacked.dart'; class InstallerView extends StatelessWidget { @@ -88,51 +88,18 @@ class InstallerView extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.end, children: [ - //TODO: Move to separate file - TextButton( - style: ButtonStyle( - padding: MaterialStateProperty.all( - const EdgeInsets.symmetric( - horizontal: 20, - vertical: 12, - ), - ), - shape: MaterialStateProperty.all( - RoundedRectangleBorder( - borderRadius: BorderRadius.circular(100), - side: BorderSide( - width: 1, - color: Theme.of(context) - .colorScheme - .secondary, - ), - ), - ), - side: MaterialStateProperty.all( - BorderSide( - color: Theme.of(context) - .iconTheme - .color! - .withOpacity(0.4), - width: 1, - ), - ), - backgroundColor: MaterialStateProperty.all( - isDark - ? Theme.of(context) - .colorScheme - .background - : Colors.white, - ), - foregroundColor: MaterialStateProperty.all( - Theme.of(context).colorScheme.secondary, - ), - ), + CustomMaterialButton( + text: "installerView.shareButton", + isFilled: false, onPressed: () => model.shareResult(), - child: I18nText("Share file"), ), const SizedBox(width: 16), - TextButton( + CustomMaterialButton( + text: model.isInstalled + ? 'installerView.openButton' + : 'installerView.installButton', + isFilled: true, + isExpanded: true, onPressed: () { if (model.isInstalled) { model.openApp(); @@ -141,34 +108,6 @@ class InstallerView extends StatelessWidget { model.installResult(); } }, - style: ButtonStyle( - padding: MaterialStateProperty.all( - const EdgeInsets.symmetric( - horizontal: 24, - vertical: 8, - ), - ), - shape: MaterialStateProperty.all( - RoundedRectangleBorder( - borderRadius: BorderRadius.circular(100), - side: BorderSide( - width: 1, - color: Theme.of(context) - .colorScheme - .secondary, - ), - ), - ), - backgroundColor: MaterialStateProperty.all( - Theme.of(context).colorScheme.secondary, - ), - foregroundColor: MaterialStateProperty.all( - Theme.of(context).colorScheme.background, - ), - ), - child: I18nText(model.isInstalled - ? 'installerView.openButton' - : 'installerView.installButton'), ), ], ), diff --git a/lib/ui/widgets/installerView/custom_material_button.dart b/lib/ui/widgets/installerView/custom_material_button.dart new file mode 100644 index 00000000..609e451b --- /dev/null +++ b/lib/ui/widgets/installerView/custom_material_button.dart @@ -0,0 +1,68 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_i18n/widgets/I18nText.dart'; +import 'package:revanced_manager/theme.dart'; + +class CustomMaterialButton extends StatelessWidget { + final String text; + final bool isFilled; + final bool isExpanded; + final Function()? onPressed; + + const CustomMaterialButton({ + Key? key, + required this.text, + 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( + RoundedRectangleBorder( + borderRadius: BorderRadius.circular(100), + side: BorderSide( + width: 1, + color: Theme.of(context).colorScheme.secondary, + ), + ), + ), + side: MaterialStateProperty.all( + BorderSide( + color: isFilled + ? Colors.transparent + : Theme.of(context).iconTheme.color!.withOpacity(0.4), + width: 1, + ), + ), + backgroundColor: MaterialStateProperty.all( + isFilled + ? Theme.of(context).colorScheme.secondary + : isDark + ? Theme.of(context).colorScheme.background + : Colors.white, + ), + foregroundColor: MaterialStateProperty.all( + isFilled + ? Theme.of(context).colorScheme.background + : Theme.of(context).colorScheme.secondary, + ), + ), + onPressed: onPressed, + child: I18nText(text), + ); + } +}