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), ), ); } }