Skip to content

Commit

Permalink
Move hover part of Project Tile into the Project Tile class
Browse files Browse the repository at this point in the history
Why was it ever outside..???
  • Loading branch information
TechnicJelle committed Oct 28, 2024
1 parent d432ff8 commit 9f8efe8
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 124 deletions.
209 changes: 122 additions & 87 deletions lib/main_menu/projects/project_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import "dart:io";
import "package:flutter/material.dart";
import "package:flutter_riverpod/flutter_riverpod.dart";
import "package:path/path.dart" as p;
import "package:url_launcher/url_launcher.dart";
import "package:url_launcher/url_launcher_string.dart";

import "../../hover.dart";
import "../../main.dart";
import "../../prefs.dart";
import "../../utils.dart";
Expand Down Expand Up @@ -62,98 +64,131 @@ class _PathPickerButtonState extends ConsumerState<ProjectTile> {
@override
Widget build(BuildContext context) {
final _PickingState pickingState = ref.watch(_pickingStateProvider);
return switch (pickingState) {
//TODO: The states other than ListTile should get more polish
_PickingState.nothing => ListTile(
title: Text(p.basename(projectDirectory.path)),
subtitle: Text(projectDirectory.path),
onTap: openProject,
),
_PickingState.directoryNotFound =>
Text("Directory ${projectDirectory.path} not found!"),
_PickingState.scanning => Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text("Scanning folder for BlueMap CLI JAR..."),
const SizedBox(height: 8),
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 300),
child: const LinearProgressIndicator(),
),
],
),
_PickingState.downloading => Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text("Downloading BlueMap CLI JAR..."),
const SizedBox(height: 8),
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 300),
child: const LinearProgressIndicator(),
),
],
),
_PickingState.downloadFailed => Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 8),
const Text(
"Downloaded failed:",
style: TextStyle(color: Colors.red),
),
const SizedBox(height: 4),
Text(
errorText ?? "Unknown error",
style: const TextStyle(color: Colors.red),
),
const SizedBox(height: 8),
ElevatedButton(
onPressed: () =>
ref.read(_pickingStateProvider.notifier).set(_PickingState.nothing),
child: const Text("Try again"),
),
const SizedBox(height: 8),
],
),
_PickingState.hashing => Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text("Verifying BlueMap CLI JAR hash..."),
const SizedBox(height: 8),
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 300),
child: const LinearProgressIndicator(),
),
],
),
_PickingState.wrongHash => Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text(
"Downloaded failed! Invalid hash!",
style: TextStyle(color: Colors.red),
),
const SizedBox(height: 8),
ElevatedButton(
onPressed: () => launchUrlString(
"https://github.com/TechnicJelle/BlueMapGUI/issues/new",
return Hover(
alwaysChild: switch (pickingState) {
//TODO: The states other than ListTile should get more polish
_PickingState.nothing => ListTile(
title: Text(p.basename(projectDirectory.path)),
subtitle: Text(projectDirectory.path),
onTap: openProject,
),
_PickingState.directoryNotFound =>
Text("Directory ${projectDirectory.path} not found!"),
_PickingState.scanning => Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text("Scanning folder for BlueMap CLI JAR..."),
const SizedBox(height: 8),
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 300),
child: const LinearProgressIndicator(),
),
],
),
_PickingState.downloading => Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text("Downloading BlueMap CLI JAR..."),
const SizedBox(height: 8),
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 300),
child: const LinearProgressIndicator(),
),
],
),
_PickingState.downloadFailed => Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 8),
const Text(
"Downloaded failed:",
style: TextStyle(color: Colors.red),
),
const SizedBox(height: 4),
Text(
errorText ?? "Unknown error",
style: const TextStyle(color: Colors.red),
),
const SizedBox(height: 8),
ElevatedButton(
onPressed: () =>
ref.read(_pickingStateProvider.notifier).set(_PickingState.nothing),
child: const Text("Try again"),
),
const SizedBox(height: 8),
],
),
_PickingState.hashing => Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text("Verifying BlueMap CLI JAR hash..."),
const SizedBox(height: 8),
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 300),
child: const LinearProgressIndicator(),
),
],
),
_PickingState.wrongHash => Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text(
"Downloaded failed! Invalid hash!",
style: TextStyle(color: Colors.red),
),
child: const Text("Contact developer"),
const SizedBox(height: 8),
ElevatedButton(
onPressed: () => launchUrlString(
"https://github.com/TechnicJelle/BlueMapGUI/issues/new",
),
child: const Text("Contact developer"),
),
],
),
_PickingState.running => Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text("Running BlueMap CLI to generate default configs..."),
const SizedBox(height: 8),
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 300),
child: const LinearProgressIndicator(),
),
],
),
},
hoverChild: Positioned(
right: 16,
top: 12,
child: PopupMenuButton(
itemBuilder: (BuildContext context) => <PopupMenuEntry>[
PopupMenuItem(
child: const Row(
children: [
Icon(Icons.folder_open),
SizedBox(width: 8),
Text("Open in file manager"),
],
),
onTap: () => launchUrl(projectDirectory.uri),
// does nothing when dir doesn't exist ↑
),
],
),
_PickingState.running => Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text("Running BlueMap CLI to generate default configs..."),
const SizedBox(height: 8),
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 300),
child: const LinearProgressIndicator(),
PopupMenuItem(
child: const Row(
children: [
Icon(Icons.clear),
SizedBox(width: 8),
Text("Remove from projects"),
],
),
onTap: () => ref
.read(knownProjectsProvider.notifier)
.removeProject(projectDirectory),
),
],
),
};
),
);
}

Future<void> openProject() async {
Expand Down
39 changes: 2 additions & 37 deletions lib/main_menu/projects/projects_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import "dart:io";

import "package:flutter/material.dart";
import "package:flutter_riverpod/flutter_riverpod.dart";
import "package:url_launcher/url_launcher.dart";

import "../../hover.dart";
import "../../prefs.dart";
import "../../project_view/project_view.dart";
import "new_project_dialog.dart";
Expand Down Expand Up @@ -47,41 +45,8 @@ class ProjectsScreen extends ConsumerWidget {
ListView.builder(
itemCount: projects.length,
itemBuilder: (BuildContext context, int index) {
final Directory project = projects[index];
return Hover(
alwaysChild: ProjectTile(project),
hoverChild: Positioned(
right: 16,
top: 12,
child: PopupMenuButton(
itemBuilder: (BuildContext context) => <PopupMenuEntry>[
PopupMenuItem(
child: const Row(
children: [
Icon(Icons.folder_open),
SizedBox(width: 8),
Text("Open in file manager"),
],
),
onTap: () => launchUrl(project.uri),
// does nothing when dir doesn't exist ↑
),
PopupMenuItem(
child: const Row(
children: [
Icon(Icons.clear),
SizedBox(width: 8),
Text("Remove from projects"),
],
),
onTap: () {
ref.read(knownProjectsProvider.notifier).removeProject(project);
},
),
],
),
),
);
final projectDirectory = projects[index];
return ProjectTile(projectDirectory);
},
),
Positioned(
Expand Down

0 comments on commit 9f8efe8

Please sign in to comment.