Skip to content

Commit

Permalink
Prepare example project
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmadre committed Dec 31, 2024
1 parent e4e5ee9 commit fe2b5d8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 30 deletions.
2 changes: 0 additions & 2 deletions bin/generate_packs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ const help = 'help';
const clear = 'clear';

Future<void> main(List<String> arguments) async {
exitCode = 0; // Presume success

final parser = ArgParser()
..addFlag(help, help: 'Shows how to use generate_packs command', abbr: 'h')
..addFlag(clear, help: 'Clears all generated packs', abbr: 'c')
Expand Down
14 changes: 4 additions & 10 deletions example/lib/app/icon_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:path_provider/path_provider.dart';
import 'app_brightness.dart';

class IconNotifier extends ChangeNotifier {
static final starterPacks = <IconPack>[IconPack.cupertino];
static final starterPacks = <IconPack>[IconPack.evaIcons];

IconNotifier._(
IconPickerIcon? iconData,
Expand All @@ -26,10 +26,7 @@ class IconNotifier extends ChangeNotifier {

IconPickerIcon? get icon => _icon;

void setIconData(
IconPickerIcon value, {
IconPack? pack,
}) {
void setIconData(IconPickerIcon value) {
if (_icon == value) {
return;
}
Expand Down Expand Up @@ -83,8 +80,7 @@ class IconNotifier extends ChangeNotifier {
try {
if (!kIsWeb) Hive.init((await getApplicationDocumentsDirectory()).path);
} catch (e) {
debugPrint(
'Hive has already been initialized. Skipping this step for now.');
debugPrint('Hive has already been initialized. Skipping this step for now.');
}

if (!Hive.isBoxOpen('FLIPBox')) {
Expand All @@ -97,9 +93,7 @@ class IconNotifier extends ChangeNotifier {
? deserializeIcon(Map<String, dynamic>.from(await box.get('iconData')))
: null;

final cachedIcons = await box.get('iconsData') != null
? deserializeIcons(await box.get('iconsData'))
: null;
final cachedIcons = await box.get('iconsData') != null ? deserializeIcons(await box.get('iconsData')) : null;

final brightness = AppBrightness.from(await box.get('app.brightness'));

Expand Down
26 changes: 8 additions & 18 deletions example/lib/home/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,19 @@ class _HomeScreenState extends State<HomeScreen> {
adaptiveDialog: isAdaptive,
showTooltips: showTooltips,
showSearchBar: showSearch,
iconPickerShape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)),
iconPickerShape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)),
iconPackModes: IconNotifier.starterPacks,
searchComparator: (String search, IconPickerIcon icon) =>
search
.toLowerCase()
.contains(icon.name.replaceAll('_', ' ').toLowerCase()) ||
search.toLowerCase().contains(icon.name.replaceAll('_', ' ').toLowerCase()) ||
icon.name.toLowerCase().contains(search.toLowerCase()),
),
);

if (icon != null) {
Provider.of<IconNotifier>(context, listen: false)
.setIconData(icon, pack: icon.pack);
Provider.of<IconNotifier>(context, listen: false).setIconData(icon);
setState(() {});

debugPrint(
'Picked Icon: $icon and saved it successfully in local hive db.');
debugPrint('Picked Icon: $icon and saved it successfully in local hive db.');
}
}

Expand Down Expand Up @@ -106,9 +101,7 @@ class _HomeScreenState extends State<HomeScreen> {
onPressed: _pickIcon,
child: AnimatedSize(
duration: const Duration(milliseconds: 300),
child: Text(notifier.icon != null
? 'Change Icon'
: 'Open IconPicker'),
child: Text(notifier.icon != null ? 'Change Icon' : 'Open IconPicker'),
),
),
AnimatedSwitcher(
Expand Down Expand Up @@ -154,24 +147,21 @@ class _HomeScreenState extends State<HomeScreen> {
children: [
Flexible(
child: SwitchListTile.adaptive(
title: const Text('Show search-bar',
style: TextStyle(color: Colors.white)),
title: const Text('Show search-bar', style: TextStyle(color: Colors.white)),
value: showSearch,
onChanged: (val) => setState(() => showSearch = val),
),
),
Flexible(
child: SwitchListTile.adaptive(
title: const Text('Show tooltips',
style: TextStyle(color: Colors.white)),
title: const Text('Show tooltips', style: TextStyle(color: Colors.white)),
value: showTooltips,
onChanged: (val) => setState(() => showTooltips = val),
),
),
Flexible(
child: SwitchListTile.adaptive(
title: const Text('Adaptive dialog',
style: TextStyle(color: Colors.white)),
title: const Text('Adaptive dialog', style: TextStyle(color: Colors.white)),
value: isAdaptive,
onChanged: (val) => setState(() => isAdaptive = val),
),
Expand Down

0 comments on commit fe2b5d8

Please sign in to comment.