feat: 新增 AppLoadingIndicator 和 AppPressable 组件
- 新增 AppLoadingIndicator 加载指示器组件 - 新增 AppPressable 按压反馈组件 - 新增 AppSheetInputField 输入框组件 - 更新 AppButton 和其他共享组件
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../core/theme/design_tokens.dart';
|
||||
|
||||
enum AppLoadingVariant { surface, inline, button }
|
||||
|
||||
class AppLoadingIndicator extends StatelessWidget {
|
||||
const AppLoadingIndicator({
|
||||
super.key,
|
||||
this.variant = AppLoadingVariant.surface,
|
||||
this.size,
|
||||
this.strokeWidth,
|
||||
this.color,
|
||||
this.trackColor,
|
||||
this.withContainer,
|
||||
});
|
||||
|
||||
final AppLoadingVariant variant;
|
||||
final double? size;
|
||||
final double? strokeWidth;
|
||||
final Color? color;
|
||||
final Color? trackColor;
|
||||
final bool? withContainer;
|
||||
|
||||
double get _resolvedSize {
|
||||
return size ??
|
||||
switch (variant) {
|
||||
AppLoadingVariant.surface => 22,
|
||||
AppLoadingVariant.inline => 16,
|
||||
AppLoadingVariant.button => 18,
|
||||
};
|
||||
}
|
||||
|
||||
double get _resolvedStrokeWidth {
|
||||
return strokeWidth ??
|
||||
switch (variant) {
|
||||
AppLoadingVariant.surface => 2.2,
|
||||
AppLoadingVariant.inline => 2,
|
||||
AppLoadingVariant.button => 2.2,
|
||||
};
|
||||
}
|
||||
|
||||
Color get _resolvedColor {
|
||||
return color ??
|
||||
switch (variant) {
|
||||
AppLoadingVariant.surface => AppColors.blue500,
|
||||
AppLoadingVariant.inline => AppColors.slate500,
|
||||
AppLoadingVariant.button => AppColors.white,
|
||||
};
|
||||
}
|
||||
|
||||
Color get _resolvedTrackColor {
|
||||
return trackColor ??
|
||||
switch (variant) {
|
||||
AppLoadingVariant.surface => AppColors.blue100,
|
||||
AppLoadingVariant.inline => AppColors.slate200,
|
||||
AppLoadingVariant.button => AppColors.blue300,
|
||||
};
|
||||
}
|
||||
|
||||
bool get _resolvedWithContainer {
|
||||
return withContainer ??
|
||||
switch (variant) {
|
||||
AppLoadingVariant.surface => true,
|
||||
AppLoadingVariant.inline => false,
|
||||
AppLoadingVariant.button => false,
|
||||
};
|
||||
}
|
||||
|
||||
Widget _buildSpinner() {
|
||||
return SizedBox(
|
||||
width: _resolvedSize,
|
||||
height: _resolvedSize,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: _resolvedStrokeWidth,
|
||||
color: _resolvedColor,
|
||||
backgroundColor: _resolvedTrackColor,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!_resolvedWithContainer) {
|
||||
return _buildSpinner();
|
||||
}
|
||||
|
||||
return Container(
|
||||
width: _resolvedSize + AppSpacing.md,
|
||||
height: _resolvedSize + AppSpacing.md,
|
||||
padding: const EdgeInsets.all(AppSpacing.xs),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
borderRadius: BorderRadius.circular(AppRadius.full),
|
||||
border: Border.all(color: AppColors.borderSecondary),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.slate200.withValues(alpha: 0.55),
|
||||
blurRadius: AppRadius.md,
|
||||
offset: const Offset(0, AppSpacing.xs),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: _buildSpinner(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user