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 520c614
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 57 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,
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:tools/tools.dart';
import 'package:workspace_screen/src/components/bottom_bar/stroke_cap_tool_option.dart';
import 'package:workspace_screen/src/components/bottom_bar/stroke_width_tool_option.dart';
import 'package:workspace_screen/workspace_screen.dart';

class ToolOptionsConfig {
static final ToolOptionsConfig _instance = ToolOptionsConfig._internal();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:tools/tools.dart';
import 'package:workspace_screen/src/components/bottom_bar/tool_button.dart';
import 'package:workspace_screen/src/components/bottom_bar/tools/tool_button.dart';
import 'package:workspace_screen/workspace_screen.dart';

class ToolsBottomSheet extends StatelessWidget {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions packages/features/workspace_screen/lib/workspace_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ library workspace_screen;

export 'src/components/bottom_bar/bottom_nav_bar.dart';
export 'src/components/bottom_bar/bottom_nav_bar_items.dart';
export 'src/components/bottom_bar/stroke_cap_tool_option.dart';
export 'src/components/bottom_bar/stroke_width_tool_option.dart';
export 'src/components/bottom_bar/tool_button.dart';
export 'src/components/bottom_bar/tool_option.dart';
export 'src/components/bottom_bar/tool_options.dart';
export 'src/components/bottom_bar/tool_options_config.dart';
export 'src/components/bottom_bar/tools_bottom_sheet.dart';
export 'src/components/bottom_bar/tool_options/stroke_cap_tool_option.dart';
export 'src/components/bottom_bar/tool_options/stroke_width_tool_option.dart';
export 'src/components/bottom_bar/tool_options/tool_option.dart';
export 'src/components/bottom_bar/tool_options/tool_options.dart';
export 'src/components/bottom_bar/tool_options/tool_options_config.dart';
export 'src/components/bottom_bar/tools/tool_button.dart';
export 'src/components/bottom_bar/tools/tools_bottom_sheet.dart';
export 'src/components/drawing_surface/canvas_painter.dart';
export 'src/components/drawing_surface/checkerboard_pattern.dart';
export 'src/components/drawing_surface/command_painter.dart';
Expand Down

0 comments on commit 520c614

Please sign in to comment.