From 4325f5eb8229661195f2b860c101ce7f0e47bfa2 Mon Sep 17 00:00:00 2001 From: TechnicJelle <22576047+TechnicJelle@users.noreply.github.com> Date: Sat, 21 Sep 2024 23:16:00 +0200 Subject: [PATCH] Split main menu into two screens (projects&settings) --- lib/main_menu/main_menu.dart | 70 ++++++++++++------- .../{ => settings}/java/java_picker.dart | 4 +- .../radio_list_tile_custom_java_picker.dart | 0 .../radio_list_tile_system_java_picker.dart | 2 +- .../util_for_checking_java_path_version.dart | 0 lib/main_menu/settings/projects_screen.dart | 35 ++++++++++ lib/main_menu/settings/settings_screen.dart | 16 +++++ 7 files changed, 96 insertions(+), 31 deletions(-) rename lib/main_menu/{ => settings}/java/java_picker.dart (91%) rename lib/main_menu/{ => settings}/java/radio_list_tile_custom_java_picker.dart (100%) rename lib/main_menu/{ => settings}/java/radio_list_tile_system_java_picker.dart (97%) rename lib/main_menu/{ => settings}/java/util_for_checking_java_path_version.dart (100%) create mode 100644 lib/main_menu/settings/projects_screen.dart create mode 100644 lib/main_menu/settings/settings_screen.dart diff --git a/lib/main_menu/main_menu.dart b/lib/main_menu/main_menu.dart index 217647c..1406a2f 100644 --- a/lib/main_menu/main_menu.dart +++ b/lib/main_menu/main_menu.dart @@ -1,37 +1,53 @@ import "package:flutter/material.dart"; import "package:flutter_riverpod/flutter_riverpod.dart"; -import "../prefs.dart"; -import "java/java_picker.dart"; -import "path_picker_button.dart"; +import "settings/projects_screen.dart"; +import "settings/settings_screen.dart"; -class MainMenu extends ConsumerWidget { +enum MainMenuState { + projects, + settings, +} + +class MainMenu extends ConsumerStatefulWidget { const MainMenu({super.key}); @override - Widget build(BuildContext context, WidgetRef ref) { - return Center( - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - const JavaPicker(), - if (ref.watch(javaPathProvider.select((path) => path != null))) ...[ - ConstrainedBox( - constraints: const BoxConstraints(maxWidth: 600), - child: const Divider(), - ), - const Text("Select an empty folder to store your BlueMap files in:"), - const SizedBox(height: 8), - const PathPickerButton(), - const SizedBox(height: 8), - const Text("The BlueMap CLI tool will be downloaded into that folder."), - const SizedBox(height: 4), - const Text("It will generate some default config files for you."), - const SizedBox(height: 4), - const Text("You will then need to configure your maps in the BlueMap GUI."), - ], - ], - ), + ConsumerState createState() => _MainMenuState(); +} + +class _MainMenuState extends ConsumerState { + MainMenuState state = MainMenuState.projects; + + @override + Widget build(BuildContext context) { + return Row( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Container( + constraints: const BoxConstraints(maxWidth: 200), + child: ListView( + children: [ + ListTile( + title: const Text("Projects"), + selected: state == MainMenuState.projects, + onTap: () => setState(() => state = MainMenuState.projects), + ), + ListTile( + title: const Text("Settings"), + selected: state == MainMenuState.settings, + onTap: () => setState(() => state = MainMenuState.settings), + ), + ], + ), + ), + Expanded( + child: switch (state) { + MainMenuState.projects => const ProjectsScreen(), + MainMenuState.settings => const SettingsScreen(), + }, + ), + ], ); } } diff --git a/lib/main_menu/java/java_picker.dart b/lib/main_menu/settings/java/java_picker.dart similarity index 91% rename from lib/main_menu/java/java_picker.dart rename to lib/main_menu/settings/java/java_picker.dart index 3d2a2f4..eca049c 100644 --- a/lib/main_menu/java/java_picker.dart +++ b/lib/main_menu/settings/java/java_picker.dart @@ -1,7 +1,7 @@ import "package:flutter/material.dart"; import "package:flutter_riverpod/flutter_riverpod.dart"; -import "../../prefs.dart"; +import "../../../prefs.dart"; import "radio_list_tile_custom_java_picker.dart"; import "radio_list_tile_system_java_picker.dart"; @@ -28,8 +28,6 @@ class JavaPicker extends ConsumerWidget { mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.center, children: [ - const Text("Select your Java executable:"), - const SizedBox(height: 4), RadioListTileSystemJavaPicker( groupValue: javaPickerMode, onSet: () { diff --git a/lib/main_menu/java/radio_list_tile_custom_java_picker.dart b/lib/main_menu/settings/java/radio_list_tile_custom_java_picker.dart similarity index 100% rename from lib/main_menu/java/radio_list_tile_custom_java_picker.dart rename to lib/main_menu/settings/java/radio_list_tile_custom_java_picker.dart diff --git a/lib/main_menu/java/radio_list_tile_system_java_picker.dart b/lib/main_menu/settings/java/radio_list_tile_system_java_picker.dart similarity index 97% rename from lib/main_menu/java/radio_list_tile_system_java_picker.dart rename to lib/main_menu/settings/java/radio_list_tile_system_java_picker.dart index d50187d..606431a 100644 --- a/lib/main_menu/java/radio_list_tile_system_java_picker.dart +++ b/lib/main_menu/settings/java/radio_list_tile_system_java_picker.dart @@ -1,7 +1,7 @@ import "package:flutter/material.dart"; import "package:flutter_riverpod/flutter_riverpod.dart"; -import "../../utils.dart"; +import "../../../utils.dart"; import "java_picker.dart"; import "util_for_checking_java_path_version.dart"; diff --git a/lib/main_menu/java/util_for_checking_java_path_version.dart b/lib/main_menu/settings/java/util_for_checking_java_path_version.dart similarity index 100% rename from lib/main_menu/java/util_for_checking_java_path_version.dart rename to lib/main_menu/settings/java/util_for_checking_java_path_version.dart diff --git a/lib/main_menu/settings/projects_screen.dart b/lib/main_menu/settings/projects_screen.dart new file mode 100644 index 0000000..31192bc --- /dev/null +++ b/lib/main_menu/settings/projects_screen.dart @@ -0,0 +1,35 @@ +import "package:flutter/material.dart"; +import "package:flutter_riverpod/flutter_riverpod.dart"; + +import "../../prefs.dart"; +import "../path_picker_button.dart"; + +class ProjectsScreen extends ConsumerWidget { + const ProjectsScreen({super.key}); + + @override + Widget build(BuildContext context, WidgetRef ref) { + if (ref.watch(javaPathProvider.select((path) => path == null))) { + return const Center( + child: Text("⬅ Please select your Java in the settings"), + ); + } + + return const Center( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Text("Select an empty folder to store your BlueMap files in:"), + SizedBox(height: 8), + PathPickerButton(), + SizedBox(height: 8), + Text("The BlueMap CLI tool will be downloaded into that folder."), + SizedBox(height: 4), + Text("It will generate some default config files for you."), + SizedBox(height: 4), + Text("You will then need to configure your maps in the BlueMap GUI."), + ], + ), + ); + } +} diff --git a/lib/main_menu/settings/settings_screen.dart b/lib/main_menu/settings/settings_screen.dart new file mode 100644 index 0000000..35cf507 --- /dev/null +++ b/lib/main_menu/settings/settings_screen.dart @@ -0,0 +1,16 @@ +import "package:flutter/material.dart"; + +import "java/java_picker.dart"; + +class SettingsScreen extends StatelessWidget { + const SettingsScreen({super.key}); + + @override + Widget build(BuildContext context) { + return ListView(children: const [ + Text("Java Executable"), //TODO: Add link to download Java + SizedBox(height: 4), + JavaPicker(), + ]); + } +}