aboutsummaryrefslogtreecommitdiffstats
path: root/lib/presentation/screens/settings/settings_screens/date_time
diff options
context:
space:
mode:
authorLisandro Pérez Meyer <lpmeyer@ics.com>2023-11-14 17:20:58 -0300
committerLisandro Pérez Meyer <lpmeyer@ics.com>2023-11-14 17:31:12 -0300
commit70ec8a79a121471a004e7e4c23157d10157e136f (patch)
treea4f9c0a4fac4e4274ec4324a289b6ef62e1c5653 /lib/presentation/screens/settings/settings_screens/date_time
Initial cleanup push.
Based on agldemo2024 on commit 2a5dc04d801134338150c3f6afc67eaa65599763 Disable device preview. Disable Lottie animation. The original commit was b3c493c340fcb4bb0a937692838fc830bec3e9ea but I am just keeping this change, because the json did not really needed to change. I think. Signed-off-by: Lisandro Pérez Meyer <lpmeyer@ics.com>
Diffstat (limited to 'lib/presentation/screens/settings/settings_screens/date_time')
-rw-r--r--lib/presentation/screens/settings/settings_screens/date_time/date/date_screen.dart218
-rw-r--r--lib/presentation/screens/settings/settings_screens/date_time/date_time_screen.dart54
-rw-r--r--lib/presentation/screens/settings/settings_screens/date_time/time/time_screen.dart426
3 files changed, 698 insertions, 0 deletions
diff --git a/lib/presentation/screens/settings/settings_screens/date_time/date/date_screen.dart b/lib/presentation/screens/settings/settings_screens/date_time/date/date_screen.dart
new file mode 100644
index 0000000..6802ed0
--- /dev/null
+++ b/lib/presentation/screens/settings/settings_screens/date_time/date/date_screen.dart
@@ -0,0 +1,218 @@
+import 'package:flutter_ics_homescreen/export.dart';
+import 'package:calendar_date_picker2/calendar_date_picker2.dart';
+import 'package:intl/intl.dart';
+
+class DatePage extends ConsumerWidget {
+ const DatePage({super.key});
+ static Page<void> page() => const MaterialPage<void>(child: DatePage());
+
+ @override
+ Widget build(BuildContext context, WidgetRef ref) {
+ return Scaffold(
+ body: Column(children: [
+ CommonTitle(
+ title: 'Date',
+ hasBackButton: true,
+ onPressed: () {
+ context.flow<AppState>().update((state) => AppState.dateTime);
+ },
+ ),
+ const Expanded(
+ child: Padding(
+ padding: EdgeInsets.symmetric(vertical: 20, horizontal: 144),
+ child: SingleChildScrollView(child: DateScreenWidget())),
+ ),
+ ]),
+ );
+ }
+}
+
+class DateScreenWidget extends ConsumerStatefulWidget {
+ const DateScreenWidget({super.key});
+ Page<void> page() => const MaterialPage<void>(child: DateScreenWidget());
+
+ @override
+ DateScreenWidgetState createState() => DateScreenWidgetState();
+}
+
+class DateScreenWidgetState extends ConsumerState<DateScreenWidget> {
+ late String selectedDate;
+
+ onPressed({required String type}) {
+ if (type == "confirm") {
+ ref.read(dateTimeStateProvider.notifier).setDate(selectedDate);
+ context.flow<AppState>().update((state) => AppState.dateTime);
+ } else if (type == "cancel") {
+ context.flow<AppState>().update((state) => AppState.dateTime);
+ }
+ }
+
+ @override
+ void initState() {
+ selectedDate = ref.read(dateTimeStateProvider).date;
+
+ super.initState();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ Size size = MediaQuery.sizeOf(context);
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ CalendarDatePicker2(
+ config: CalendarDatePicker2Config(
+ calendarType: CalendarDatePicker2Type.single,
+ dayBuilder: (
+ {required date,
+ decoration,
+ isDisabled,
+ isSelected,
+ isToday,
+ textStyle}) {
+ Widget? dayWidget;
+ dayWidget = Container(
+ decoration: decoration,
+ child: Center(
+ child: Stack(
+ alignment: AlignmentDirectional.center,
+ children: [
+ Text(
+ MaterialLocalizations.of(context)
+ .formatDecimal(date.day),
+ style: textStyle,
+ ),
+ ],
+ ),
+ ),
+ );
+
+ return dayWidget;
+ },
+ dayTextStyle: const TextStyle(
+ color: AGLDemoColors.periwinkleColor, fontSize: 40),
+ selectedDayHighlightColor: AGLDemoColors.neonBlueColor,
+ controlsTextStyle: const TextStyle(
+ color: AGLDemoColors.periwinkleColor, fontSize: 40),
+ weekdayLabelTextStyle: const TextStyle(
+ color: AGLDemoColors.periwinkleColor, fontSize: 40),
+ controlsHeight: 40,
+ dayTextStylePredicate: ({required date}) {
+ return const TextStyle(
+ color: AGLDemoColors.periwinkleColor, fontSize: 40);
+ },
+ selectedDayTextStyle:
+ const TextStyle(color: Colors.white, fontSize: 40)),
+ value: selectedDate == "mm/dd/yyyy"
+ ? []
+ : [DateFormat().add_yMMMMd().parse(selectedDate)],
+ onValueChanged: (dates) {
+ setState(() {
+ selectedDate = DateFormat().add_yMMMMd().format(dates.first!);
+ });
+ },
+ ),
+ const SizedBox(
+ height: 120,
+ ),
+ Row(
+ mainAxisAlignment: MainAxisAlignment.spaceEvenly,
+ children: [
+ Material(
+ color: Colors.transparent,
+ child: InkWell(
+ onHighlightChanged: (value) {
+ // setState(() {
+ // isCancelButtonHighlighted = value;
+ // });
+ },
+ onTap: () {
+ onPressed(type: "cancel");
+
+ // onTap(type: "cancel");
+ },
+ child: Container(
+ width: size.width / 3.2,
+ alignment: Alignment.center,
+ decoration: BoxDecoration(
+ boxShadow: [
+ BoxShadow(
+ color: Colors.black.withOpacity(0.7),
+ blurRadius: 1.5,
+ offset: const Offset(1, 2))
+ ],
+ gradient: LinearGradient(colors: [
+ AGLDemoColors.resolutionBlueColor,
+ AGLDemoColors.neonBlueColor.withOpacity(0.15),
+ ]),
+ borderRadius: BorderRadius.circular(3),
+ border: Border.all(
+ color:
+ AGLDemoColors.neonBlueColor.withOpacity(0.20))),
+ child: const Padding(
+ padding: EdgeInsets.symmetric(vertical: 20),
+ child: Text(
+ "Cancel",
+ style: TextStyle(
+ color: AGLDemoColors.periwinkleColor,
+ fontWeight: FontWeight.w600,
+ fontSize: 40,
+ letterSpacing: 0.4),
+ ),
+ ),
+ ),
+ ),
+ ),
+ const SizedBox(
+ width: 10,
+ ),
+ Material(
+ color: Colors.transparent,
+ child: InkWell(
+ onHighlightChanged: (value) {
+ // setState(() {
+ // isCancelButtonHighlighted = value;
+ // });
+ },
+ onTap: () {
+ onPressed(type: "confirm");
+ // onTap(type: "cancel");
+ },
+ child: Container(
+ width: MediaQuery.sizeOf(context).width / 3.2,
+ alignment: Alignment.center,
+ decoration: BoxDecoration(
+ boxShadow: [
+ BoxShadow(
+ color: Colors.black.withOpacity(0.7),
+ blurRadius: 1.5,
+ offset: const Offset(1, 2))
+ ],
+ gradient: LinearGradient(colors: [
+ AGLDemoColors.resolutionBlueColor,
+ AGLDemoColors.neonBlueColor.withOpacity(0.15),
+ ]),
+ borderRadius: BorderRadius.circular(3),
+ border: Border.all(
+ color:
+ AGLDemoColors.neonBlueColor.withOpacity(0.20))),
+ child: const Padding(
+ padding: EdgeInsets.symmetric(vertical: 20),
+ child: Text(
+ "Confirm",
+ style: TextStyle(
+ color: AGLDemoColors.periwinkleColor,
+ fontWeight: FontWeight.w600,
+ fontSize: 40,
+ letterSpacing: 0.4),
+ ),
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ],
+ );
+ }
+}
diff --git a/lib/presentation/screens/settings/settings_screens/date_time/date_time_screen.dart b/lib/presentation/screens/settings/settings_screens/date_time/date_time_screen.dart
new file mode 100644
index 0000000..2365ecc
--- /dev/null
+++ b/lib/presentation/screens/settings/settings_screens/date_time/date_time_screen.dart
@@ -0,0 +1,54 @@
+import 'package:flutter_ics_homescreen/export.dart';
+
+class DateTimePage extends ConsumerWidget {
+ const DateTimePage({super.key});
+
+ static Page<void> page() => const MaterialPage<void>(child: DateTimePage());
+ @override
+ Widget build(BuildContext context, WidgetRef ref) {
+ final dateTime = ref.watch(dateTimeStateProvider.select((val) => val));
+
+ return Scaffold(
+ body: Column(
+ children: [
+ CommonTitle(
+ title: 'Date & Time',
+ hasBackButton: true,
+ onPressed: () {
+ context.flow<AppState>().update((state) => AppState.settings);
+ },
+ ),
+ Expanded(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 144),
+ child: ListView(
+ children: [
+ UnitsTile(
+ image: "assets/Calendar.svg",
+ title: 'Date',
+ unitName: dateTime.date,
+ hasSwich: false,
+ voidCallback: () async {
+ context
+ .flow<AppState>()
+ .update((next) => AppState.date);
+ }),
+ UnitsTile(
+ image: "assets/Time.svg",
+ title: 'Time',
+ unitName: dateTime.time,
+ hasSwich: true,
+ voidCallback: () {
+ context
+ .flow<AppState>()
+ .update((next) => AppState.time);
+ }),
+ ],
+ ),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+}
diff --git a/lib/presentation/screens/settings/settings_screens/date_time/time/time_screen.dart b/lib/presentation/screens/settings/settings_screens/date_time/time/time_screen.dart
new file mode 100644
index 0000000..61131b5
--- /dev/null
+++ b/lib/presentation/screens/settings/settings_screens/date_time/time/time_screen.dart
@@ -0,0 +1,426 @@
+import 'package:flutter_ics_homescreen/export.dart';
+import 'package:flutter/services.dart';
+import 'package:intl/intl.dart';
+
+class TimePage extends ConsumerWidget {
+ const TimePage({super.key});
+ static Page<void> page() => const MaterialPage<void>(child: TimePage());
+
+ @override
+ Widget build(BuildContext context, WidgetRef ref) {
+ return Scaffold(
+ body: Column(children: [
+ CommonTitle(
+ title: 'Time',
+ hasBackButton: true,
+ onPressed: () {
+ context.flow<AppState>().update((state) => AppState.dateTime);
+ },
+ ),
+ const Expanded(
+ child: Padding(
+ padding: EdgeInsets.symmetric(vertical: 20, horizontal: 144),
+ child: SingleChildScrollView(child: TimeScreenWidget())),
+ ),
+ ]),
+ );
+ }
+}
+
+class TimeScreenWidget extends ConsumerStatefulWidget {
+ const TimeScreenWidget({super.key});
+ Page<void> page() => const MaterialPage<void>(child: TimeScreenWidget());
+
+ @override
+ TimeScreenWidgetState createState() => TimeScreenWidgetState();
+}
+
+class TimeScreenWidgetState extends ConsumerState<TimeScreenWidget> {
+ late int selectedTimeHour;
+ late int selectedTimeMinute;
+ String selectedMeridien = "AM";
+
+ TextEditingController hourController = TextEditingController();
+ TextEditingController minuteController = TextEditingController();
+
+ onPressed({required String type}) {
+ if (type == "confirm") {
+ ref.read(dateTimeStateProvider.notifier).setTime(
+ "${hourController.text}:${minuteController.text} $selectedMeridien");
+ context.flow<AppState>().update((state) => AppState.dateTime);
+ } else if (type == "cancel") {
+ context.flow<AppState>().update((state) => AppState.dateTime);
+ }
+ }
+
+ @override
+ void initState() {
+ String time = ref.read(dateTimeStateProvider).time;
+ if (time == "hh:mm a") {
+ time = DateFormat('hh:mm a').format(DateTime.now());
+ }
+ List<String> split = time.split(":");
+ selectedTimeHour = int.parse(split[0]);
+ List<String> splitMeridian = split[1].split(" ");
+
+ selectedTimeMinute = int.parse(splitMeridian[0]);
+
+ setState(() {
+ selectedMeridien = splitMeridian[1];
+ hourController.text = selectedTimeHour.toString();
+ minuteController.text = selectedTimeMinute.toString();
+ });
+
+ super.initState();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ Size size = MediaQuery.sizeOf(context);
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ const SizedBox(
+ height: 60,
+ ),
+ Row(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ TimeTextField(
+ controller: hourController,
+ type: "hour",
+ ),
+ const Padding(
+ padding: EdgeInsets.all(15),
+ child: Text(
+ ":",
+ style: TextStyle(
+ color: AGLDemoColors.periwinkleColor, fontSize: 44),
+ ),
+ ),
+ TimeTextField(
+ controller: minuteController,
+ type: "minute",
+ ),
+ ],
+ ),
+ const SizedBox(
+ height: 50,
+ ),
+ Row(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ Container(
+ decoration: BoxDecoration(
+ borderRadius: const BorderRadius.only(
+ topLeft: Radius.circular(30),
+ bottomLeft: Radius.circular(30),
+ ),
+ border: Border.all(color: AGLDemoColors.periwinkleColor),
+ color: selectedMeridien == "AM"
+ ? AGLDemoColors.neonBlueColor
+ : Colors.transparent),
+ child: Material(
+ color: Colors.transparent,
+ child: InkWell(
+ borderRadius: const BorderRadius.only(
+ topLeft: Radius.circular(30),
+ bottomLeft: Radius.circular(30),
+ ),
+ onTap: () {
+ setState(() {
+ selectedMeridien = "AM";
+ });
+ },
+ child: Padding(
+ padding: const EdgeInsets.only(
+ top: 17, bottom: 17, right: 30, left: 25),
+ child: Row(
+ children: [
+ selectedMeridien == "AM"
+ ? const Icon(
+ Icons.check,
+ size: 48,
+ color: Colors.white,
+ )
+ : const SizedBox(
+ width: 48,
+ height: 48,
+ ),
+ const SizedBox(
+ width: 3,
+ ),
+ Text(
+ "AM",
+ style: TextStyle(
+ color: selectedMeridien == "AM"
+ ? Colors.white
+ : AGLDemoColors.periwinkleColor,
+ fontSize: 40),
+ )
+ ],
+ ),
+ ),
+ ),
+ ),
+ ),
+ Container(
+ decoration: BoxDecoration(
+ borderRadius: const BorderRadius.only(
+ topRight: Radius.circular(30),
+ bottomRight: Radius.circular(30),
+ ),
+ border: Border.all(color: AGLDemoColors.periwinkleColor),
+ color: selectedMeridien == "PM"
+ ? AGLDemoColors.neonBlueColor
+ : Colors.transparent),
+ child: Material(
+ color: Colors.transparent,
+ child: InkWell(
+ borderRadius: const BorderRadius.only(
+ topRight: Radius.circular(30),
+ bottomRight: Radius.circular(30),
+ ),
+ onTap: () {
+ setState(() {
+ selectedMeridien = "PM";
+ });
+ },
+ child: Padding(
+ padding: const EdgeInsets.only(
+ top: 17, bottom: 17, right: 30, left: 25),
+ child: Row(
+ children: [
+ selectedMeridien == "PM"
+ ? const Icon(
+ Icons.check,
+ size: 48,
+ color: Colors.white,
+ )
+ : const SizedBox(
+ width: 48,
+ height: 48,
+ ),
+ const SizedBox(
+ width: 3,
+ ),
+ Text(
+ "PM",
+ style: TextStyle(
+ color: selectedMeridien == "PM"
+ ? Colors.white
+ : AGLDemoColors.periwinkleColor,
+ fontSize: 40),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ const SizedBox(
+ height: 200,
+ ),
+ Row(
+ mainAxisAlignment: MainAxisAlignment.spaceEvenly,
+ children: [
+ Material(
+ color: Colors.transparent,
+ child: InkWell(
+ onHighlightChanged: (value) {
+ // setState(() {
+ // isCancelButtonHighlighted = value;
+ // });
+ },
+ onTap: () {
+ onPressed(type: "cancel");
+
+ // onTap(type: "cancel");
+ },
+ child: Container(
+ width: size.width / 3.2,
+ alignment: Alignment.center,
+ decoration: BoxDecoration(
+ boxShadow: [
+ BoxShadow(
+ color: Colors.black.withOpacity(0.7),
+ blurRadius: 1.5,
+ offset: const Offset(1, 2))
+ ],
+ gradient: LinearGradient(colors: [
+ AGLDemoColors.resolutionBlueColor,
+ AGLDemoColors.neonBlueColor.withOpacity(0.15),
+ ]),
+ borderRadius: BorderRadius.circular(3),
+ border: Border.all(
+ color:
+ AGLDemoColors.neonBlueColor.withOpacity(0.20))),
+ child: const Padding(
+ padding: EdgeInsets.symmetric(vertical: 10),
+ child: Text(
+ "Cancel",
+ style: TextStyle(
+ color: AGLDemoColors.periwinkleColor,
+ fontWeight: FontWeight.w600,
+ fontSize: 40,
+ letterSpacing: 0.4),
+ ),
+ ),
+ ),
+ ),
+ ),
+ const SizedBox(
+ width: 10,
+ ),
+ Material(
+ color: Colors.transparent,
+ child: InkWell(
+ onHighlightChanged: (value) {
+ // setState(() {
+ // isCancelButtonHighlighted = value;
+ // });
+ },
+ onTap: () {
+ onPressed(type: "confirm");
+ // onTap(type: "cancel");
+ },
+ child: Container(
+ width: MediaQuery.sizeOf(context).width / 3.2,
+ alignment: Alignment.center,
+ decoration: BoxDecoration(
+ boxShadow: [
+ BoxShadow(
+ color: Colors.black.withOpacity(0.7),
+ blurRadius: 1.5,
+ offset: const Offset(1, 2))
+ ],
+ gradient: LinearGradient(colors: [
+ AGLDemoColors.resolutionBlueColor,
+ AGLDemoColors.neonBlueColor.withOpacity(0.15),
+ ]),
+ borderRadius: BorderRadius.circular(3),
+ border: Border.all(
+ color:
+ AGLDemoColors.neonBlueColor.withOpacity(0.20))),
+ child: const Padding(
+ padding: EdgeInsets.symmetric(vertical: 10),
+ child: Text(
+ "Confirm",
+ style: TextStyle(
+ color: AGLDemoColors.periwinkleColor,
+ fontWeight: FontWeight.w600,
+ fontSize: 40,
+ letterSpacing: 0.4),
+ ),
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ],
+ );
+ }
+}
+
+class TimeTextField extends StatefulWidget {
+ const TimeTextField(
+ {super.key, required this.controller, required this.type});
+ final TextEditingController controller;
+ final String type;
+
+ @override
+ State<TimeTextField> createState() => _TimeTextFieldState();
+}
+
+class _TimeTextFieldState extends State<TimeTextField> {
+ TextEditingController controller = TextEditingController();
+ @override
+ void initState() {
+ super.initState();
+ controller = widget.controller;
+ }
+
+ @override
+ void dispose() {
+ controller.dispose();
+ super.dispose();
+ }
+
+ onKeyBoardEvent(RawKeyEvent event) {
+ if (event.isKeyPressed(LogicalKeyboardKey.arrowUp)) {
+ if (controller.text != "") {
+ int value = int.tryParse(controller.text) ?? 0;
+ if (widget.type == "hour") {
+ if (value > 11) {
+ controller.text = "12";
+ } else {
+ controller.text = (value + 1).toString();
+ }
+ } else if (widget.type == "minute") {
+ if (value > 58) {
+ controller.text = "59";
+ } else {
+ controller.text = (value + 1).toString();
+ }
+ }
+ return KeyEventResult.handled;
+ } else {
+ controller.text = "0";
+ return KeyEventResult.handled;
+ }
+ } else if (event.isKeyPressed(LogicalKeyboardKey.arrowDown)) {
+ if (controller.text.isNotEmpty) {
+ int value = int.tryParse(controller.text) ?? 0;
+ if (value < 1) {
+ controller.text = "0";
+ } else {
+ controller.text = (value - 1).toString();
+ }
+ return KeyEventResult.handled;
+ } else {
+ controller.text = "0";
+ return KeyEventResult.handled;
+ }
+ }
+ return KeyEventResult.ignored;
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return SizedBox(
+ width: 185,
+ child: RawKeyboardListener(
+ focusNode: FocusNode(onKey: (node, event) {
+ return onKeyBoardEvent(event);
+ }),
+ child: TextField(
+ style: const TextStyle(color: Colors.white, fontSize: 40),
+ decoration: InputDecoration(
+ contentPadding: const EdgeInsets.symmetric(vertical: 23),
+ filled: true,
+ fillColor: AGLDemoColors.blueGlowFillColor.withOpacity(0.1)),
+ controller: controller,
+ textAlign: TextAlign.center,
+ inputFormatters: [
+ FilteringTextInputFormatter.digitsOnly,
+ ],
+ onChanged: (value) {
+ if (value.isNotEmpty) {
+ if (widget.type == "hour") {
+ if (int.parse(value) > 12) {
+ widget.controller.text = '12';
+ }
+ } else if (widget.type == "minute") {
+ if (int.parse(value) > 59) {
+ widget.controller.text = '59';
+ }
+ }
+ }
+ },
+ ),
+ ));
+ }
+}