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(
debugShowCheckedModeBanner:
false, // Matches the image's debug ribbon presence but not the main view.
title: 'Flutter Demo',
// We will set the color theme to something matching the lavender/light purple of the image.
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> {
DateTime _date = DateTime.now();
TimeOfDay _time = TimeOfDay.now();
void _showDateDialog() async {
DateTime? select = await showDatePicker(
context: context,
initialDate: _date,
firstDate: DateTime(2000),
lastDate: DateTime(2027),
helpText: "SELECT DATE",
cancelText: "CANCEL",
confirmText: "SELECT",
);
if (select != null && select != _date) {
setState(() {
_date = select;
});
}
}
void _showTime() async {
final TimeOfDay? select = await showTimePicker(
context: context,
initialTime: _time,
);
if (select != null && select != _time) {
setState(() {
_time = select;
});
}
}
void _showAlertDialog() {
showDialog(
context: context,
builder: (_) => AlertDialog(
title: Text("Logout Account "),
content: Text("Are you sure to logout fro this account ?"),
actions: [
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: Text("CANCEL"),
),
],
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Settings")),
body: Column(
children: [
ListTile(
leading: Icon(Icons.calendar_today),
title: Text("Birthday"),
trailing: Text(_date.toString().split('')[0]),
onTap: _showDateDialog,
),
ListTile(
leading: Icon(Icons.alarm),
title: Text("Alarm"),
trailing: Text(_time.format(context)),
onTap: _showTime,
),
ListTile(
leading: Icon(Icons.logout),
title: Text("Alert Dialog"),
onTap: _showAlertDialog,
),
],
),
);
}
}10 views