feat(proj): init
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:please_pay_me/theme/theme.dart';
|
||||
import 'package:please_pay_me/ui/ui.dart';
|
||||
import 'package:please_pay_me_widgetbook/knobs/common_knobs.dart';
|
||||
import 'package:widgetbook/widgetbook.dart';
|
||||
|
||||
enum UiAsyncState { content, loading, empty, error }
|
||||
|
||||
UiAsyncState knobAsyncState(BuildContext context, {String label = 'State'}) {
|
||||
return context.knobs.object.dropdown(
|
||||
label: label,
|
||||
options: UiAsyncState.values,
|
||||
labelBuilder: (value) => value.name,
|
||||
initialOption: UiAsyncState.content,
|
||||
);
|
||||
}
|
||||
|
||||
/// Shared empty / error / loading wrappers for molecules & screens.
|
||||
Widget wrapAsyncState({
|
||||
required BuildContext context,
|
||||
required UiAsyncState state,
|
||||
required Widget Function() builder,
|
||||
String emptyLabel = 'Пока пусто',
|
||||
String errorLabel = 'Что-то пошло не так',
|
||||
}) {
|
||||
return switch (state) {
|
||||
UiAsyncState.loading => const Padding(
|
||||
padding: EdgeInsets.all(AppSpacing.s6),
|
||||
child: Center(child: AppSpinner()),
|
||||
),
|
||||
UiAsyncState.empty => Padding(
|
||||
padding: const EdgeInsets.all(AppSpacing.s6),
|
||||
child: Center(child: AppText.subhead(emptyLabel)),
|
||||
),
|
||||
UiAsyncState.error => Padding(
|
||||
padding: const EdgeInsets.all(AppSpacing.s6),
|
||||
child: Center(
|
||||
child: AppText.subhead(
|
||||
knobText(context, label: 'Error text', initialValue: errorLabel),
|
||||
color: AppColors.systemRed,
|
||||
),
|
||||
),
|
||||
),
|
||||
UiAsyncState.content => builder(),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user