onyx-tasks/apps/flutter/lib/screens/setup_screen.dart

114 lines
4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:file_picker/file_picker.dart';
import '../providers/app_provider.dart';
class SetupScreen extends StatefulWidget {
const SetupScreen({super.key});
@override
State<SetupScreen> createState() => _SetupScreenState();
}
class _SetupScreenState extends State<SetupScreen> {
final _nameController = TextEditingController();
final _pathController = TextEditingController();
@override
void dispose() {
_nameController.dispose();
_pathController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final app = context.read<AppProvider>();
final theme = Theme.of(context);
return Scaffold(
body: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: Card(
child: Padding(
padding: const EdgeInsets.all(32),
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 360),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Bevy Tasks',
style: theme.textTheme.headlineSmall?.copyWith(fontWeight: FontWeight.bold),
),
const SizedBox(height: 4),
Text(
'Create or open a workspace to get started.',
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
),
const SizedBox(height: 24),
// Workspace name
Text('Workspace name', style: theme.textTheme.labelMedium),
const SizedBox(height: 4),
TextField(
controller: _nameController,
decoration: const InputDecoration(hintText: 'My Tasks'),
),
const SizedBox(height: 16),
// Folder path
Text('Folder', style: theme.textTheme.labelMedium),
const SizedBox(height: 4),
Row(
children: [
Expanded(
child: TextField(
controller: _pathController,
readOnly: true,
decoration: const InputDecoration(hintText: 'Select a folder…'),
),
),
const SizedBox(width: 8),
FilledButton(
onPressed: () async {
final result = await FilePicker.platform.getDirectoryPath();
if (result != null) {
_pathController.text = result;
}
},
child: const Text('Browse'),
),
],
),
const SizedBox(height: 24),
// Create button
SizedBox(
width: double.infinity,
child: FilledButton(
onPressed: () {
final name = _nameController.text.trim();
final path = _pathController.text.trim();
if (name.isNotEmpty && path.isNotEmpty) {
app.addWorkspace(name, path);
}
},
child: const Text('Create Workspace'),
),
),
],
),
),
),
),
),
),
);
}
}