初始化
This commit is contained in:
65
lib/widgets/base/button/index.dart
Normal file
65
lib/widgets/base/button/index.dart
Normal file
@@ -0,0 +1,65 @@
|
||||
import 'package:app/config/theme/theme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../config/config.dart';
|
||||
|
||||
class Button extends StatelessWidget {
|
||||
final double? width;
|
||||
final String text;
|
||||
final ThemeType type;
|
||||
final BorderRadius radius;
|
||||
final VoidCallback onPressed;
|
||||
final bool loading;
|
||||
final bool disabled;
|
||||
|
||||
const Button({
|
||||
super.key,
|
||||
this.width,
|
||||
this.radius = const BorderRadius.all(Radius.circular(80)),
|
||||
required this.text,
|
||||
required 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 ? 0.5 : 1,
|
||||
child: Container(
|
||||
width: width,
|
||||
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: Center(
|
||||
child: Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
color: type != ThemeType.info ? Colors.white : Colors.black,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
27
lib/widgets/base/card/g_card.dart
Normal file
27
lib/widgets/base/card/g_card.dart
Normal file
@@ -0,0 +1,27 @@
|
||||
import 'package:app/config/theme/base/app_theme_ext.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class GCard extends StatelessWidget {
|
||||
final Widget child;
|
||||
|
||||
const GCard({super.key, required this.child});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(context.pagePadding),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surfaceContainerHigh,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Theme.of(context).colorScheme.shadow,
|
||||
blurRadius: 9,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: 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,
|
||||
}
|
||||
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/config/theme/base/app_theme_ext.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../config/color.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 => context.info,
|
||||
};
|
||||
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,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
70
lib/widgets/base/transition/slide_hide.dart
Normal file
70
lib/widgets/base/transition/slide_hide.dart
Normal file
@@ -0,0 +1,70 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
enum SlideDirection { up, down }
|
||||
|
||||
class SlideHide extends StatefulWidget {
|
||||
final Widget child;
|
||||
final bool hide; // 是否隐藏
|
||||
final SlideDirection direction;
|
||||
final Duration duration;
|
||||
|
||||
const SlideHide({
|
||||
super.key,
|
||||
required this.child,
|
||||
this.hide = false,
|
||||
this.direction = SlideDirection.up,
|
||||
this.duration = const Duration(milliseconds: 200),
|
||||
});
|
||||
|
||||
@override
|
||||
State<SlideHide> createState() => _SlideHideState();
|
||||
}
|
||||
|
||||
class _SlideHideState extends State<SlideHide> with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _controller;
|
||||
late final Animation<Offset> _animation;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = AnimationController(
|
||||
vsync: this,
|
||||
duration: widget.duration,
|
||||
);
|
||||
_animation = Tween<Offset>(
|
||||
begin: Offset.zero,
|
||||
end: widget.direction == SlideDirection.up ? const Offset(0, -1) : const Offset(0, 1),
|
||||
).animate(CurvedAnimation(parent: _controller, curve: Curves.easeInOut));
|
||||
|
||||
if (widget.hide) {
|
||||
_controller.value = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant SlideHide oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.hide != widget.hide) {
|
||||
if (widget.hide) {
|
||||
_controller.forward();
|
||||
} else {
|
||||
_controller.reverse();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SlideTransition(
|
||||
position: _animation,
|
||||
child: widget.child,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user