0% found this document useful (0 votes)
3 views2 pages

RoutineApp FlutterCode

The document is a Flutter application for managing weekly routines, allowing users to add, edit, and copy routines across different days. It features a tabbed interface for each day of the week, a dialog for routine details, and a settings page for theme customization. The app uses a stateful widget to manage the routines and their display dynamically.

Uploaded by

tamimbillah7854
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

RoutineApp FlutterCode

The document is a Flutter application for managing weekly routines, allowing users to add, edit, and copy routines across different days. It features a tabbed interface for each day of the week, a dialog for routine details, and a settings page for theme customization. The app uses a stateful widget to manage the routines and their display dynamically.

Uploaded by

tamimbillah7854
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

import 'package:flutter/material.

dart';

void main() { runApp(RoutineApp()); }

class RoutineApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp(
title: 'Routine App', theme: ThemeData.light(), darkTheme: ThemeData.dark(), themeMode: ThemeMode.system, home:
HomeScreen(), ); } }

class HomeScreen extends StatefulWidget { @override _HomeScreenState createState() => _HomeScreenState(); }

class _HomeScreenState extends State with SingleTickerProviderStateMixin { late TabController _tabController;


final Map<String, List<Map<String, String>>> weeklyRoutines = { 'Saturday': [], 'Sunday': [], 'Monday': [],
'Tuesday': [], 'Wednesday': [], 'Thursday': [], 'Friday': [], };

@override void initState() { super.initState(); _tabController = TabController(length: 7, vsync: this); }

void *addRoutine(String day) async { final result = await showDialog<Map<String, String>>( context: context,
builder: (*) => RoutineDialog(), ); if (result != null) { setState(() => weeklyRoutines[day]!.add(result)); } }

void *editRoutine(String day, int index) async { final routine = weeklyRoutines[day]![index]; final result =
await showDialog<Map<String, String>>( context: context, builder: (*) => RoutineDialog( initialTitle:
routine['title']!, initialTime: routine['time']!, ), ); if (result != null) { setState(() =>
weeklyRoutines[day]![index] = result); } }

void *copyToOtherDays(String sourceDay) async { final selected = await showDialog<List>( context: context,
builder: (*) => CopyDialog(sourceDay: sourceDay), ); if (selected != null) { for (String day in selected) {
setState(() { weeklyRoutines[day] = List.from(weeklyRoutines[sourceDay]!); }); } } }

@override Widget build(BuildContext context) { final days = weeklyRoutines.keys.toList();


return DefaultTabController( length: 7, child: Scaffold( appBar: AppBar( title: Text('My Weekly Routine'),
bottom: TabBar( controller: _tabController, isScrollable: true, tabs: days.map((day) => Tab(text:
day)).toList(), ), actions: [ IconButton( icon: Icon(Icons.settings), onPressed: () => Navigator.push( context,
MaterialPageRoute(builder: (_) => SettingsPage()), ), ), ], ), body: TabBarView( controller: _tabController,
children: days.map((day) { final routines = weeklyRoutines[day]!; return GestureDetector( onLongPress: () =>
_copyToOtherDays(day), child: ListView.builder( itemCount: routines.length + 1, itemBuilder: (context, index) {
if (index == routines.length) { return ListTile( title: TextButton.icon( onPressed: () => _addRoutine(day),
icon: Icon(Icons.add), label: Text('Add More'), ), ); } return ListTile( title:
Text(routines[index]['title']!), subtitle: Text(routines[index]['time']!), trailing: IconButton( icon:
Icon(Icons.edit), onPressed: () => _editRoutine(day, index), ), ); }, ), ); }).toList(), ), ), ); } }

class RoutineDialog extends StatefulWidget { final String? initialTitle; final String? initialTime;

RoutineDialog({this.initialTitle, this.initialTime});

@override _RoutineDialogState createState() => _RoutineDialogState(); }

class _RoutineDialogState extends State { late TextEditingController _titleController; late


TextEditingController _timeController;

@override void initState() { super.initState(); _titleController = TextEditingController(text:


widget.initialTitle); _timeController = TextEditingController(text: widget.initialTime); }

@override Widget build(BuildContext context) { return AlertDialog( title: Text('Routine Details'), content:
Column( mainAxisSize: MainAxisSize.min, children: [ TextField( controller: _titleController, decoration:
InputDecoration(labelText: 'Activity Title'), ), TextField( controller: _timeController, decoration:
InputDecoration(labelText: 'Time (e.g., 10:00 AM - 11:00 AM)'), ), ], ), actions: [ TextButton(onPressed: () =>
Navigator.pop(context), child: Text('Cancel')), ElevatedButton( onPressed: () { Navigator.pop(context, {
'title': _titleController.text, 'time': _timeController.text, }); }, child: Text('Save'), ), ], ); } }

class CopyDialog extends StatefulWidget { final String sourceDay; CopyDialog({required this.sourceDay});

@override _CopyDialogState createState() => _CopyDialogState(); }

class _CopyDialogState extends State { final Map<String, bool> selectedDays = { 'Saturday': false, 'Sunday':
false, 'Monday': false, 'Tuesday': false, 'Wednesday': false, 'Thursday': false, 'Friday': false, };

@override void initState() { super.initState(); selectedDays.remove(widget.sourceDay); }

@override Widget build(BuildContext context) { return AlertDialog( title: Text('Copy to:'), content:
SingleChildScrollView( child: Column( children: selectedDays.keys.map((day) { return CheckboxListTile( title:
Text(day), value: selectedDays[day], onChanged: (val) { setState(() => selectedDays[day] = val!); }, );
}).toList(), ), ), actions: [ TextButton(onPressed: () => Navigator.pop(context), child: Text('Cancel')),
ElevatedButton( onPressed: () { Navigator.pop(context, selectedDays.entries.where((e) => e.value).map((e) =>
e.key).toList()); }, child: Text('Copy'), ), ], ); } }

class SettingsPage extends StatefulWidget { @override _SettingsPageState createState() => _SettingsPageState();


}

class _SettingsPageState extends State { ThemeMode _themeMode = ThemeMode.system;

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text('Settings')), body:
Column( children: [ ListTile( title: Text('Theme: Light'), leading: Radio( value: ThemeMode.light, groupValue:
_themeMode, onChanged: (value) => setState(() => _themeMode = value!), ), ), ListTile( title: Text('Theme:
Dark'), leading: Radio( value: ThemeMode.dark, groupValue: _themeMode, onChanged: (value) => setState(() =>
_themeMode = value!), ), ), ListTile( title: Text('Theme: System Default'), leading: Radio( value:
ThemeMode.system, groupValue: _themeMode, onChanged: (value) => setState(() => _themeMode = value!), ), ),
Divider(), ListTile( title: Text('Upgrade to Premium'), trailing: Icon(Icons.arrow_forward_ios), onTap: () {
ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text('Premium feature coming soon!')), ); }, ) ],
), ); } }

You might also like