Aidra Connect 10.0.2+16
Aidra Connect Mobile Application
Loading...
Searching...
No Matches
theme_switcher_dialog.dart
Go to the documentation of this file.
1import 'package:connect/core/localization/app_localizations.dart';
2import 'package:flutter/cupertino.dart';
3import 'package:flutter/material.dart';
4import 'package:flutter_bloc/flutter_bloc.dart';
5import 'package:flutter_screenutil/flutter_screenutil.dart';
6import 'package:hugeicons/hugeicons.dart';
7
8import '../../logic/theme_cubit/theme_cubit.dart';
9
11 const ThemeSwitcherDialog({super.key});
12
13 @override
14 Widget build(BuildContext context) {
15 return BlocBuilder<ThemeModeBloc, ThemeModeState>(
16 builder: (context, state) {
17 return Column(
18 crossAxisAlignment: CrossAxisAlignment.start,
19 mainAxisSize: MainAxisSize.min,
20 children: [
21 Column(
22 children: [
24 label: AppLocalizations.of(context).translate('Light'),
25 icon: HugeIcons.strokeRoundedSun01,
26 isActive: state.themeMode == ThemeMode.light,
27 context: context,
28 isEnabled: true,
29 onPressed: () {
30 context
31 .read<ThemeModeBloc>()
32 .add(const ChangeThemeMode(ThemeMode.light));
33 },
34 ),
35 SizedBox(height: 8.sp),
37 label: AppLocalizations.of(context).translate('Dark'),
38 icon: HugeIcons.strokeRoundedMoon02,
39 isActive: state.themeMode == ThemeMode.dark,
40 context: context,
41 isEnabled: true,
42 onPressed: () {
43 context
44 .read<ThemeModeBloc>()
45 .add(const ChangeThemeMode(ThemeMode.dark));
46 },
47 ),
48 SizedBox(height: 8.sp),
50 label: AppLocalizations.of(context).translate('System'),
51 icon: HugeIcons.strokeRoundedSettings03,
52 isActive: state.themeMode == ThemeMode.system,
53 context: context,
54 isEnabled: true,
55 onPressed: () {
56 context
57 .read<ThemeModeBloc>()
58 .add(const ChangeThemeMode(ThemeMode.system));
59 },
60 ),
61 ],
62 ),
63 ],
64 );
65 },
66 );
67 }
68
70 required String label,
71 required IconData icon,
72 required bool isActive,
73 required BuildContext context,
74 required bool isEnabled,
75 required VoidCallback onPressed,
76 }) {
77 return Opacity(
78 opacity: isEnabled ? .9 : .2,
79 child: ElevatedButton(
80 onPressed: isEnabled ? onPressed : null,
81 style: ElevatedButton.styleFrom(
82 backgroundColor: Theme.of(context).colorScheme.surface,
83 overlayColor: Theme.of(context).primaryColor.withOpacity(0.11),
84 padding: EdgeInsets.all(15.sp),
85 shape: RoundedRectangleBorder(
86 borderRadius: BorderRadius.circular(8.sp),
87 ),
88 elevation: 0,
89 ),
90 child: Row(
91 mainAxisAlignment: MainAxisAlignment.spaceBetween,
92 children: [
93 Row(
94 children: [
95 Icon(
96 icon,
97 color: Theme.of(context).colorScheme.onSurface,
98 size: 20.sp,
99 ),
100 SizedBox(width: 15.sp),
101 Text(
102 label,
103 style: Theme.of(context).textTheme.bodyMedium?.copyWith(
104 color: Theme.of(context).colorScheme.onSurface,
105 ),
106 ),
107 ],
108 ),
109 CupertinoSwitch(
110 value: isActive,
111 onChanged: (value) => onPressed(),
112 activeColor: Theme.of(context).colorScheme.primary,
113 ),
114 ],
115 ),
116 ),
117 );
118 }
119}
120
121// Example of how to show the dialog
122void showThemeSwitcher(BuildContext context) {
123 showDialog(
124 context: context,
125 builder: (context) => Dialog(
126 shape: RoundedRectangleBorder(
127 borderRadius: BorderRadius.circular(12.sp),
128 ),
129 child: Padding(
130 padding: EdgeInsets.all(16.sp),
131 child: const ThemeSwitcherDialog(),
132 ),
133 ),
134 );
135}
String translate(String key)
static AppLocalizations of(BuildContext context)
final bool isActive
Widget _buildThemeModeEnablerButton({ required String label, required IconData icon, required bool isActive, required BuildContext context, required bool isEnabled, required VoidCallback onPressed, })
final IconData icon
final VoidCallback onPressed
override Widget build(BuildContext context)
const ThemeSwitcherDialog({super.key})
final String label
final Widget child
final EdgeInsets padding
final Color backgroundColor
final String label
final Color color
Definition failures.dart:1
final double value
class ThemeSwitcherDialog extends StatelessWidget showThemeSwitcher(BuildContext context)
const ThemeSwitcherDialog({super.key})