Skip to content

Commit 6d71920

Browse files
committed
Code cleanup and reduced by 45 lines
1 parent 6013b09 commit 6d71920

1 file changed

Lines changed: 30 additions & 76 deletions

File tree

lib/pages/settings_page.dart

Lines changed: 30 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ class SettingsPage extends StatelessWidget {
1010
@override
1111
Widget build(BuildContext context) {
1212
final theme = Theme.of(context);
13-
1413
final themeFocusNode = FocusNode();
1514
final settingsController = Provider.of<SettingsController>(context);
1615
final currentMode = settingsController.selectedTheme;
1716
final currentLocalization = settingsController.selectedLocale?.languageCode ?? 'system';
18-
// Get translation
19-
final appLocalizations = AppLocalizations.of(context)!;
17+
final appLocalizations = AppLocalizations.of(context)!; // Get translation
2018

2119
return Scaffold(
2220
appBar: AppBar(
@@ -40,18 +38,9 @@ class SettingsPage extends StatelessWidget {
4038
FocusScope.of(context).requestFocus(FocusNode());
4139
},
4240
items: [
43-
DropdownMenuItem(
44-
value: ThemeMode.system,
45-
child: Text(appLocalizations.system) // System
46-
),
47-
DropdownMenuItem(
48-
value: ThemeMode.light,
49-
child: Text(appLocalizations.lightMode) // Light
50-
),
51-
DropdownMenuItem(
52-
value: ThemeMode.dark,
53-
child: Text(appLocalizations.darkMode) // Dark
54-
),
41+
DropdownMenuItem(value: ThemeMode.system, child: Text(appLocalizations.system)), // System
42+
DropdownMenuItem(value: ThemeMode.light, child: Text(appLocalizations.lightMode)), // Light
43+
DropdownMenuItem(value: ThemeMode.dark, child: Text(appLocalizations.darkMode)), // Dark
5544
],
5645
),
5746
),
@@ -77,18 +66,9 @@ class SettingsPage extends StatelessWidget {
7766
FocusScope.of(context).requestFocus(FocusNode());
7867
},
7968
items: [
80-
DropdownMenuItem(
81-
value: 'system',
82-
child: Text(appLocalizations.system), // System
83-
),
84-
DropdownMenuItem(
85-
value: 'en',
86-
child: Text(appLocalizations.localeEnglish), // English
87-
),
88-
DropdownMenuItem(
89-
value: 'de',
90-
child: Text(appLocalizations.localeGerman), // German
91-
),
69+
DropdownMenuItem(value: 'system', child: Text(appLocalizations.system)), // System
70+
DropdownMenuItem(value: 'en', child: Text(appLocalizations.localeEnglish)), // English
71+
DropdownMenuItem(value: 'de', child: Text(appLocalizations.localeGerman)), // German
9272
],
9373
),
9474
),
@@ -105,74 +85,38 @@ class SettingsPage extends StatelessWidget {
10585
children: [
10686
TextButton(
10787
child: Text(appLocalizations.aboutThisButton), // About this project
108-
onPressed: () async {
109-
final url = Uri.parse("https://github.com/naibaf-1/CodeJudge");
110-
111-
if (await canLaunchUrl(url)) {
112-
await launchUrl(url, mode: LaunchMode.externalApplication);
113-
} else {
114-
throw "Could not launch $url";
115-
}
88+
onPressed: () {
89+
openLink("https://github.com/naibaf-1/CodeJudge");
11690
},
11791
),
11892
TextButton(
11993
child: Text(appLocalizations.seeLicenseButton), // See the license
120-
onPressed: () async {
121-
final url = Uri.parse("https://github.com/naibaf-1/CodeJudge?tab=License-1-ov-file");
122-
123-
if (await canLaunchUrl(url)) {
124-
await launchUrl(url, mode: LaunchMode.externalApplication);
125-
} else {
126-
throw "Could not launch $url";
127-
}
94+
onPressed: () {
95+
openLink("https://github.com/naibaf-1/CodeJudge?tab=License-1-ov-file");
12896
},
12997
),
13098
TextButton(
13199
child: Text(appLocalizations.reportABugButton), // Report a bug
132-
onPressed: () async {
133-
final url = Uri.parse("https://github.com/naibaf-1/CodeJudge/issues/new?template=bug-report-for-codejudge.md");
134-
135-
if (await canLaunchUrl(url)) {
136-
await launchUrl(url, mode: LaunchMode.externalApplication);
137-
} else {
138-
throw "Could not launch $url";
139-
}
100+
onPressed: () {
101+
openLink("https://github.com/naibaf-1/CodeJudge/issues/new?template=bug-report-for-codejudge.md");
140102
},
141103
),
142104
TextButton(
143105
child: Text(appLocalizations.requestAFeatureButton), // Request a feature
144-
onPressed: () async {
145-
final url = Uri.parse("https://github.com/naibaf-1/CodeJudge/issues/new?template=feature-request-for-codejudge.md");
146-
147-
if (await canLaunchUrl(url)) {
148-
await launchUrl(url, mode: LaunchMode.externalApplication);
149-
} else {
150-
throw "Could not launch $url";
151-
}
106+
onPressed: () {
107+
openLink("https://github.com/naibaf-1/CodeJudge/issues/new?template=feature-request-for-codejudge.md");
152108
},
153109
),
154110
TextButton(
155111
child: Text(appLocalizations.seeReleasesButton), // See all releases
156-
onPressed: () async {
157-
final url = Uri.parse("https://github.com/naibaf-1/CodeJudge/releases");
158-
159-
if (await canLaunchUrl(url)) {
160-
await launchUrl(url, mode: LaunchMode.externalApplication);
161-
} else {
162-
throw "Could not launch $url";
163-
}
112+
onPressed: () {
113+
openLink("https://github.com/naibaf-1/CodeJudge/releases");
164114
},
165115
),
166116
TextButton(
167117
child: Text(appLocalizations.aboutMeButton), // About the developer
168-
onPressed: () async {
169-
final url = Uri.parse("https://github.com/naibaf-1");
170-
171-
if (await canLaunchUrl(url)) {
172-
await launchUrl(url, mode: LaunchMode.externalApplication);
173-
} else {
174-
throw "Could not launch $url";
175-
}
118+
onPressed: () {
119+
openLink("https://github.com/naibaf-1");
176120
},
177121
),
178122
],
@@ -182,4 +126,14 @@ class SettingsPage extends StatelessWidget {
182126
),
183127
);
184128
}
185-
}
129+
130+
// Open a link in the browser
131+
void openLink(String link) async {
132+
final url = Uri.parse(link);
133+
if (await canLaunchUrl(url)) {
134+
await launchUrl(url, mode: LaunchMode.externalApplication);
135+
} else {
136+
throw "Could not launch $url";
137+
}
138+
}
139+
}

0 commit comments

Comments
 (0)