save before flutter upgrade
This commit is contained in:
93
lib/pages/widgets/animated_hover_button.dart
Normal file
93
lib/pages/widgets/animated_hover_button.dart
Normal file
@@ -0,0 +1,93 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AnimatedHoverButton extends StatefulWidget {
|
||||
const AnimatedHoverButton({
|
||||
Key? key,
|
||||
required this.primaryColor,
|
||||
required this.secondaryColor,
|
||||
required this.onTap,
|
||||
required this.icon,
|
||||
required this.tooltip,
|
||||
this.radius = 50,
|
||||
this.size = 50,
|
||||
this.enable = true,
|
||||
}) : super(key: key);
|
||||
|
||||
final Color primaryColor;
|
||||
final Color secondaryColor;
|
||||
final void Function() onTap;
|
||||
final IconData icon;
|
||||
final String tooltip;
|
||||
final double radius;
|
||||
final double size;
|
||||
final bool? enable;
|
||||
|
||||
@override
|
||||
State<AnimatedHoverButton> createState() => _AnimatedHoverButtonState();
|
||||
}
|
||||
|
||||
class _AnimatedHoverButtonState extends State<AnimatedHoverButton> {
|
||||
bool isHovered = false;
|
||||
|
||||
void setHovered(bool hovered) {
|
||||
setState(() {
|
||||
isHovered = hovered;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Color primaryColor;
|
||||
final Color secondaryColor;
|
||||
|
||||
if (!isHovered) {
|
||||
if (widget.enable == true) {
|
||||
primaryColor = widget.primaryColor;
|
||||
secondaryColor = widget.secondaryColor;
|
||||
} else {
|
||||
primaryColor = Theme.of(context).hintColor;
|
||||
secondaryColor = Theme.of(context).scaffoldBackgroundColor;
|
||||
}
|
||||
} else {
|
||||
if (widget.enable == true) {
|
||||
primaryColor = widget.secondaryColor;
|
||||
secondaryColor = widget.primaryColor;
|
||||
} else {
|
||||
primaryColor = Theme.of(context).scaffoldBackgroundColor;
|
||||
secondaryColor = Theme.of(context).hintColor;
|
||||
}
|
||||
}
|
||||
|
||||
return Tooltip(
|
||||
message: widget.tooltip,
|
||||
child: GestureDetector(
|
||||
onTap: widget.enable == true ? widget.onTap : null,
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
onEnter: (_) => setHovered(true),
|
||||
onExit: (_) => setHovered(false),
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
width: widget.size,
|
||||
height: widget.size,
|
||||
decoration: BoxDecoration(
|
||||
color: secondaryColor,
|
||||
borderRadius: BorderRadius.circular(widget.radius),
|
||||
border: Border.all(
|
||||
color: primaryColor,
|
||||
width: 1.5,
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: Icon(
|
||||
widget.icon,
|
||||
color: primaryColor,
|
||||
size: widget.size / 1.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
110
lib/pages/widgets/animated_hover_icon_text_button.dart
Normal file
110
lib/pages/widgets/animated_hover_icon_text_button.dart
Normal file
@@ -0,0 +1,110 @@
|
||||
import 'package:nethive_neo/theme/theme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AnimatedHoverIconTextButton extends StatefulWidget {
|
||||
const AnimatedHoverIconTextButton({
|
||||
Key? key,
|
||||
required this.primaryColor,
|
||||
required this.secondaryColor,
|
||||
required this.onTap,
|
||||
required this.icon,
|
||||
required this.text,
|
||||
required this.tooltip,
|
||||
this.size = 45,
|
||||
this.enable = true,
|
||||
}) : super(key: key);
|
||||
|
||||
final Color primaryColor;
|
||||
final Color secondaryColor;
|
||||
final void Function() onTap;
|
||||
final IconData icon;
|
||||
final String text;
|
||||
final String? tooltip;
|
||||
final double? size;
|
||||
final bool? enable;
|
||||
|
||||
@override
|
||||
State<AnimatedHoverIconTextButton> createState() =>
|
||||
_AnimatedHoverButtonState();
|
||||
}
|
||||
|
||||
class _AnimatedHoverButtonState extends State<AnimatedHoverIconTextButton> {
|
||||
late Color primaryColor;
|
||||
late Color secondaryColor;
|
||||
|
||||
void setColors(bool isPrimary) {
|
||||
if (isPrimary) {
|
||||
if (widget.enable == true) {
|
||||
primaryColor = widget.primaryColor;
|
||||
secondaryColor = widget.secondaryColor;
|
||||
} else {
|
||||
primaryColor = AppTheme.of(context).hintText;
|
||||
secondaryColor = AppTheme.of(context).primaryBackground;
|
||||
}
|
||||
} else {
|
||||
if (widget.enable == true) {
|
||||
primaryColor = widget.secondaryColor;
|
||||
secondaryColor = widget.primaryColor;
|
||||
} else {
|
||||
primaryColor = AppTheme.of(context).primaryBackground;
|
||||
secondaryColor = AppTheme.of(context).hintText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
primaryColor = widget.primaryColor;
|
||||
secondaryColor = widget.secondaryColor;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Tooltip(
|
||||
message: widget.tooltip,
|
||||
child: GestureDetector(
|
||||
onTap: widget.enable == true ? widget.onTap : null,
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
onEnter: (_) => setState(() => setColors(false)),
|
||||
onExit: (_) => setState(() => setColors(true)),
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
//width: (MediaQuery.of(context).size.width * 48 / 1920),
|
||||
//height: (MediaQuery.of(context).size.width * 48 / 1920),
|
||||
decoration: BoxDecoration(
|
||||
color: secondaryColor,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(16)),
|
||||
border: Border.all(
|
||||
color: primaryColor,
|
||||
width: 1.5,
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
widget.icon,
|
||||
color: primaryColor,
|
||||
size: (MediaQuery.of(context).size.width * 25 / 1920),
|
||||
),
|
||||
const SizedBox(width: 5),
|
||||
Text(
|
||||
widget.text,
|
||||
style: AppTheme.of(context).bodyText3.override(
|
||||
fontFamily: AppTheme.of(context).bodyText3Family,
|
||||
color: primaryColor,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
185
lib/pages/widgets/custom_button.dart
Normal file
185
lib/pages/widgets/custom_button.dart
Normal file
@@ -0,0 +1,185 @@
|
||||
import 'package:auto_size_text/auto_size_text.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ButtonOptions {
|
||||
ButtonOptions({
|
||||
this.textStyle,
|
||||
this.elevation,
|
||||
this.height = 50,
|
||||
this.width,
|
||||
this.padding,
|
||||
required this.color,
|
||||
this.disabledColor = const Color(0xFF57636C),
|
||||
this.disabledTextColor = const Color(0xFFc1c7cc),
|
||||
this.splashColor,
|
||||
this.iconSize,
|
||||
this.iconColor,
|
||||
this.iconPadding,
|
||||
this.borderRadius,
|
||||
this.borderSide,
|
||||
this.disabled = false,
|
||||
});
|
||||
|
||||
final TextStyle? textStyle;
|
||||
final double? elevation;
|
||||
final double? height;
|
||||
final double? width;
|
||||
final EdgeInsetsGeometry? padding;
|
||||
final Color color;
|
||||
final Color disabledColor;
|
||||
final Color disabledTextColor;
|
||||
final Color? splashColor;
|
||||
final double? iconSize;
|
||||
final Color? iconColor;
|
||||
final EdgeInsetsGeometry? iconPadding;
|
||||
final BorderRadius? borderRadius;
|
||||
final BorderSide? borderSide;
|
||||
final bool disabled;
|
||||
}
|
||||
|
||||
class CustomButton extends StatefulWidget {
|
||||
const CustomButton({
|
||||
Key? key,
|
||||
required this.text,
|
||||
required this.onPressed,
|
||||
this.icon,
|
||||
this.iconData,
|
||||
required this.options,
|
||||
this.showLoadingIndicator = true,
|
||||
}) : super(key: key);
|
||||
|
||||
final String text;
|
||||
final Widget? icon;
|
||||
final IconData? iconData;
|
||||
final Function() onPressed;
|
||||
final ButtonOptions options;
|
||||
final bool showLoadingIndicator;
|
||||
|
||||
@override
|
||||
State<CustomButton> createState() => _CustomButtonState();
|
||||
}
|
||||
|
||||
class _CustomButtonState extends State<CustomButton> {
|
||||
bool loading = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget textWidget = loading
|
||||
? Center(
|
||||
child: SizedBox(
|
||||
width: 23,
|
||||
height: 23,
|
||||
child: CircularProgressIndicator(
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
widget.options.textStyle?.color ?? Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
: AutoSizeText(
|
||||
widget.text,
|
||||
style: widget.options.textStyle,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
);
|
||||
|
||||
final onPressed =
|
||||
widget.options.disabled || (widget.showLoadingIndicator && loading)
|
||||
? null
|
||||
: () async {
|
||||
if (!widget.showLoadingIndicator) {
|
||||
widget.onPressed();
|
||||
return;
|
||||
}
|
||||
setState(() => loading = true);
|
||||
try {
|
||||
await widget.onPressed();
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setState(() => loading = false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ButtonStyle style = ButtonStyle(
|
||||
shape: MaterialStateProperty.all<OutlinedBorder>(
|
||||
RoundedRectangleBorder(
|
||||
borderRadius:
|
||||
widget.options.borderRadius ?? BorderRadius.circular(8.0),
|
||||
side: widget.options.borderSide ?? BorderSide.none,
|
||||
),
|
||||
),
|
||||
foregroundColor: MaterialStateProperty.resolveWith<Color?>(
|
||||
(states) {
|
||||
if (states.contains(MaterialState.disabled) ||
|
||||
widget.options.disabled) {
|
||||
return widget.options.disabledTextColor;
|
||||
}
|
||||
return widget.options.textStyle?.color;
|
||||
},
|
||||
),
|
||||
backgroundColor: MaterialStateProperty.resolveWith<Color>(
|
||||
(states) {
|
||||
if (states.contains(MaterialState.disabled) ||
|
||||
widget.options.disabled) {
|
||||
return widget.options.disabledColor;
|
||||
}
|
||||
return widget.options.color;
|
||||
},
|
||||
),
|
||||
overlayColor: MaterialStateProperty.resolveWith<Color?>((states) {
|
||||
if (widget.options.disabled) {
|
||||
return null;
|
||||
}
|
||||
if (states.contains(MaterialState.pressed)) {
|
||||
return widget.options.splashColor;
|
||||
}
|
||||
return null;
|
||||
}),
|
||||
padding: MaterialStateProperty.all(widget.options.padding ??
|
||||
const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0)),
|
||||
elevation:
|
||||
MaterialStateProperty.all<double>(widget.options.elevation ?? 2.0),
|
||||
mouseCursor: MaterialStateProperty.resolveWith<MouseCursor?>(
|
||||
(Set<MaterialState> states) {
|
||||
if (widget.options.disabled) {
|
||||
return SystemMouseCursors.basic;
|
||||
}
|
||||
return SystemMouseCursors.click;
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
if (widget.icon != null || widget.iconData != null) {
|
||||
return SizedBox(
|
||||
height: widget.options.height,
|
||||
width: widget.options.width,
|
||||
child: ElevatedButton.icon(
|
||||
icon: Padding(
|
||||
padding: widget.options.iconPadding ?? EdgeInsets.zero,
|
||||
child: widget.icon ??
|
||||
Icon(
|
||||
widget.iconData,
|
||||
size: widget.options.iconSize,
|
||||
color: widget.options.iconColor ??
|
||||
widget.options.textStyle?.color,
|
||||
),
|
||||
),
|
||||
label: textWidget,
|
||||
onPressed: onPressed,
|
||||
style: style,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return SizedBox(
|
||||
height: widget.options.height,
|
||||
width: widget.options.width,
|
||||
child: ElevatedButton(
|
||||
onPressed: onPressed,
|
||||
style: style,
|
||||
child: textWidget,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user