Theme Mode #2

This commit is contained in:
2025-09-03 15:51:44 +05:30
parent d9f78629d2
commit 52534f9210
16 changed files with 124 additions and 56 deletions

View File

@@ -107,35 +107,36 @@ class _KMobileState extends State<KMobile> {
// ); // );
// }, // },
// ), // ),
child: BlocBuilder<ThemeCubit, ThemeState>( child: BlocBuilder<ThemeCubit, ThemeState>(
builder: (context, themeState) { builder: (context, themeState) {
return BlocBuilder<ThemeModeCubit, ThemeModeState>( return BlocBuilder<ThemeModeCubit, ThemeModeState>(
builder: (context, modeState) { builder: (context, modeState) {
return MaterialApp( return MaterialApp(
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
locale: _locale ?? const Locale('en'), locale: _locale ?? const Locale('en'),
supportedLocales: const [ supportedLocales: const [
Locale('en'), Locale('en'),
Locale('hi'), Locale('hi'),
], ],
localizationsDelegates: const [ localizationsDelegates: const [
AppLocalizations.delegate, AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate, GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate, GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate, GlobalCupertinoLocalizations.delegate,
], ],
title: 'kMobile', title: 'kMobile',
theme: themeState.getThemeData(), theme: themeState.getLightThemeData(),
darkTheme: themeState.getThemeData(), // reuse same color in dark darkTheme: themeState.getDarkThemeData(),
themeMode: context.watch<ThemeModeCubit>().state.mode, // <<-- coming from ThemeModeCubit themeMode: context.watch<ThemeModeCubit>().state.mode,
onGenerateRoute: AppRoutes.generateRoute, onGenerateRoute: AppRoutes.generateRoute,
initialRoute: AppRoutes.splash, initialRoute: AppRoutes.splash,
home: showSplash ? const SplashScreen() : const AuthGate(), home: showSplash ? const SplashScreen() : const AuthGate(),
);
},
); );
}, },
); ),
},
),
); );
} }
} }
@@ -367,8 +368,7 @@ class _NavigationScaffoldState extends State<NavigationScaffold> {
bottomNavigationBar: BottomNavigationBar( bottomNavigationBar: BottomNavigationBar(
currentIndex: _selectedIndex, currentIndex: _selectedIndex,
type: BottomNavigationBarType.fixed, type: BottomNavigationBarType.fixed,
backgroundColor: Theme.of(context) backgroundColor: Theme.of(context).scaffoldBackgroundColor,
.scaffoldBackgroundColor,
selectedItemColor: Theme.of(context).primaryColor, selectedItemColor: Theme.of(context).primaryColor,
unselectedItemColor: Colors.black54, unselectedItemColor: Colors.black54,
onTap: (index) { onTap: (index) {

View File

@@ -1,4 +1,4 @@
import 'package:flutter/material.dart'; /*import 'package:flutter/material.dart';
import 'theme_type.dart'; import 'theme_type.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
@@ -36,4 +36,54 @@ class AppThemes {
), ),
); );
} }
}*/
import 'package:flutter/material.dart';import 'theme_type.dart';
import 'package:google_fonts/google_fonts.dart';
class AppThemes {
static ThemeData getLightTheme(ThemeType type) {
final Color seedColor = _getSeedColor(type);
final colorScheme = ColorScheme.fromSeed(
seedColor: seedColor,
brightness: Brightness.light,
);
return ThemeData.from(
colorScheme: colorScheme,
useMaterial3: true,
textTheme: GoogleFonts.rubikTextTheme(),
).copyWith(
scaffoldBackgroundColor: Colors.white,
bottomNavigationBarTheme: BottomNavigationBarThemeData(
backgroundColor: colorScheme.surface,
),
);
}
static ThemeData getDarkTheme(ThemeType type) {
final Color seedColor = _getSeedColor(type);
final colorScheme = ColorScheme.fromSeed(
seedColor: seedColor,
brightness: Brightness.dark, // Use dark brightness
);
return ThemeData.from(
colorScheme: colorScheme,
useMaterial3: true,
textTheme: GoogleFonts.rubikTextTheme(
ThemeData(brightness: Brightness.dark).textTheme,
),
);
}
static Color _getSeedColor(ThemeType type) {
switch (type) {
case ThemeType.green:
return Colors.green;
case ThemeType.orange:
return Colors.orange;
case ThemeType.blue:
return Colors.blue;
case ThemeType.violet:
default:
return Colors.deepPurple;
}
}
} }

View File

@@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'theme_mode_state.dart'; import 'theme_mode_state.dart';
class ThemeModeCubit extends Cubit<ThemeModeState> { class ThemeModeCubit extends Cubit<ThemeModeState> {
ThemeModeCubit() : super(const ThemeModeState(mode: ThemeMode.system)) { ThemeModeCubit() : super(const ThemeModeState(mode: ThemeMode.system)) {
loadThemeMode(); loadThemeMode();

View File

@@ -1,4 +1,4 @@
import 'package:equatable/equatable.dart'; /*import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:kmobile/config/theme_type.dart'; import 'package:kmobile/config/theme_type.dart';
import 'package:kmobile/config/themes.dart'; import 'package:kmobile/config/themes.dart';
@@ -14,4 +14,28 @@ class ThemeState extends Equatable {
@override @override
List<Object?> get props => [themeType]; List<Object?> get props => [themeType];
} }*/
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:kmobile/config/theme_type.dart';
import 'package:kmobile/config/themes.dart';
class ThemeState extends Equatable {
final ThemeType themeType;
const ThemeState({required this.themeType});
ThemeData getLightThemeData() {
return AppThemes.getLightTheme(themeType);
}
ThemeData getDarkThemeData() {
return AppThemes.getDarkTheme(themeType);
}
@override
List<Object?> get props => [themeType];
}

View File

@@ -224,7 +224,7 @@ class _AddBeneficiaryScreen extends State<AddBeneficiaryScreen> {
const TextStyle(color: Colors.black, fontWeight: FontWeight.w500), const TextStyle(color: Colors.black, fontWeight: FontWeight.w500),
), ),
centerTitle: false, centerTitle: false,
), ),
body: SafeArea( body: SafeArea(
child: Form( child: Form(
key: _formKey, key: _formKey,

View File

@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import '../../../l10n/app_localizations.dart'; import '../../../l10n/app_localizations.dart';
class BlockCardScreen extends StatefulWidget { class BlockCardScreen extends StatefulWidget {
const BlockCardScreen({super.key}); const BlockCardScreen({super.key});
@@ -61,7 +60,7 @@ class _BlockCardScreen extends State<BlockCardScreen> {
const TextStyle(color: Colors.black, fontWeight: FontWeight.w500), const TextStyle(color: Colors.black, fontWeight: FontWeight.w500),
), ),
centerTitle: false, centerTitle: false,
), ),
body: Padding( body: Padding(
padding: const EdgeInsets.all(10.0), padding: const EdgeInsets.all(10.0),
child: Form( child: Form(

View File

@@ -59,7 +59,7 @@ class _CardManagementScreen extends State<CardManagementScreen> {
}, },
), ),
const Divider(height: 1), const Divider(height: 1),
CardManagementTile( CardManagementTile(
icon: Symbols.payment_card, icon: Symbols.payment_card,
label: AppLocalizations.of(context).viewCardDeatils, label: AppLocalizations.of(context).viewCardDeatils,
onTap: () { onTap: () {
@@ -78,7 +78,6 @@ class _CardManagementScreen extends State<CardManagementScreen> {
} }
} }
class CardManagementTile extends StatelessWidget { class CardManagementTile extends StatelessWidget {
final IconData icon; final IconData icon;
final String label; final String label;

View File

@@ -50,7 +50,7 @@ class _CardPinChangeDetailsScreen extends State<CardPinChangeDetailsScreen> {
const TextStyle(color: Colors.black, fontWeight: FontWeight.w500), const TextStyle(color: Colors.black, fontWeight: FontWeight.w500),
), ),
centerTitle: false, centerTitle: false,
), ),
body: Padding( body: Padding(
padding: const EdgeInsets.all(10.0), padding: const EdgeInsets.all(10.0),
child: Form( child: Form(

View File

@@ -50,7 +50,7 @@ class _CardPinSetScreen extends State<CardPinSetScreen> {
const TextStyle(color: Colors.black, fontWeight: FontWeight.w500), const TextStyle(color: Colors.black, fontWeight: FontWeight.w500),
), ),
centerTitle: false, centerTitle: false,
), ),
body: Padding( body: Padding(
padding: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(16.0),
child: Form( child: Form(

View File

@@ -21,7 +21,7 @@ class _ChequeManagementScreen extends State<ChequeManagementScreen> {
const TextStyle(color: Colors.black, fontWeight: FontWeight.w500), const TextStyle(color: Colors.black, fontWeight: FontWeight.w500),
), ),
centerTitle: false, centerTitle: false,
), ),
body: ListView( body: ListView(
children: [ children: [
const SizedBox(height: 15), const SizedBox(height: 15),

View File

@@ -17,6 +17,7 @@ import 'package:kmobile/features/fund_transfer/screens/transaction_pin_screen.da
import '../../../l10n/app_localizations.dart'; import '../../../l10n/app_localizations.dart';
import 'package:kmobile/api/services/payment_service.dart'; import 'package:kmobile/api/services/payment_service.dart';
import 'package:kmobile/data/models/transfer.dart'; import 'package:kmobile/data/models/transfer.dart';
enum TransactionMode { neft, rtgs, imps } enum TransactionMode { neft, rtgs, imps }
class FundTransferAmountScreen extends StatefulWidget { class FundTransferAmountScreen extends StatefulWidget {
@@ -38,7 +39,7 @@ class FundTransferAmountScreen extends StatefulWidget {
_FundTransferAmountScreenState(); _FundTransferAmountScreenState();
} }
class _FundTransferAmountScreenState extends State<FundTransferAmountScreen> { class _FundTransferAmountScreenState extends State<FundTransferAmountScreen> {
final _amountController = TextEditingController(); final _amountController = TextEditingController();
final _formKey = GlobalKey<FormState>(); final _formKey = GlobalKey<FormState>();
TransactionMode _selectedMode = TransactionMode.neft; TransactionMode _selectedMode = TransactionMode.neft;
@@ -370,10 +371,8 @@ class _FundTransferAmountScreenState extends State<FundTransferAmountScreen> {
color: Theme.of(context).colorScheme.onSurface, color: Theme.of(context).colorScheme.onSurface,
borderColor: Colors.transparent, borderColor: Colors.transparent,
selectedBorderColor: Colors.transparent, selectedBorderColor: Colors.transparent,
splashColor: splashColor: Theme.of(context).primaryColor,
Theme.of(context).primaryColor, highlightColor: Theme.of(context).primaryColor,
highlightColor:
Theme.of(context).primaryColor,
children: [ children: [
Padding( Padding(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(

View File

@@ -29,8 +29,7 @@ class PreferenceScreen extends StatelessWidget {
onTap: () { onTap: () {
showDialog( showDialog(
context: context, context: context,
builder: (_) => builder: (_) => const LanguageDialog(),
const LanguageDialog(),
); );
}, },
), ),
@@ -51,8 +50,7 @@ class PreferenceScreen extends StatelessWidget {
context: context, context: context,
builder: (_) => const ColorThemeDialog(), builder: (_) => const ColorThemeDialog(),
); );
} }),
),
], ],
); );
}, },

View File

@@ -379,7 +379,7 @@ class _QuickPayOutsideBankScreen extends State<QuickPayOutsideBankScreen> {
const TextStyle(color: Colors.black, fontWeight: FontWeight.w500), const TextStyle(color: Colors.black, fontWeight: FontWeight.w500),
), ),
centerTitle: false, centerTitle: false,
), ),
body: Padding( body: Padding(
padding: const EdgeInsets.all(12), padding: const EdgeInsets.all(12),
child: Form( child: Form(