Files
flutter-template/lib/core/widgets/app_button.dart
T
SkyJourney 61017f1c39 chore: 初始化脚手架 — sunny_mochi 企业级 Flutter 模板
Core 基础设施:Flavor 三包体系、Drift+SQLCipher 加密数据库
7 拦截器 Dio 网络栈、CrashReporter 崩溃日志、Sealed Failure 错误体系
5 色板主题系统、Auth 认证骨架(Clean Architecture)、Dev Panel、Mock Adapter

通过验证:flutter analyze(0 errors)、flutter test(全绿)、staging APK 74.8MB
2026-05-14 12:51:05 +08:00

80 lines
1.8 KiB
Dart

import 'package:flutter/material.dart';
/// 带 loading 状态的通用 FilledButton。
class AppButton extends StatelessWidget {
const AppButton({
super.key,
required this.label,
required this.onPressed,
this.loading = false,
this.width = double.infinity,
this.height = 50.0,
});
final String label;
final VoidCallback? onPressed;
final bool loading;
final double width;
final double height;
@override
Widget build(BuildContext context) {
return SizedBox(
width: width,
height: height,
child: FilledButton(
onPressed: loading ? null : onPressed,
child: loading
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
color: Colors.white,
),
)
: Text(label),
),
);
}
}
/// 带 loading 状态的通用 OutlinedButton。
class AppOutlinedButton extends StatelessWidget {
const AppOutlinedButton({
super.key,
required this.label,
required this.onPressed,
this.loading = false,
this.width = double.infinity,
this.height = 50.0,
});
final String label;
final VoidCallback? onPressed;
final bool loading;
final double width;
final double height;
@override
Widget build(BuildContext context) {
return SizedBox(
width: width,
height: height,
child: OutlinedButton(
onPressed: loading ? null : onPressed,
child: loading
? SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
color: Theme.of(context).colorScheme.primary,
),
)
: Text(label),
),
);
}
}