初始化
This commit is contained in:
83
lib/widgets/base/button/index.dart
Normal file
83
lib/widgets/base/button/index.dart
Normal file
@@ -0,0 +1,83 @@
|
||||
import 'package:app/core/theme/theme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../config/config.dart';
|
||||
|
||||
class Button extends StatelessWidget {
|
||||
final double? width;
|
||||
final double? height;
|
||||
final Widget child;
|
||||
final ThemeType type;
|
||||
final BorderRadius radius;
|
||||
final VoidCallback? onPressed;
|
||||
final bool loading;
|
||||
final bool disabled;
|
||||
final Widget? icon;
|
||||
|
||||
const Button({
|
||||
super.key,
|
||||
this.icon,
|
||||
this.width,
|
||||
this.height,
|
||||
this.radius = const BorderRadius.all(Radius.circular(80)),
|
||||
required this.child,
|
||||
this.onPressed,
|
||||
this.type = ThemeType.primary,
|
||||
this.loading = false,
|
||||
this.disabled = false,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bgDecoration = switch (type) {
|
||||
ThemeType.primary => BoxDecoration(color: Theme.of(context).primaryColor),
|
||||
ThemeType.success => BoxDecoration(color: context.success),
|
||||
ThemeType.danger => BoxDecoration(color: context.danger),
|
||||
ThemeType.warning => BoxDecoration(color: context.warning),
|
||||
ThemeType.info => BoxDecoration(color: context.info),
|
||||
};
|
||||
|
||||
return Opacity(
|
||||
opacity: disabled || loading ? 0.5 : 1,
|
||||
child: Container(
|
||||
width: width,
|
||||
height: height,
|
||||
decoration: bgDecoration.copyWith(borderRadius: radius),
|
||||
child: Material(
|
||||
type: MaterialType.transparency, // 让波纹依附在上层容器
|
||||
child: InkWell(
|
||||
borderRadius: radius,
|
||||
onTap: disabled || loading ? null : onPressed,
|
||||
splashColor: Colors.white.withValues(alpha: 0.2),
|
||||
highlightColor: Colors.white.withValues(alpha: 0.2),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 7),
|
||||
child: DefaultTextStyle(
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
color: Colors.white
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
child: Row(
|
||||
spacing: 10,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
if (loading)
|
||||
const SizedBox(
|
||||
width: 15,
|
||||
height: 15,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation(Colors.white),
|
||||
),
|
||||
),
|
||||
child,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
21
lib/widgets/base/config/color.dart
Normal file
21
lib/widgets/base/config/color.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'config.dart';
|
||||
|
||||
class ColorResolver {
|
||||
final Color bg;
|
||||
final Color font;
|
||||
final Color border;
|
||||
|
||||
ColorResolver(this.bg, this.font, this.border);
|
||||
}
|
||||
|
||||
///返回颜色
|
||||
ColorResolver resolveEffectColors(Color color, Effect effect) => switch (effect) {
|
||||
Effect.dark => ColorResolver(color, Colors.white, color),
|
||||
Effect.light => () {
|
||||
final pale = color.withValues(alpha: 0.2);
|
||||
return ColorResolver(pale, color, pale);
|
||||
}(), // 注意这里多了 (),表示立即调用
|
||||
Effect.plain => ColorResolver(Colors.white, color, color),
|
||||
};
|
||||
15
lib/widgets/base/config/config.dart
Normal file
15
lib/widgets/base/config/config.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
///主题风格
|
||||
enum Effect {
|
||||
dark,
|
||||
light,
|
||||
plain,
|
||||
}
|
||||
|
||||
///主题类型
|
||||
enum ThemeType {
|
||||
primary,
|
||||
success,
|
||||
warning,
|
||||
danger,
|
||||
info,
|
||||
}
|
||||
53
lib/widgets/base/empty/index.dart
Normal file
53
lib/widgets/base/empty/index.dart
Normal file
@@ -0,0 +1,53 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
enum EmptyType {
|
||||
data,
|
||||
}
|
||||
|
||||
class Empty extends StatelessWidget {
|
||||
final EmptyType type;
|
||||
final String? text;
|
||||
final Widget? child;
|
||||
|
||||
const Empty({
|
||||
super.key,
|
||||
this.type = EmptyType.data,
|
||||
this.text,
|
||||
this.child,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var emptyImg = switch (type) {
|
||||
EmptyType.data => Image.asset('assets/image/empty_data.png'),
|
||||
};
|
||||
var emptyText = switch (type) {
|
||||
EmptyType.data => '暂无数据',
|
||||
};
|
||||
return Container(
|
||||
padding: EdgeInsets.all(0),
|
||||
child: Column(
|
||||
children: [
|
||||
FractionallySizedBox(
|
||||
widthFactor: 0.5,
|
||||
child: Container(
|
||||
margin: EdgeInsets.only(bottom: 15),
|
||||
child: emptyImg,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
text ?? emptyText,
|
||||
style: Theme.of(context).textTheme.labelLarge,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
child != null
|
||||
? Container(
|
||||
margin: EdgeInsets.only(top: 15),
|
||||
child: child,
|
||||
)
|
||||
: SizedBox(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
58
lib/widgets/base/tag/index.dart
Normal file
58
lib/widgets/base/tag/index.dart
Normal file
@@ -0,0 +1,58 @@
|
||||
import 'package:app/core/theme/base/app_theme_ext.dart';
|
||||
import 'package:app/widgets/base/config/color.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../config/config.dart';
|
||||
|
||||
class Tag extends StatelessWidget {
|
||||
final String text;
|
||||
final Color? color;
|
||||
final ThemeType type;
|
||||
final Effect effect;
|
||||
final EdgeInsets padding;
|
||||
|
||||
const Tag({
|
||||
super.key,
|
||||
required this.text,
|
||||
this.color,
|
||||
this.type = ThemeType.primary,
|
||||
this.effect = Effect.dark,
|
||||
this.padding = const EdgeInsets.symmetric(vertical: 3, horizontal: 6),
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
///颜色
|
||||
var baseColor = switch (type) {
|
||||
ThemeType.primary => Theme.of(context).primaryColor,
|
||||
ThemeType.success => context.success,
|
||||
ThemeType.warning => context.warning,
|
||||
ThemeType.danger => context.danger,
|
||||
ThemeType.info => Color(0xFF8F9298),
|
||||
};
|
||||
if (color != null) {
|
||||
baseColor = color!;
|
||||
}
|
||||
|
||||
ColorResolver colorResolver = resolveEffectColors(baseColor, effect);
|
||||
|
||||
return Container(
|
||||
padding: padding,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
color: colorResolver.bg,
|
||||
border: Border.all(
|
||||
color: colorResolver.border,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
color: colorResolver.font,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user