import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(useMaterial3: true),
home: const MainScreen(),
routes: {
'/profile': (context) =>
const Scaffold(body: Center(child: Text("Profile Screen"))),
'/settings': (context) =>
const Scaffold(body: Center(child: Text("Settings Screen"))),
'/Help': (context) =>
const Scaffold(body: Center(child: Text("Help Screen"))),
},
);
}
}
class MainScreen extends StatefulWidget {
const MainScreen({super.key});
@override
State<MainScreen> createState() => _MainScreenState();
}
class _MainScreenState extends State<MainScreen> {
// 1. Added State variables from the image
DateTime _date = DateTime.now();
TimeOfDay _time = TimeOfDay.now();
// 2. Completed the Date Picker function
void _showDateDialog() async {
DateTime? select = await showDatePicker(
context: context,
initialDate: _date,
firstDate: DateTime(1900),
lastDate: DateTime(2100),
);
// Update the state if a date was picked
if (select != null) {
setState(() {
_date = select;
});
}
}
// 3. Added a Time Picker function for the "Alarm" tile
void _showTimeDialog() async {
TimeOfDay? select = await showTimePicker(
context: context,
initialTime: _time,
);
// Update the state if a time was picked
if (select != null) {
setState(() {
_time = select;
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("navigation demos"),
centerTitle: true,
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
),
drawer: Drawer(
child: Column(
children: [
const UserAccountsDrawerHeader(
accountName: Text("Name"),
accountEmail: Text("[email protected]"),
),
ListTile(
leading: const Icon(Icons.person),
title: const Text("profile"),
onTap: () {
Navigator.pushNamed(context, '/profile');
},
),
ListTile(
leading: const Icon(Icons.settings),
title: const Text("settings"),
onTap: () {
Navigator.pushNamed(context, '/settings');
},
),
ListTile(
leading: const Icon(Icons.help),
title: const Text("help"),
onTap: () {
Navigator.pushNamed(context, '/Help');
},
),
],
),
),
// 4. Replaced the body with a Column to hold the new ListTiles + existing HomeScreen
body: Column(
children: [
ListTile(
leading: const Icon(Icons.cake),
title: const Text("Birthday"),
trailing: Text("${_date.year}-${_date.month}-${_date.day}"),
onTap: _showDateDialog,
),
ListTile(
leading: const Icon(Icons.alarm),
title: const Text("Alarm"),
trailing: Text(_time.format(context)),
onTap: _showTimeDialog,
),
const Divider(),
// Kept your existing tab layout below the newly added settings
const Expanded(
child: HomeScreen(),
),
],
),
);
}
}
class HomeScreen extends StatelessWidget {
const HomeScreen({super.key});
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
child: Column(
children: [
const TabBar(
tabs: [
Tab(icon: Icon(Icons.chat), text: "chat"),
Tab(icon: Icon(Icons.group), text: "group"),
Tab(icon: Icon(Icons.notifications), text: "notification"),
],
),
const Expanded(
child: TabBarView(
children: [
Center(child: Text("Chat view Screen")),
Center(child: Text("friend view Screen")),
Center(child: Text("notification view Screen")),
],
),
),
],
),
);
}
}⚠️Content was pasted as plain text and auto-formatted as a code block. Use the Code Block button in the editor for proper formatting.