Swipe_Button_on_quick_pay
This commit is contained in:
@@ -1,72 +1,73 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:kmobile/src/preferences/color_dialog.dart';
|
||||
import 'package:kmobile/src/preferences/language_dialog.dart';
|
||||
import 'package:kmobile/src/preferences/preferences_provider.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:kmobile/src/preferences/preferences_cubit.dart';
|
||||
import 'package:kmobile/src/preferences/preferences_state.dart';
|
||||
|
||||
class Preference extends StatelessWidget {
|
||||
const Preference({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<PreferencesCubit, PreferencesState>(
|
||||
builder: (context, state) {
|
||||
return Scaffold(
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
appBar: AppBar(
|
||||
title: Text(AppLocalizations.of(context)!.preferences),
|
||||
PreferencesProvider preferencesProvider =
|
||||
Provider.of<PreferencesProvider>(context);
|
||||
return Scaffold(
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
appBar: AppBar(
|
||||
title: Text(AppLocalizations.of(context)!.preferences),
|
||||
),
|
||||
body: ListView(
|
||||
children: [
|
||||
ListTile(
|
||||
title: Text(AppLocalizations.of(context)!.dark_theme),
|
||||
trailing: Switch(
|
||||
value: preferencesProvider.themeMode == ThemeMode.dark,
|
||||
onChanged: (value) {
|
||||
preferencesProvider.themeMode =
|
||||
value ? ThemeMode.dark : ThemeMode.light;
|
||||
}),
|
||||
),
|
||||
body: ListView(
|
||||
children: [
|
||||
ListTile(
|
||||
title: Text(AppLocalizations.of(context)!.dark_theme),
|
||||
trailing: Switch(
|
||||
value: state.themeMode == ThemeMode.dark,
|
||||
onChanged: (value) {
|
||||
context.read<PreferencesCubit>().setThemeMode(
|
||||
value ? ThemeMode.dark : ThemeMode.light,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const Divider(height: 0),
|
||||
ListTile(
|
||||
title: Text(AppLocalizations.of(context)!.color_theme),
|
||||
onTap: () => _changeCurrentTheme(context),
|
||||
),
|
||||
const Divider(height: 0),
|
||||
ListTile(
|
||||
title: Text(AppLocalizations.of(context)!.language),
|
||||
onTap: () => _changeCurrentLocale(context),
|
||||
),
|
||||
],
|
||||
const Divider(height: 0),
|
||||
ListTile(
|
||||
title: Text(AppLocalizations.of(context)!.color_theme),
|
||||
onTap: () => _changeCurrentTheme(context),
|
||||
),
|
||||
);
|
||||
},
|
||||
const Divider(height: 0),
|
||||
ListTile(
|
||||
title: Text(AppLocalizations.of(context)!.language),
|
||||
onTap: () => _changeCurrentLocale(context),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _changeCurrentTheme(BuildContext context) async {
|
||||
final selectedColorScheme = await showDialog<Map<ThemeMode, ColorScheme>>(
|
||||
Map<ThemeMode, ColorScheme> selectedColorScheme = await showDialog(
|
||||
context: context,
|
||||
builder: (context) => const ColorDialog(),
|
||||
builder: (BuildContext context) {
|
||||
return const ColorDialog();
|
||||
},
|
||||
);
|
||||
|
||||
if (context.mounted && selectedColorScheme != null) {
|
||||
context.read<PreferencesCubit>().setColorScheme(selectedColorScheme);
|
||||
if (context.mounted) {
|
||||
PreferencesProvider provider =
|
||||
Provider.of<PreferencesProvider>(context, listen: false);
|
||||
provider.colorScheme = selectedColorScheme;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _changeCurrentLocale(BuildContext context) async {
|
||||
final selectedLocale = await showDialog<Locale>(
|
||||
Locale selectedLocale = await showDialog(
|
||||
context: context,
|
||||
builder: (context) => const LanguageDialog(),
|
||||
builder: (BuildContext context) {
|
||||
return const LanguageDialog();
|
||||
},
|
||||
);
|
||||
|
||||
if (context.mounted && selectedLocale != null) {
|
||||
context.read<PreferencesCubit>().setLocale(selectedLocale);
|
||||
if (context.mounted) {
|
||||
PreferencesProvider provider =
|
||||
Provider.of<PreferencesProvider>(context, listen: false);
|
||||
provider.locale = selectedLocale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,25 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'preferences_state.dart';
|
||||
import 'package:kmobile/utils/theme/color/color_scheme.dart';
|
||||
|
||||
class PreferencesCubit extends Cubit<PreferencesState> {
|
||||
PreferencesCubit()
|
||||
: super(PreferencesState(
|
||||
themeMode: ThemeMode.light,
|
||||
colorScheme: KMobileColorScheme.everforest,
|
||||
locale: const Locale.fromSubtags(languageCode: 'en'),
|
||||
));
|
||||
|
||||
void setThemeMode(ThemeMode mode) {
|
||||
emit(state.copyWith(themeMode: mode));
|
||||
}
|
||||
|
||||
void setColorScheme(Map<ThemeMode, ColorScheme> colorScheme) {
|
||||
emit(state.copyWith(colorScheme: colorScheme));
|
||||
}
|
||||
|
||||
void setLocale(Locale locale) {
|
||||
emit(state.copyWith(locale: locale));
|
||||
}
|
||||
}
|
25
lib/src/preferences/preferences_provider.dart
Normal file
25
lib/src/preferences/preferences_provider.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:kmobile/utils/theme/color/color_scheme.dart';
|
||||
|
||||
class PreferencesProvider with ChangeNotifier {
|
||||
ThemeMode _themeMode = ThemeMode.light;
|
||||
ThemeMode get themeMode => _themeMode;
|
||||
set themeMode(ThemeMode currentMode) {
|
||||
_themeMode = currentMode;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Map<ThemeMode, ColorScheme> _colorScheme = KMobileColorScheme.everforest;
|
||||
Map<ThemeMode, ColorScheme> get colorScheme => _colorScheme;
|
||||
set colorScheme(Map<ThemeMode, ColorScheme> currentColorScheme) {
|
||||
_colorScheme = currentColorScheme;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Locale _locale = const Locale.fromSubtags(languageCode: 'en');
|
||||
Locale get locale => _locale;
|
||||
set locale(Locale currentLocale) {
|
||||
_locale = currentLocale;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class PreferencesState {
|
||||
final ThemeMode themeMode;
|
||||
final Map<ThemeMode, ColorScheme> colorScheme;
|
||||
final Locale locale;
|
||||
|
||||
PreferencesState({
|
||||
required this.themeMode,
|
||||
required this.colorScheme,
|
||||
required this.locale,
|
||||
});
|
||||
|
||||
PreferencesState copyWith({
|
||||
ThemeMode? themeMode,
|
||||
Map<ThemeMode, ColorScheme>? colorScheme,
|
||||
Locale? locale,
|
||||
}) {
|
||||
return PreferencesState(
|
||||
themeMode: themeMode ?? this.themeMode,
|
||||
colorScheme: colorScheme ?? this.colorScheme,
|
||||
locale: locale ?? this.locale,
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user