Skip to content

Commit

Permalink
refactor(lib-interfaces): refactor some widgets ds-12
Browse files Browse the repository at this point in the history
  • Loading branch information
KeidsID committed Jan 15, 2025
1 parent 7e65e98 commit 9c24233
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 184 deletions.
10 changes: 6 additions & 4 deletions lib/interfaces/libs/widgets.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
export "widgets/app_about_list_tile.dart";
export "widgets/common_network_image.dart";
export "widgets/custom_camera.dart";
export "widgets/email_text_field.dart";
export "widgets/image_from_x_file.dart";
export "widgets/list_tile/app_about_list_tile.dart";
export "widgets/list_tile/locale_list_tile.dart";
export "widgets/list_tile/theme_list_tile.dart";
export "widgets/media/common_network_image.dart";
export "widgets/media/custom_camera.dart";
export "widgets/media/image_from_x_file.dart";
export "widgets/password_text_field.dart";
export "widgets/sized_error_widget.dart";
export "widgets/story_card.dart";
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import "package:dicoding_story_fl/libs/constants.dart";
class AppAboutListTile extends StatelessWidget {
const AppAboutListTile({super.key});

VoidCallback _onTapLink(BuildContext context, {required Uri url}) {
VoidCallback _handleUrlVisit(BuildContext context, {required Uri url}) {
return () async {
if (!await launchUrl(url, mode: LaunchMode.externalApplication)) {
if (kIsWeb) return; // skip invalid error on web
Expand All @@ -21,8 +21,8 @@ class AppAboutListTile extends StatelessWidget {
context: context,
builder: (context) {
return AlertDialog(
title: const Text("Hyperlink Fail"),
content: Text("Cannot launch $url"),
title: const Text("Url Visit Error"),
content: Text("Cannot visit $url"),
actions: [
TextButton(
onPressed: () => Navigator.maybePop(context),
Expand All @@ -48,7 +48,8 @@ class AppAboutListTile extends StatelessWidget {
image: AssetImages.appIconL,
width: 80.0,
),
applicationVersion: "v${package.version}+${package.buildNumber}",
applicationVersion:
"v${package.version}${package.buildNumber.isNotEmpty ? "+${package.buildNumber}" : ""}",
applicationLegalese: "MIT License\n\n"
"Copyright (c) 2024 Kemal Idris [KeidsID]",
aboutBoxChildren: [
Expand All @@ -65,7 +66,7 @@ class AppAboutListTile extends StatelessWidget {
text: "App Icon",
style: linkTextStyle,
recognizer: TapGestureRecognizer()
..onTap = _onTapLink(
..onTap = _handleUrlVisit(
context,
url: Uri.parse(
"https://www.flaticon.com/free-icon/content_15911316",
Expand All @@ -77,7 +78,7 @@ class AppAboutListTile extends StatelessWidget {
text: "Adrly",
style: linkTextStyle,
recognizer: TapGestureRecognizer()
..onTap = _onTapLink(
..onTap = _handleUrlVisit(
context,
url: Uri.parse(
"https://www.flaticon.com/authors/adrly",
Expand All @@ -89,7 +90,7 @@ class AppAboutListTile extends StatelessWidget {
text: "flaticon.com",
style: linkTextStyle,
recognizer: TapGestureRecognizer()
..onTap = _onTapLink(
..onTap = _handleUrlVisit(
context,
url: Uri.parse("https://www.flaticon.com/"),
),
Expand All @@ -103,7 +104,7 @@ class AppAboutListTile extends StatelessWidget {
Wrap(
children: [
TextButton(
onPressed: _onTapLink(
onPressed: _handleUrlVisit(
context,
url: Uri.parse("https://github.com/KeidsID/dicoding_story_fl"),
),
Expand Down
47 changes: 47 additions & 0 deletions lib/interfaces/libs/widgets/list_tile/locale_list_tile.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import "package:flutter/material.dart";
import "package:provider/provider.dart";

import "package:dicoding_story_fl/interfaces/libs/l10n.dart";
import "package:dicoding_story_fl/interfaces/libs/providers.dart";

class LocaleListTile extends StatelessWidget {
const LocaleListTile({super.key});

@override
Widget build(BuildContext context) {
final appL10n = AppL10n.of(context)!;

return ListTile(
leading: const Icon(Icons.language_outlined),
title: Text(appL10n.language),
trailing: Builder(builder: (context) {
final localeProvider = context.watch<LocaleProvider>();

String localeString(String localeString) {
return switch (localeString) {
"en" => "English",
"id" => "Bahasa Indonesia",
_ => appL10n.flThemeMode(ThemeMode.system.name),
};
}

return DropdownButton<Locale?>(
value: localeProvider.value,
onChanged: (value) => localeProvider.value = value,
items: [
DropdownMenuItem(
value: null,
child: Text(localeString("system")),
),
...AppL10n.supportedLocales.map((e) {
return DropdownMenuItem(
value: e,
child: Text(localeString("$e")),
);
})
],
);
}),
);
}
}
47 changes: 47 additions & 0 deletions lib/interfaces/libs/widgets/list_tile/theme_list_tile.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import "package:flutter/material.dart";
import "package:provider/provider.dart";

import "package:dicoding_story_fl/interfaces/libs/l10n.dart";
import "package:dicoding_story_fl/interfaces/libs/providers.dart";

class ThemeListTile extends StatelessWidget {
const ThemeListTile({super.key});

@override
Widget build(BuildContext context) {
final appL10n = AppL10n.of(context)!;

return ListTile(
leading: const Icon(Icons.color_lens_outlined),
title: Text(appL10n.appTheme),
trailing: Builder(builder: (context) {
final themeModeProvider = context.watch<ThemeModeProvider>();

final icons = ThemeMode.values.map((e) {
return switch (e) {
ThemeMode.system => Icons.settings_outlined,
ThemeMode.light => Icons.light_mode_outlined,
ThemeMode.dark => Icons.dark_mode_outlined,
};
}).toList();

return DropdownButton<ThemeMode>(
value: themeModeProvider.value,
items: ThemeMode.values.map((e) {
return DropdownMenuItem<ThemeMode>(
value: e,
child: Row(
children: [
Icon(icons[e.index]),
const SizedBox(width: 8.0),
Text(appL10n.flThemeMode(e.name)),
],
),
);
}).toList(),
onChanged: (value) => themeModeProvider.value = value!,
);
}),
);
}
}
Loading

0 comments on commit 9c24233

Please sign in to comment.