init
This commit is contained in:
commit
ffc2051e20
80 files changed
+2915
No files matched your search
@@ -0,0 +1,184 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'data/repositories/task_repository.dart';
|
||||
import 'data/services/mock_task_service.dart';
|
||||
import 'ui/core/theme/app_theme.dart';
|
||||
import 'ui/core/theme/theme_controller.dart';
|
||||
import 'ui/core/widgets/responsive_scaffold.dart';
|
||||
import 'ui/features/dashboard/view_models/dashboard_view_model.dart';
|
||||
import 'ui/features/dashboard/views/dashboard_view.dart';
|
||||
import 'ui/features/settings/views/settings_view.dart';
|
||||
|
||||
class MobileApp extends StatefulWidget {
|
||||
const MobileApp({super.key});
|
||||
|
||||
@override
|
||||
State<MobileApp> createState() => _MobileAppState();
|
||||
}
|
||||
|
||||
class _MobileAppState extends State<MobileApp> {
|
||||
late final ThemeController _themeController;
|
||||
late final TaskRepository _taskRepository;
|
||||
late final DashboardViewModel _dashboardViewModel;
|
||||
int _currentTabIndex = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_themeController = ThemeController();
|
||||
_taskRepository = TaskRepository(service: MockTaskService());
|
||||
_dashboardViewModel = DashboardViewModel(repository: _taskRepository);
|
||||
_dashboardViewModel.loadTasks();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_dashboardViewModel.dispose();
|
||||
_themeController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _showAddTaskDialog(BuildContext context) {
|
||||
final titleController = TextEditingController();
|
||||
final descriptionController = TextEditingController();
|
||||
String selectedCategory = 'General';
|
||||
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (dialogContext) {
|
||||
return StatefulBuilder(
|
||||
builder: (context, setDialogState) {
|
||||
return AlertDialog(
|
||||
title: const Text('New Task'),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextField(
|
||||
controller: titleController,
|
||||
autofocus: true,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Title',
|
||||
hintText: 'Enter task title',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: descriptionController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Description',
|
||||
hintText: 'Optional details',
|
||||
),
|
||||
maxLines: 2,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<String>(
|
||||
initialValue: selectedCategory,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Category',
|
||||
),
|
||||
items: const [
|
||||
DropdownMenuItem(value: 'General', child: Text('General')),
|
||||
DropdownMenuItem(value: 'Design', child: Text('Design')),
|
||||
DropdownMenuItem(value: 'Theme', child: Text('Theme')),
|
||||
DropdownMenuItem(value: 'A11y', child: Text('A11y')),
|
||||
],
|
||||
onChanged: (val) {
|
||||
if (val != null) {
|
||||
setDialogState(() => selectedCategory = val);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(dialogContext).pop(),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
final title = titleController.text.trim();
|
||||
if (title.isNotEmpty) {
|
||||
_dashboardViewModel.addTask(
|
||||
title: title,
|
||||
description: descriptionController.text.trim(),
|
||||
category: selectedCategory,
|
||||
);
|
||||
Navigator.of(dialogContext).pop();
|
||||
}
|
||||
},
|
||||
child: const Text('Add Task'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListenableBuilder(
|
||||
listenable: _themeController,
|
||||
builder: (context, _) {
|
||||
return MaterialApp(
|
||||
title: 'Mobile App',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: AppTheme.lightTheme,
|
||||
darkTheme: AppTheme.darkTheme,
|
||||
themeMode: _themeController.themeMode,
|
||||
home: Builder(
|
||||
builder: (innerContext) {
|
||||
final isDarkMode = Theme.of(innerContext).brightness == Brightness.dark;
|
||||
|
||||
return ResponsiveScaffold(
|
||||
selectedIndex: _currentTabIndex,
|
||||
onDestinationSelected: (index) {
|
||||
setState(() => _currentTabIndex = index);
|
||||
},
|
||||
appBarTitle: Text(
|
||||
_currentTabIndex == 0 ? 'Dashboard' : 'Settings',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
isDarkMode ? Icons.light_mode : Icons.dark_mode,
|
||||
),
|
||||
tooltip: isDarkMode ? 'Switch to light mode' : 'Switch to dark mode',
|
||||
onPressed: _themeController.toggleTheme,
|
||||
),
|
||||
],
|
||||
floatingActionButton: _currentTabIndex == 0
|
||||
? FloatingActionButton.extended(
|
||||
onPressed: () => _showAddTaskDialog(innerContext),
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text('Add Task'),
|
||||
tooltip: 'Create a new task',
|
||||
)
|
||||
: null,
|
||||
destinations: const [
|
||||
NavigationDestinationItem(
|
||||
icon: Icon(Icons.dashboard_outlined),
|
||||
selectedIcon: Icon(Icons.dashboard),
|
||||
label: 'Dashboard',
|
||||
),
|
||||
NavigationDestinationItem(
|
||||
icon: Icon(Icons.settings_outlined),
|
||||
selectedIcon: Icon(Icons.settings),
|
||||
label: 'Settings',
|
||||
),
|
||||
],
|
||||
body: _currentTabIndex == 0
|
||||
? DashboardView(viewModel: _dashboardViewModel)
|
||||
: SettingsView(themeController: _themeController),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user