Skip to content

Commit 3808808

Browse files
committed
rewrite: Added Settings Dropdown component
1 parent 04b2b0c commit 3808808

8 files changed

Lines changed: 228 additions & 34 deletions

lib/presentation/screens/anime_details_screen.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ class _AnimeDetailsViewState extends State<_AnimeDetailsView> {
288288
child: UnyoDropdown(
289289
onPressed: (selectedExtensionName) => context.read<AnimeDetailsCubit>().selectAnimeExtension(selectedExtensionName),
290290
selectedValue: state.selectedExtension?.name,
291+
label: "Select Extension",
291292
children: [
292293
...state.installedExtensions.map(
293294
(extension) => extension.name,

lib/presentation/screens/manga_details_screen.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ class _MangaDetailsViewState extends State<_MangaDetailsView> {
272272
child: UnyoDropdown(
273273
onPressed: (selectedExtensionName) => context.read<MangaDetailsCubit>().selectMangaExtension(selectedExtensionName),
274274
selectedValue: state.selectedExtension?.name,
275+
label: "Select Extension",
275276
children: [
276277
...state.installedExtensions.map(
277278
(extension) => extension.name,

lib/presentation/screens/settings_screen.dart

Lines changed: 102 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
77
import 'package:unyo/application/cubits/settings_cubit.dart';
88
import 'package:unyo/application/states/settings_state.dart';
99
import 'package:unyo/core/di/locator.dart';
10+
import 'package:unyo/core/enums/episode_service.dart';
11+
import 'package:unyo/core/enums/service.dart';
1012
import 'package:unyo/core/services/effects/app_effect_handler.dart';
1113
import 'package:unyo/presentation/widgets/styled/unyo_settings_category.dart';
1214
import 'package:unyo/presentation/widgets/styled/unyo_settings_selection_dialog.dart';
15+
import 'package:unyo/presentation/widgets/styled/unyo_settings_selection_dropdown.dart';
16+
import 'package:unyo/presentation/widgets/styled/unyo_settings_selection_slider.dart';
17+
import 'package:unyo/presentation/widgets/styled/unyo_settings_selection_toggle.dart';
1318
import 'package:unyo/presentation/widgets/text/text_body_large.dart';
1419
import 'package:unyo/presentation/widgets/text/text_headline_medium.dart';
1520

@@ -34,7 +39,9 @@ class _SettingsListener extends StatelessWidget {
3439
sl<AppEffectHandler>().handleEffects(
3540
context,
3641
state.effects,
37-
context.read<SettingsCubit>().clearEffects,
42+
context
43+
.read<SettingsCubit>()
44+
.clearEffects,
3845
);
3946
}
4047
},
@@ -77,7 +84,9 @@ class _SettingsViewState extends State<_SettingsView> with TickerProviderStateMi
7784
TextHeadlineMedium(
7885
text: "Settings!",
7986
style: TextStyle(
80-
color: ColorScheme.of(context).tertiary,
87+
color: ColorScheme
88+
.of(context)
89+
.tertiary,
8190
fontWeight: FontWeight.bold,
8291
),
8392
),
@@ -106,7 +115,7 @@ class _SettingsViewState extends State<_SettingsView> with TickerProviderStateMi
106115
UnyoSettingsCategory(
107116
title: "Accounts",
108117
description: "Manage your connected accounts",
109-
icon: Icons.person_outline_rounded,
118+
icon: Icons.person_rounded,
110119
alignment: "top",
111120
childAlignment: "center",
112121
settingsOptions: [
@@ -152,17 +161,51 @@ class _SettingsViewState extends State<_SettingsView> with TickerProviderStateMi
152161
alignment: "",
153162
childAlignment: "",
154163
settingsOptions: [
164+
UnyoSettingsSelectionDropdown(
165+
title: "Media Metadata Service",
166+
description: "Select the Media Metadata service to use",
167+
icon: Icons.image_search_rounded,
168+
label: "Select a service",
169+
defaultValue: Service.anilist.name.substring(0, 1).toUpperCase() + Service.anilist.name.substring(1),
170+
children: Service.values.map((service) => service.name.substring(0, 1).toUpperCase() + service.name.substring(1)).toList(),
171+
onPressed: (value){ },
172+
),
173+
UnyoSettingsSelectionDropdown(
174+
title: "Episode Metadata Service",
175+
description: "Select the Episode Metadata service to use",
176+
icon: Icons.movie_filter_rounded,
177+
label: "Select a service",
178+
defaultValue: EpisodeService.anizip.name.substring(0, 1).toUpperCase() + Service.anilist.name.substring(1),
179+
children: EpisodeService.values.map((service) => service.name.substring(0, 1).toUpperCase() + service.name.substring(1)).toList(),
180+
onPressed: (value){ },
181+
),
182+
UnyoSettingsSelectionDropdown(
183+
title: "Language",
184+
description: "Select the application language",
185+
icon: Icons.language_rounded,
186+
label: "Select a language",
187+
defaultValue: "English",
188+
children: ["English"],
189+
onPressed: (value){ },
190+
),
155191
UnyoSettingsSelectionDialog(
156-
title: "Media Metadata Service",
157-
description: "Select the Media Metadata service to use",
158-
icon: Icons.image_search_rounded,
159-
openDialog: (){}
192+
title: "Default Title Language",
193+
description: "Select the default title language",
194+
icon: Icons.text_fields_rounded,
195+
openDialog: () {},
160196
),
161197
UnyoSettingsSelectionDialog(
162-
title: "Episode Metadata Service",
163-
description: "Select the Episode Metadata service to use",
164-
icon: Icons.movie_filter_rounded,
165-
openDialog: (){}
198+
title: "Default Episode Title Language",
199+
description: "Select the default episode title language",
200+
icon: Icons.text_fields_rounded,
201+
openDialog: () {},
202+
),
203+
UnyoSettingsSelectionToggle(
204+
title: "Discord RPC",
205+
description: "Enable or disable Discord Rich Presence",
206+
icon: Icons.discord_rounded,
207+
initiallySelected: true,
208+
onPressed: (value) {},
166209
),
167210
],
168211
),
@@ -180,7 +223,45 @@ class _SettingsViewState extends State<_SettingsView> with TickerProviderStateMi
180223
icon: Icons.play_arrow_rounded,
181224
alignment: "",
182225
childAlignment: "",
183-
settingsOptions: [],
226+
settingsOptions: [
227+
UnyoSettingsSelectionToggle(
228+
title: "Skip opening automatically (when available)",
229+
description: "Automatically skip the opening of episodes",
230+
icon: Icons.skip_next_rounded,
231+
initiallySelected: false,
232+
onPressed: (value) {},
233+
),
234+
UnyoSettingsSelectionToggle(
235+
title: "Skip ending automatically (when available)",
236+
description: "Automatically skip the ending of episodes",
237+
icon: Icons.skip_previous_rounded,
238+
initiallySelected: false,
239+
onPressed: (value) {},
240+
),
241+
UnyoSettingsSelectionSlider(
242+
title: "Default manual skip time",
243+
description: "Set the default time for manual skips",
244+
icon: Icons.fast_forward_rounded,
245+
initialValue: 85,
246+
minValue: 60,
247+
maxValue: 120,
248+
onChanged: (value) {},
249+
),
250+
UnyoSettingsSelectionToggle(
251+
title: "Enable auto-play next episode",
252+
description: "Automatically accept next episode pop-up when the current one ends",
253+
icon: Icons.navigate_next_rounded,
254+
initiallySelected: false,
255+
onPressed: (value) {},
256+
),
257+
UnyoSettingsSelectionToggle(
258+
title: "Enable OpenSubtitles.org integration (When available)",
259+
description: "Enable OpenSubtitles.org integration for automatic subtitle fetching",
260+
icon: Icons.subtitles_rounded,
261+
initiallySelected: false,
262+
onPressed: (value) {},
263+
),
264+
],
184265
),
185266
UnyoSettingsCategory(
186267
title: "Reader",
@@ -198,17 +279,17 @@ class _SettingsViewState extends State<_SettingsView> with TickerProviderStateMi
198279
childAlignment: "",
199280
settingsOptions: [
200281
UnyoSettingsSelectionDialog(
201-
title: "Aniyomi Extensions Repository",
202-
description: "Change the Aniyomi extensions repository URL",
203-
icon: Icons.link_rounded,
204-
openDialog: (){}
282+
title: "Aniyomi Extensions Repository",
283+
description: "Change the Aniyomi extensions repository URL",
284+
icon: Icons.link_rounded,
285+
openDialog: () {},
205286
),
206287
UnyoSettingsSelectionDialog(
207-
title: "Tachiyomi Extensions Repository",
208-
description: "Change the Tachiyomi extensions repository URL",
209-
icon: Icons.link_rounded,
210-
openDialog: (){}
211-
)
288+
title: "Tachiyomi Extensions Repository",
289+
description: "Change the Tachiyomi extensions repository URL",
290+
icon: Icons.link_rounded,
291+
openDialog: () {},
292+
),
212293
],
213294
),
214295
UnyoSettingsCategory(

lib/presentation/widgets/styled/unyo_dropdown.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import 'package:flutter/material.dart';
44
class UnyoDropdown extends StatefulWidget {
55
final void Function(String?)? onPressed;
66
final List<String> children;
7+
final String? label;
78
final String? selectedValue;
89

910
const UnyoDropdown({
1011
super.key,
1112
required this.children,
13+
required this.label,
1214
required this.onPressed,
1315
this.selectedValue
1416
});
@@ -66,7 +68,7 @@ class _UnyoDropdownState extends State<UnyoDropdown> {
6668
backgroundColor: WidgetStatePropertyAll(Colors.black.withOpacity(0.5)),
6769
maximumSize: WidgetStatePropertyAll(Size(constrains.maxWidth, 300)),
6870
),
69-
label: Text('Select Extension', style: TextStyle(color: Colors.white.withOpacity(0.8))),
71+
label: widget.label != null ? Text(widget.label!, style: TextStyle(color: Colors.white.withOpacity(0.8))) : null,
7072
inputDecorationTheme: InputDecorationTheme(
7173
focusedBorder: OutlineInputBorder(
7274
borderRadius: const BorderRadius.all(Radius.circular(16.0)),

lib/presentation/widgets/styled/unyo_settings_selection_dialog.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ class UnyoSettingsSelectionDialog extends StatelessWidget {
55
final String title;
66
final String description;
77
final IconData icon;
8+
final String? imageUrl;
89
final void Function() openDialog;
910

1011
const UnyoSettingsSelectionDialog({
1112
super.key,
1213
required this.title,
1314
required this.description,
14-
required this.icon,
15+
this.icon = Icons.question_mark_rounded,
16+
this.imageUrl,
1517
required this.openDialog,
1618
});
1719

@@ -38,7 +40,10 @@ class UnyoSettingsSelectionDialog extends StatelessWidget {
3840
borderRadius: BorderRadius.circular(10),
3941
color: ColorScheme.of(context).primary.withOpacity(0.2),
4042
),
41-
child: Icon(icon, color: ColorScheme.of(context).tertiary),
43+
child:
44+
imageUrl == null
45+
? Icon(icon, color: ColorScheme.of(context).tertiary)
46+
: Image.network(imageUrl!),
4247
),
4348
const SizedBox(width: 18.0),
4449
Column(
@@ -58,7 +63,7 @@ class UnyoSettingsSelectionDialog extends StatelessWidget {
5863
),
5964
],
6065
),
61-
const Icon(Icons.checklist_rounded)
66+
const Icon(Icons.checklist_rounded),
6267
],
6368
),
6469
),
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_screenutil/flutter_screenutil.dart';
3+
import 'package:unyo/presentation/widgets/styled/unyo_dropdown.dart';
4+
5+
class UnyoSettingsSelectionDropdown extends StatefulWidget {
6+
final String title;
7+
final String description;
8+
final IconData icon;
9+
final String? imageUrl;
10+
final String? label;
11+
final String defaultValue;
12+
final List<String> children;
13+
final void Function(String?) onPressed;
14+
15+
const UnyoSettingsSelectionDropdown({
16+
super.key,
17+
required this.title,
18+
required this.description,
19+
required this.icon,
20+
this.imageUrl,
21+
this.label,
22+
required this.defaultValue,
23+
required this.children,
24+
required this.onPressed,
25+
});
26+
27+
@override
28+
State<UnyoSettingsSelectionDropdown> createState() => _UnyoSettingsSelectionDropdownState();
29+
}
30+
31+
class _UnyoSettingsSelectionDropdownState extends State<UnyoSettingsSelectionDropdown> {
32+
@override
33+
Widget build(BuildContext context) {
34+
return Container(
35+
color: Colors.transparent,
36+
width: double.infinity,
37+
height: 75,
38+
child: Padding(
39+
padding: EdgeInsets.symmetric(horizontal: 20.0.w),
40+
child: Row(
41+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
42+
crossAxisAlignment: CrossAxisAlignment.center,
43+
children: [
44+
Row(
45+
children: [
46+
Container(
47+
width: 47,
48+
height: 47,
49+
decoration: BoxDecoration(
50+
borderRadius: BorderRadius.circular(10),
51+
color: ColorScheme.of(context).primary.withOpacity(0.2),
52+
),
53+
child:
54+
widget.imageUrl == null
55+
? Icon(widget.icon, color: ColorScheme.of(context).tertiary)
56+
: Image.network(widget.imageUrl!),
57+
),
58+
const SizedBox(width: 18.0),
59+
Column(
60+
mainAxisAlignment: MainAxisAlignment.center,
61+
crossAxisAlignment: CrossAxisAlignment.start,
62+
children: [
63+
Text(
64+
widget.title,
65+
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Colors.white),
66+
),
67+
Text(
68+
widget.description,
69+
style: TextStyle(color: Colors.grey.withOpacity(0.8), fontSize: 13),
70+
),
71+
],
72+
),
73+
],
74+
),
75+
SizedBox(
76+
width: 170.w,
77+
child: UnyoDropdown(
78+
children: widget.children,
79+
label: widget.label,
80+
selectedValue: widget.defaultValue,
81+
onPressed: (value) {
82+
widget.onPressed(value);
83+
},
84+
),
85+
),
86+
],
87+
),
88+
),
89+
);
90+
}
91+
}

lib/presentation/widgets/styled/unyo_settings_selection_slider.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class UnyoSettingsSelectionSlider extends StatefulWidget {
55
final String title;
66
final String description;
77
final IconData icon;
8+
final String? imageUrl;
89
final String labelSuffix;
910
final int initialValue;
1011
final int minValue;
@@ -16,7 +17,8 @@ class UnyoSettingsSelectionSlider extends StatefulWidget {
1617
super.key,
1718
required this.title,
1819
required this.description,
19-
required this.icon,
20+
this.icon = Icons.question_mark_rounded,
21+
this.imageUrl,
2022
this.labelSuffix = "",
2123
required this.initialValue,
2224
required this.minValue,
@@ -56,7 +58,10 @@ class _UnyoSettingsSelectionSliderState extends State<UnyoSettingsSelectionSlide
5658
borderRadius: BorderRadius.circular(10),
5759
color: ColorScheme.of(context).primary.withOpacity(0.2),
5860
),
59-
child: Icon(widget.icon, color: ColorScheme.of(context).tertiary),
61+
child:
62+
widget.imageUrl == null
63+
? Icon(widget.icon, color: ColorScheme.of(context).tertiary)
64+
: Image.network(widget.imageUrl!),
6065
),
6166
const SizedBox(width: 18.0),
6267
Column(

0 commit comments

Comments
 (0)