Kenneth Bruen
2 years ago
10 changed files with 303 additions and 42 deletions
@ -0,0 +1,37 @@
|
||||
import 'package:flutter/widgets.dart'; |
||||
import 'package:hooks_riverpod/hooks_riverpod.dart'; |
||||
import 'package:info_tren/models.dart'; |
||||
import 'package:info_tren/pages/settings/settings_page_cupertino.dart'; |
||||
import 'package:info_tren/pages/settings/settings_page_fluent.dart'; |
||||
import 'package:info_tren/pages/settings/settings_page_material.dart'; |
||||
import 'package:info_tren/providers.dart'; |
||||
|
||||
class SettingsPage extends ConsumerWidget { |
||||
const SettingsPage({super.key,}); |
||||
|
||||
static const String routeName = '/settings'; |
||||
|
||||
@override |
||||
Widget build(BuildContext context, WidgetRef ref) { |
||||
final uiDesign = ref.watch(uiDesignProvider); |
||||
|
||||
switch (uiDesign) { |
||||
case UiDesign.MATERIAL: |
||||
return const SettingsPageMaterial(); |
||||
case UiDesign.CUPERTINO: |
||||
return const SettingsPageCupertino(); |
||||
case UiDesign.FLUENT: |
||||
return const SettingsPageFluent(); |
||||
default: |
||||
throw UnmatchedUiDesignException(uiDesign); |
||||
} |
||||
} |
||||
} |
||||
|
||||
abstract class SettingsPageShared extends StatelessWidget { |
||||
final String pageTitle = 'Setări'; |
||||
final String appearanceTitle = 'Aspect'; |
||||
|
||||
const SettingsPageShared({super.key}); |
||||
|
||||
} |
@ -0,0 +1,77 @@
|
||||
import 'package:flutter/cupertino.dart'; |
||||
import 'package:hooks_riverpod/hooks_riverpod.dart'; |
||||
import 'package:info_tren/components/cupertino_listtile.dart'; |
||||
import 'package:info_tren/models.dart'; |
||||
import 'package:info_tren/pages/settings/setings_page.dart'; |
||||
import 'package:info_tren/providers.dart'; |
||||
|
||||
class SettingsPageCupertino extends SettingsPageShared { |
||||
const SettingsPageCupertino({super.key,}); |
||||
|
||||
Future<T?> singleChoice<T>({required BuildContext context, required List<T> choices, required String Function(T) labelBuilder, String? title}) async { |
||||
return await showCupertinoModalPopup<T>( |
||||
context: context, |
||||
builder: (context) { |
||||
return CupertinoActionSheet( |
||||
title: title != null ? Text(title) : null, |
||||
actions: choices.map((c) => CupertinoActionSheetAction( |
||||
onPressed: () { |
||||
Navigator.of(context).pop(c); |
||||
}, |
||||
child: Text(labelBuilder(c)), |
||||
)).toList(), |
||||
cancelButton: CupertinoActionSheetAction( |
||||
child: const Text('Anulare'), |
||||
onPressed: () { |
||||
Navigator.of(context).pop(); |
||||
}, |
||||
), |
||||
); |
||||
}, |
||||
); |
||||
} |
||||
|
||||
@override |
||||
Widget build(BuildContext context) { |
||||
return CupertinoPageScaffold( |
||||
navigationBar: CupertinoNavigationBar( |
||||
previousPageTitle: 'Info Tren', |
||||
middle: Text(pageTitle), |
||||
), |
||||
child: Builder( |
||||
builder: (context) { |
||||
final mq = MediaQuery.of(context); |
||||
return SingleChildScrollView( |
||||
child: Column( |
||||
children: [ |
||||
SizedBox( |
||||
height: mq.padding.top, |
||||
), |
||||
Consumer( |
||||
builder: (context, ref, _) { |
||||
final currentUiDesign = ref.watch(uiDesignProvider); |
||||
return CupertinoListTile( |
||||
title: Text(appearanceTitle), |
||||
trailing: Text(currentUiDesign.userInterfaceName), |
||||
onTap: () async { |
||||
final choice = await singleChoice( |
||||
context: context, |
||||
choices: UiDesign.values, |
||||
labelBuilder: (UiDesign ud) => ud.userInterfaceName, |
||||
title: appearanceTitle, |
||||
); |
||||
if (choice != null) { |
||||
ref.read(uiDesignProvider.notifier).set(choice); |
||||
} |
||||
}, |
||||
); |
||||
}, |
||||
), |
||||
], |
||||
), |
||||
); |
||||
}, |
||||
), |
||||
); |
||||
} |
||||
} |
@ -0,0 +1,42 @@
|
||||
import 'package:fluent_ui/fluent_ui.dart'; |
||||
import 'package:hooks_riverpod/hooks_riverpod.dart'; |
||||
import 'package:info_tren/models.dart'; |
||||
import 'package:info_tren/pages/settings/setings_page.dart'; |
||||
import 'package:info_tren/providers.dart'; |
||||
|
||||
class SettingsPageFluent extends SettingsPageShared { |
||||
const SettingsPageFluent({super.key,}); |
||||
|
||||
@override |
||||
Widget build(BuildContext context) { |
||||
return NavigationView( |
||||
appBar: NavigationAppBar( |
||||
title: Text(pageTitle), |
||||
), |
||||
content: SingleChildScrollView( |
||||
child: Column( |
||||
children: [ |
||||
Consumer( |
||||
builder: (context, ref, _) { |
||||
final currentUiDesign = ref.watch(uiDesignProvider); |
||||
return ListTile( |
||||
title: Text(appearanceTitle), |
||||
trailing: ComboBox<UiDesign>( |
||||
items: UiDesign.values.map((d) => ComboBoxItem( |
||||
value: d, |
||||
child: Text(d.userInterfaceName), |
||||
)).toList(), |
||||
value: currentUiDesign, |
||||
onChanged: (newUiDesign) { |
||||
ref.read(uiDesignProvider.notifier).set(newUiDesign); |
||||
}, |
||||
), |
||||
); |
||||
}, |
||||
), |
||||
], |
||||
), |
||||
), |
||||
); |
||||
} |
||||
} |
@ -0,0 +1,43 @@
|
||||
import 'package:flutter/material.dart'; |
||||
import 'package:hooks_riverpod/hooks_riverpod.dart'; |
||||
import 'package:info_tren/models.dart'; |
||||
import 'package:info_tren/pages/settings/setings_page.dart'; |
||||
import 'package:info_tren/providers.dart'; |
||||
|
||||
class SettingsPageMaterial extends SettingsPageShared { |
||||
const SettingsPageMaterial({super.key,}); |
||||
|
||||
@override |
||||
Widget build(BuildContext context) { |
||||
return Scaffold( |
||||
appBar: AppBar( |
||||
title: Text(pageTitle), |
||||
centerTitle: true, |
||||
), |
||||
body: SingleChildScrollView( |
||||
child: Column( |
||||
children: [ |
||||
Consumer( |
||||
builder: (context, ref, _) { |
||||
final currentUiDesign = ref.watch(uiDesignProvider); |
||||
return ListTile( |
||||
title: Text(appearanceTitle), |
||||
trailing: DropdownButton<UiDesign>( |
||||
items: UiDesign.values.map((d) => DropdownMenuItem( |
||||
value: d, |
||||
child: Text(d.userInterfaceName), |
||||
)).toList(), |
||||
value: currentUiDesign, |
||||
onChanged: (newUiDesign) { |
||||
ref.read(uiDesignProvider.notifier).set(newUiDesign); |
||||
}, |
||||
), |
||||
); |
||||
}, |
||||
), |
||||
], |
||||
), |
||||
), |
||||
); |
||||
} |
||||
} |
Loading…
Reference in new issue