feat(proj): init
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:please_pay_me/theme/theme.dart';
|
||||
import 'package:widgetbook/widgetbook.dart';
|
||||
|
||||
String knobText(
|
||||
BuildContext context, {
|
||||
required String label,
|
||||
String initialValue = 'Label',
|
||||
}) {
|
||||
return context.knobs.string(label: label, initialValue: initialValue);
|
||||
}
|
||||
|
||||
bool knobBool(
|
||||
BuildContext context, {
|
||||
required String label,
|
||||
bool initialValue = false,
|
||||
}) {
|
||||
return context.knobs.boolean(label: label, initialValue: initialValue);
|
||||
}
|
||||
|
||||
double knobDouble(
|
||||
BuildContext context, {
|
||||
required String label,
|
||||
double initialValue = 0.5,
|
||||
double min = 0,
|
||||
double max = 1,
|
||||
}) {
|
||||
return context.knobs.double.slider(
|
||||
label: label,
|
||||
initialValue: initialValue,
|
||||
min: min,
|
||||
max: max,
|
||||
);
|
||||
}
|
||||
|
||||
int knobInt(
|
||||
BuildContext context, {
|
||||
required String label,
|
||||
int initialValue = 0,
|
||||
int min = 0,
|
||||
int max = 10,
|
||||
}) {
|
||||
return context.knobs.int.slider(
|
||||
label: label,
|
||||
initialValue: initialValue,
|
||||
min: min,
|
||||
max: max,
|
||||
);
|
||||
}
|
||||
|
||||
Color knobColor(
|
||||
BuildContext context, {
|
||||
required String label,
|
||||
Color? initialValue,
|
||||
}) {
|
||||
return context.knobs.color(
|
||||
label: label,
|
||||
initialValue: initialValue ?? AppColors.of(context, AppColors.accent),
|
||||
);
|
||||
}
|
||||
|
||||
/// Dropdown over iOS system tints used by badges and progress bars.
|
||||
Color knobTint(BuildContext context, {String label = 'Tint'}) {
|
||||
const options = <String, Color>{
|
||||
'accent': AppColors.accent,
|
||||
'red': AppColors.systemRed,
|
||||
'orange': AppColors.systemOrange,
|
||||
'green': AppColors.systemGreen,
|
||||
'gray': AppColors.systemGray,
|
||||
};
|
||||
|
||||
final key = context.knobs.object.dropdown(
|
||||
label: label,
|
||||
options: options.keys.toList(),
|
||||
initialOption: 'accent',
|
||||
);
|
||||
|
||||
return options[key]!;
|
||||
}
|
||||
|
||||
T knobEnum<T extends Enum>(
|
||||
BuildContext context, {
|
||||
required String label,
|
||||
required List<T> values,
|
||||
required T initial,
|
||||
}) {
|
||||
return context.knobs.object.dropdown(
|
||||
label: label,
|
||||
options: values,
|
||||
labelBuilder: (value) => value.name,
|
||||
initialOption: initial,
|
||||
);
|
||||
}
|
||||
@@ -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