From 58ddc8abb47e94f8bedc6612619c2dc465940272 Mon Sep 17 00:00:00 2001 From: TechnicJelle <22576047+TechnicJelle@users.noreply.github.com> Date: Sun, 3 Nov 2024 02:55:15 +0100 Subject: [PATCH] Added path picker button for new projects So you don't have to type or copy the path manually --- .../projects/new_project_dialog.dart | 71 +++++++++++++------ 1 file changed, 50 insertions(+), 21 deletions(-) diff --git a/lib/main_menu/projects/new_project_dialog.dart b/lib/main_menu/projects/new_project_dialog.dart index 4721816..25a7237 100644 --- a/lib/main_menu/projects/new_project_dialog.dart +++ b/lib/main_menu/projects/new_project_dialog.dart @@ -1,5 +1,6 @@ import "dart:io"; +import "package:file_picker/file_picker.dart"; import "package:flutter/material.dart"; import "package:flutter_riverpod/flutter_riverpod.dart"; import "package:path/path.dart" as p; @@ -90,27 +91,55 @@ class NewProjectDialogState extends ConsumerState { }, ), const SizedBox(height: 16), - TextFormField( - controller: _locationController, - onChanged: (_) => setState(() { - specialError = null; - }), - decoration: const InputDecoration( - labelText: "Location:", - ), - textInputAction: TextInputAction.done, - textCapitalization: TextCapitalization.none, - autovalidateMode: AutovalidateMode.onUserInteraction, - validator: (value) { - if (value == null || value.isEmpty) { - return "Can't be empty"; - } - if (!Directory(value).existsSync()) { - return "Directory does not exist"; - } - return null; - }, - onFieldSubmitted: (_) => validateAndCreate(), + Row( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: TextFormField( + controller: _locationController, + onChanged: (_) => setState(() { + specialError = null; + }), + decoration: const InputDecoration( + labelText: "Location:", + ), + textInputAction: TextInputAction.done, + textCapitalization: TextCapitalization.none, + autovalidateMode: AutovalidateMode.onUserInteraction, + validator: (value) { + if (value == null || value.isEmpty) { + return "Can't be empty"; + } + if (!Directory(value).existsSync()) { + return "Directory does not exist"; + } + return null; + }, + onFieldSubmitted: (_) => validateAndCreate(), + ), + ), + Padding( + padding: const EdgeInsets.only(top: 24, left: 8), + child: ElevatedButton.icon( + onPressed: () async { + final String? picked = await FilePicker.platform.getDirectoryPath( + dialogTitle: "Pick project location", + ); + if (picked == null) return; + + setState(() { + _locationController?.text = picked; + }); + }, + icon: const Icon(Icons.folder_open), + label: const Text("Pick"), + style: ElevatedButton.styleFrom( + backgroundColor: Colors.blue[300], + ), + ), + ) + ], ), const SizedBox(height: 8), Text(