Skip to content

Commit ea61a80

Browse files
author
AhsanSarwar45
committed
Add separator option for digital clock widget
1 parent 0c952d1 commit ea61a80

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

lib/common/utils/time_format.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'package:clock_app/clock/types/time.dart';
22
import 'package:flutter/material.dart';
33

44
String getTimeFormatString(BuildContext context, TimeFormat timeFormat,
5-
{bool showMeridiem = true}) {
5+
{bool showMeridiem = true, String separator = "default"}) {
66
if (timeFormat == TimeFormat.device) {
77
if (MediaQuery.of(context).alwaysUse24HourFormat) {
88
timeFormat = TimeFormat.h24;
@@ -11,7 +11,11 @@ String getTimeFormatString(BuildContext context, TimeFormat timeFormat,
1111
}
1212
}
1313

14+
if (separator == "default") {
15+
separator = ":";
16+
}
17+
1418
return timeFormat == TimeFormat.h12
15-
? "h:mm${showMeridiem ? " a" : ""}"
16-
: "HH:mm";
19+
? "h${separator}mm${showMeridiem ? " a" : ""}"
20+
: "HH${separator}mm";
1721
}

lib/l10n/app_en.arb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,9 @@
664664
"translateLink": "Translate",
665665
"@translateLink": {},
666666
"translateDescription": "Help translate the app",
667-
"@translateDescription": {}
667+
"@translateDescription": {},
668+
"separatorSetting": "Separator",
669+
"@separatorSetting": {}
668670

669671

670672
}

lib/settings/data/widget_settings_schema.dart

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ SettingGroup widgetSettingSchema = SettingGroup(
7979
"Size",
8080
(context) => AppLocalizations.of(context)!.sizeSetting,
8181
10,
82-
100,
82+
150,
8383
70,
8484
onChange: (context, value) async {
8585
setDigitalClockWidgetData(context);
@@ -107,6 +107,24 @@ SettingGroup widgetSettingSchema = SettingGroup(
107107
},
108108
// snapLength: 1,
109109
),
110+
SelectSetting(
111+
"Separator",
112+
(context) => AppLocalizations.of(context)!.separatorSetting,
113+
[
114+
SelectSettingOption(
115+
(context) => AppLocalizations.of(context)!.defaultLabel,
116+
"default"),
117+
SelectSettingOption((context) => ".", "."),
118+
SelectSettingOption((context) => ":", ":"),
119+
SelectSettingOption((context) => "/", "/"),
120+
SelectSettingOption((context) => "-", "-"),
121+
SelectSettingOption((context) => "Space", " "),
122+
],
123+
defaultValue: 0,
124+
onChange: (context, value) async {
125+
setDigitalClockWidgetData(context);
126+
},
127+
),
110128
],
111129
),
112130

@@ -126,7 +144,7 @@ SettingGroup widgetSettingSchema = SettingGroup(
126144
"Size",
127145
(context) => AppLocalizations.of(context)!.sizeSetting,
128146
10,
129-
100,
147+
150,
130148
15,
131149
onChange: (context, value) async {
132150
setDigitalClockWidgetData(context);

lib/widgets/logic/update_widgets.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ void setDigitalClockWidgetData(BuildContext context) async {
2525
'#${dateSettingGroup.getSetting('Color').value.value.toRadixString(16)}';
2626
final bool showMeridiem =
2727
timeSettingGroup.getSetting('Show Meridiem').value;
28+
final String separator =
29+
timeSettingGroup.getSetting('Separator').value.toString();
2830
final String timeFormat = getTimeFormatString(
2931
context,
3032
appSettings
@@ -33,6 +35,7 @@ void setDigitalClockWidgetData(BuildContext context) async {
3335
.getSetting('Time Format')
3436
.value,
3537
showMeridiem: showMeridiem,
38+
separator: separator,
3639
);
3740

3841
await HomeWidget.saveWidgetData("timeFormat", timeFormat);

0 commit comments

Comments
 (0)