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

View File

@@ -1,4 +1,4 @@
import 'package:flutter/material.dart';
/*import 'package:flutter/material.dart';
import 'theme_type.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 'theme_mode_state.dart';
class ThemeModeCubit extends Cubit<ThemeModeState> {
ThemeModeCubit() : super(const ThemeModeState(mode: ThemeMode.system)) {
loadThemeMode();
@@ -21,4 +20,4 @@ class ThemeModeCubit extends Cubit<ThemeModeState> {
await prefs.setInt('theme_mode', mode.index);
emit(ThemeModeState(mode: mode));
}
}
}

View File

@@ -8,4 +8,4 @@ class ThemeModeState extends Equatable {
@override
List<Object?> get props => [mode];
}
}

View File

@@ -1,4 +1,4 @@
import 'package:equatable/equatable.dart';
/*import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:kmobile/config/theme_type.dart';
import 'package:kmobile/config/themes.dart';
@@ -14,4 +14,28 @@ class ThemeState extends Equatable {
@override
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),
),
centerTitle: false,
),
),
body: SafeArea(
child: Form(
key: _formKey,

View File

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

View File

@@ -161,4 +161,4 @@ class CardTile extends StatelessWidget {
),
);
}
}
}

View File

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

View File

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

View File

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

View File

@@ -21,7 +21,7 @@ class _ChequeManagementScreen extends State<ChequeManagementScreen> {
const TextStyle(color: Colors.black, fontWeight: FontWeight.w500),
),
centerTitle: false,
),
),
body: ListView(
children: [
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 'package:kmobile/api/services/payment_service.dart';
import 'package:kmobile/data/models/transfer.dart';
enum TransactionMode { neft, rtgs, imps }
class FundTransferAmountScreen extends StatefulWidget {
@@ -38,7 +39,7 @@ class FundTransferAmountScreen extends StatefulWidget {
_FundTransferAmountScreenState();
}
class _FundTransferAmountScreenState extends State<FundTransferAmountScreen> {
class _FundTransferAmountScreenState extends State<FundTransferAmountScreen> {
final _amountController = TextEditingController();
final _formKey = GlobalKey<FormState>();
TransactionMode _selectedMode = TransactionMode.neft;
@@ -370,10 +371,8 @@ class _FundTransferAmountScreenState extends State<FundTransferAmountScreen> {
color: Theme.of(context).colorScheme.onSurface,
borderColor: Colors.transparent,
selectedBorderColor: Colors.transparent,
splashColor:
Theme.of(context).primaryColor,
highlightColor:
Theme.of(context).primaryColor,
splashColor: Theme.of(context).primaryColor,
highlightColor: Theme.of(context).primaryColor,
children: [
Padding(
padding: const EdgeInsets.symmetric(
@@ -434,4 +433,4 @@ class _FundTransferAmountScreenState extends State<FundTransferAmountScreen> {
),
);
}
}
}

View File

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

View File

@@ -30,4 +30,4 @@ Future<void> showThemeModeDialog(BuildContext context) async {
);
},
);
}
}

View File

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