Skip to content

Commit

Permalink
PAINTROID-639 Make tool options disappear when tapping the tool
Browse files Browse the repository at this point in the history
CR
  • Loading branch information
Lenkomotive committed Feb 7, 2024
1 parent ee9c23a commit 30a391a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,11 @@ class BottomNavBar extends ConsumerWidget {

const BottomNavBar({Key? key}) : super(key: key);

void _onNavigationItemSelected(
int index, BuildContext context, WidgetRef ref) {
BottomNavBarItem item = BottomNavBarItem.values[index];
switch (item) {
case BottomNavBarItem.TOOLS:
showToolBottomSheet(context);
break;
case BottomNavBarItem.CURRENT_TOOL:
handleToolOptionsVisibility(ref);
break;
default:
return;
}
}

void showToolBottomSheet(BuildContext context) {
showModalBottomSheet(
context: context,
builder: (BuildContext context) => const SizedBox(
height: 270,
child: ToolsBottomSheet(),
),
);
}

void handleToolOptionsVisibility(WidgetRef ref) {
ref.read(toolOptionsVisibilityStateProvider.notifier).toggleVisibility();
}

@override
Widget build(BuildContext context, WidgetRef ref) {
final localizations = AppLocalizations.of(context);
final currentToolData = getCurrentToolData(ref);

return NavigationBarTheme(
data: WidgetThemes.bottomNavBarThemeData,
child: NavigationBar(
Expand All @@ -53,22 +26,9 @@ class BottomNavBar extends ConsumerWidget {
label: localizations.tools,
icon: const BottomBarIcon(asset: 'assets/svg/ic_tools.svg'),
),
Consumer(
builder: (BuildContext context, WidgetRef ref, Widget? child) {
final ToolType currentToolType = ref.watch(
toolBoxStateProvider.select((value) => value.currentToolType),
);

final currentToolData = ToolData.allToolsData.firstWhere(
(toolData) => toolData.type == currentToolType,
orElse: () => ToolData.BRUSH,
);

return NavigationDestination(
label: currentToolData.name,
icon: BottomBarIcon(asset: currentToolData.svgAssetPath),
);
},
NavigationDestination(
label: currentToolData.name,
icon: BottomBarIcon(asset: currentToolData.svgAssetPath),
),
NavigationDestination(
label: localizations.color,
Expand All @@ -86,4 +46,44 @@ class BottomNavBar extends ConsumerWidget {
),
);
}

ToolData getCurrentToolData(WidgetRef ref) {
final ToolType currentToolType = ref.watch(
toolBoxStateProvider.select((value) => value.currentToolType),
);

final currentToolData = ToolData.allToolsData.firstWhere(
(toolData) => toolData.type == currentToolType,
orElse: () => ToolData.BRUSH,
);
return currentToolData;
}
}

void _onNavigationItemSelected(int index, BuildContext context, WidgetRef ref) {
BottomNavBarItem item = BottomNavBarItem.values[index];
switch (item) {
case BottomNavBarItem.TOOLS:
_showToolBottomSheet(context);
break;
case BottomNavBarItem.TOOL_OPTIONS:
_handleToolOptionsVisibility(ref);
break;
default:
return;
}
}

void _showToolBottomSheet(BuildContext context) {
showModalBottomSheet(
context: context,
builder: (BuildContext context) => const SizedBox(
height: 270,
child: ToolsBottomSheet(),
),
);
}

void _handleToolOptionsVisibility(WidgetRef ref) {
ref.read(toolOptionsVisibilityStateProvider.notifier).toggleVisibility();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
enum BottomNavBarItem {
TOOLS,
CURRENT_TOOL,
TOOL_OPTIONS,
COLOR,
LAYERS,
}

0 comments on commit 30a391a

Please sign in to comment.