登录流程已全部重构
This commit is contained in:
75
lib/widgets/ui_kit/button/app_button.dart
Normal file
75
lib/widgets/ui_kit/button/app_button.dart
Normal file
@@ -0,0 +1,75 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../utils/enums/ui_theme.dart';
|
||||
import '../utils/enums/ui_variant.dart';
|
||||
import '../utils/theme/ui_color.dart';
|
||||
|
||||
class AppButton extends StatelessWidget {
|
||||
final Widget child;
|
||||
final VoidCallback? onPressed;
|
||||
final UiThemeType type;
|
||||
final UiVariant variant;
|
||||
final bool loading;
|
||||
final bool round;
|
||||
final bool disabled;
|
||||
|
||||
const AppButton({
|
||||
super.key,
|
||||
required this.child,
|
||||
this.onPressed,
|
||||
this.type = UiThemeType.primary,
|
||||
this.variant = UiVariant.solid,
|
||||
this.loading = false,
|
||||
this.round = true,
|
||||
this.disabled = false,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
//设置颜色
|
||||
final scheme = UiColor.getColorScheme(
|
||||
context,
|
||||
type: type,
|
||||
variant: variant,
|
||||
);
|
||||
|
||||
return Opacity(
|
||||
opacity: disabled ? 0.5 : 1,
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
if (!loading && !disabled) {
|
||||
onPressed?.call();
|
||||
}
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: scheme.background,
|
||||
// 应用自定义颜色
|
||||
shadowColor: Colors.transparent,
|
||||
foregroundColor: scheme.foreground,
|
||||
shape: round
|
||||
? const StadiumBorder()
|
||||
: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
spacing: 8,
|
||||
children: [
|
||||
Visibility(
|
||||
visible: loading,
|
||||
child: SizedBox.square(
|
||||
dimension: 15,
|
||||
child: CircularProgressIndicator(
|
||||
color: scheme.foreground,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
),
|
||||
),
|
||||
child,
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
///自定义按钮
|
||||
///包括loading功能
|
||||
class CustomButton extends StatelessWidget {
|
||||
final Widget child;
|
||||
final VoidCallback? onPressed;
|
||||
final bool loading;
|
||||
final bool round;
|
||||
final bool disabled;
|
||||
|
||||
const CustomButton({
|
||||
super.key,
|
||||
required this.child,
|
||||
this.onPressed,
|
||||
this.loading = false,
|
||||
this.round = true,
|
||||
this.disabled = false,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
///自定义颜色
|
||||
// switch (size) {
|
||||
// case ButtonSize.small:
|
||||
// height = 28;
|
||||
// loadingSize = 16;
|
||||
// fontSize = 12;
|
||||
// padding = const EdgeInsets.symmetric(horizontal: 12);
|
||||
// break;
|
||||
// case ButtonSize.large:
|
||||
// height = 48;
|
||||
// loadingSize = 24;
|
||||
// fontSize = 18;
|
||||
// padding = const EdgeInsets.symmetric(horizontal: 20);
|
||||
// break;
|
||||
// case ButtonSize.medium:
|
||||
// height = 45;
|
||||
// loadingSize = 15;
|
||||
// fontSize = 16;
|
||||
// padding = const EdgeInsets.symmetric(horizontal: 16);
|
||||
// break;
|
||||
// }
|
||||
|
||||
void handClick() {
|
||||
if (!loading && !disabled) {
|
||||
onPressed?.call();
|
||||
}
|
||||
}
|
||||
|
||||
return Opacity(
|
||||
opacity: disabled ? 0.5 : 1,
|
||||
child: ElevatedButton(
|
||||
onPressed: handClick,
|
||||
style: ElevatedButton.styleFrom(
|
||||
shape: round
|
||||
? const StadiumBorder()
|
||||
: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Visibility(
|
||||
visible: loading,
|
||||
child: Container(
|
||||
margin: EdgeInsets.only(right: 8),
|
||||
child: SizedBox.square(
|
||||
dimension: 15,
|
||||
child: CircularProgressIndicator(
|
||||
color: Colors.white,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
child,
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
7
lib/widgets/ui_kit/utils/enums/ui_theme.dart
Normal file
7
lib/widgets/ui_kit/utils/enums/ui_theme.dart
Normal file
@@ -0,0 +1,7 @@
|
||||
// 主题风格
|
||||
enum UiThemeType {
|
||||
primary,
|
||||
success,
|
||||
warning,
|
||||
danger,
|
||||
}
|
||||
5
lib/widgets/ui_kit/utils/enums/ui_variant.dart
Normal file
5
lib/widgets/ui_kit/utils/enums/ui_variant.dart
Normal file
@@ -0,0 +1,5 @@
|
||||
//定义Variant
|
||||
enum UiVariant {
|
||||
solid,
|
||||
plain,
|
||||
}
|
||||
46
lib/widgets/ui_kit/utils/theme/ui_color.dart
Normal file
46
lib/widgets/ui_kit/utils/theme/ui_color.dart
Normal file
@@ -0,0 +1,46 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_health/config/theme/base/app_theme_ext.dart';
|
||||
|
||||
import '../enums/ui_theme.dart';
|
||||
import '../enums/ui_variant.dart';
|
||||
|
||||
class UiColorScheme {
|
||||
final Color background;
|
||||
final Color foreground;
|
||||
|
||||
UiColorScheme({
|
||||
required this.background,
|
||||
required this.foreground,
|
||||
});
|
||||
}
|
||||
|
||||
class UiColor {
|
||||
static UiColorScheme getColorScheme(
|
||||
BuildContext context, {
|
||||
UiThemeType type = UiThemeType.primary,
|
||||
UiVariant variant = UiVariant.solid,
|
||||
}) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final themeExt = Theme.of(context).extension<AppThemeExtension>()!;
|
||||
|
||||
//主题色映射
|
||||
final baseColor = switch (type) {
|
||||
UiThemeType.primary => colorScheme.primary,
|
||||
UiThemeType.success => themeExt.success,
|
||||
UiThemeType.warning => themeExt.warning,
|
||||
UiThemeType.danger => themeExt.danger,
|
||||
};
|
||||
|
||||
// 风格区分
|
||||
return switch (variant) {
|
||||
UiVariant.solid => UiColorScheme(
|
||||
background: baseColor,
|
||||
foreground: Colors.white,
|
||||
),
|
||||
UiVariant.plain => UiColorScheme(
|
||||
background: baseColor.withValues(alpha: 0.3),
|
||||
foreground: baseColor,
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user