used enum for IconButton types

This commit is contained in:
ashilkn 2022-11-02 19:49:39 +05:30
parent bd96b44976
commit aba878a1fd
6 changed files with 29 additions and 23 deletions

View file

@ -29,7 +29,7 @@ class BackupSettingsScreen extends StatelessWidget {
actionIcons: [
IconButtonWidget(
icon: Icons.close_outlined,
isSecondary: true,
iconButtonType: IconButtonType.secondary,
onTap: () {
Navigator.pop(context);
Navigator.pop(context);

View file

@ -20,7 +20,7 @@ class _HomeHeaderWidgetState extends State<HomeHeaderWidget> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButtonWidget(
isPrimary: true,
iconButtonType: IconButtonType.primary,
icon: Icons.menu_outlined,
onTap: () {
Scaffold.of(context).openDrawer();

View file

@ -2,10 +2,14 @@ import 'package:flutter/material.dart';
import 'package:photos/theme/colors.dart';
import 'package:photos/theme/ente_theme.dart';
enum IconButtonType {
primary,
secondary,
rounded,
}
class IconButtonWidget extends StatefulWidget {
final bool isPrimary;
final bool isSecondary;
final bool isRounded;
final IconButtonType iconButtonType;
final IconData icon;
final bool disableGestureDetector;
final VoidCallback? onTap;
@ -14,9 +18,7 @@ class IconButtonWidget extends StatefulWidget {
final Color? iconColor;
const IconButtonWidget({
required this.icon,
this.isPrimary = false,
this.isSecondary = false,
this.isRounded = false,
required this.iconButtonType,
this.disableGestureDetector = false,
this.onTap,
this.defaultColor,
@ -41,13 +43,12 @@ class _IconButtonWidgetState extends State<IconButtonWidget> {
@override
Widget build(BuildContext context) {
if (!widget.isPrimary && !widget.isRounded && !widget.isSecondary) {
return const SizedBox.shrink();
}
final colorTheme = getEnteColorScheme(context);
iconStateColor ??
(iconStateColor = widget.defaultColor ??
(widget.isRounded ? colorTheme.fillFaint : null));
(widget.iconButtonType == IconButtonType.rounded
? colorTheme.fillFaint
: null));
return widget.disableGestureDetector
? _iconButton(colorTheme)
: GestureDetector(
@ -72,7 +73,7 @@ class _IconButtonWidgetState extends State<IconButtonWidget> {
child: Icon(
widget.icon,
color: widget.iconColor ??
(widget.isSecondary
(widget.iconButtonType == IconButtonType.secondary
? colorTheme.strokeMuted
: colorTheme.strokeBase),
size: 24,
@ -85,7 +86,9 @@ class _IconButtonWidgetState extends State<IconButtonWidget> {
final colorTheme = getEnteColorScheme(context);
setState(() {
iconStateColor = widget.pressedColor ??
(widget.isRounded ? colorTheme.fillMuted : colorTheme.fillFaint);
(widget.iconButtonType == IconButtonType.rounded
? colorTheme.fillMuted
: colorTheme.fillFaint);
});
}

View file

@ -54,7 +54,7 @@ class NotificationWarningWidget extends StatelessWidget {
const SizedBox(width: 12),
IconButtonWidget(
icon: actionIcon,
isRounded: true,
iconButtonType: IconButtonType.rounded,
iconColor: strokeBaseDark,
defaultColor: fillFaintDark,
pressedColor: fillMutedDark,

View file

@ -3,6 +3,7 @@ import 'package:photos/theme/ente_theme.dart';
import 'package:photos/ui/components/icon_button_widget.dart';
class TitleBarWidget extends StatelessWidget {
final IconButtonWidget? leading;
final String? title;
final String? caption;
final Widget? flexibleSpaceTitle;
@ -11,6 +12,7 @@ class TitleBarWidget extends StatelessWidget {
final bool isTitleH2WithoutLeading;
final bool isFlexibleSpaceDisabled;
const TitleBarWidget({
this.leading,
this.title,
this.caption,
this.flexibleSpaceTitle,
@ -67,13 +69,14 @@ class TitleBarWidget extends StatelessWidget {
],
leading: isTitleH2WithoutLeading
? null
: IconButtonWidget(
icon: Icons.arrow_back_outlined,
isPrimary: true,
onTap: () {
Navigator.pop(context);
},
),
: leading ??
IconButtonWidget(
icon: Icons.arrow_back_outlined,
iconButtonType: IconButtonType.primary,
onTap: () {
Navigator.pop(context);
},
),
flexibleSpace: isFlexibleSpaceDisabled
? null
: FlexibleSpaceBar(

View file

@ -34,7 +34,7 @@ class _SearchIconWidgetState extends State<SearchIconWidget> {
return Hero(
tag: "search_icon",
child: IconButtonWidget(
isPrimary: true,
iconButtonType: IconButtonType.primary,
icon: Icons.search,
onTap: () {
Navigator.push(