-
Notifications
You must be signed in to change notification settings - Fork 4
/
utils.dart
39 lines (34 loc) · 1.19 KB
/
utils.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import 'package:flutter/material.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:zeta_flutter/zeta_flutter.dart';
String iconLabelBuilder(int? codePoint) {
return icons.entries.firstWhere((element) => element.value.codePoint == codePoint).key.split('_').join(' ');
}
List<IconData> iconOptions() => icons.values
.map((e) => IconData(e.codePoint, fontFamily: ZetaIcons.family, fontPackage: ZetaIcons.package))
.toList();
String enumLabelBuilder(Enum? value) => value?.name.split('.').last.capitalize() ?? '';
IconData? iconKnob(
BuildContext context, {
bool nullable = false,
String name = 'Icon',
final IconData? initial,
}) {
return nullable
? context.knobs.listOrNull(
label: name,
options: iconOptions(),
labelBuilder: (value) => iconLabelBuilder(value?.codePoint),
initialOption: initial,
)
: context.knobs.list(
label: name,
options: iconOptions(),
labelBuilder: (value) => iconLabelBuilder(value?.codePoint),
initialOption: initial,
);
}
bool disabledKnob(BuildContext context) => context.knobs.boolean(
label: 'Disabled',
initialValue: false,
);