-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
822 additions
and
510 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,76 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_native_splash/flutter_native_splash.dart'; | ||
import 'package:provider/provider.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
import 'consts/consts.dart'; | ||
import 'consts/style.dart'; | ||
import 'provider/addpasswordprovider.dart'; | ||
import 'provider/generatedpassswordprovideer.dart'; | ||
import 'provider/onboardprovider.dart'; | ||
import 'provider/themeprovider.dart'; | ||
import 'screens/auth/login.dart'; | ||
import 'screens/onboardingpage.dart'; | ||
import 'services/databaseservice.dart'; | ||
|
||
int? isviewed; | ||
void main() { | ||
WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized(); | ||
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding); | ||
runApp(const MyApp()); | ||
} | ||
|
||
class MyApp extends StatefulWidget { | ||
class MyApp extends StatelessWidget { | ||
const MyApp({super.key}); | ||
|
||
@override | ||
State<MyApp> createState() => _MyAppState(); | ||
} | ||
Widget build(BuildContext context) { | ||
return MultiProvider( | ||
providers: [ | ||
ChangeNotifierProvider(create: (_) { | ||
return ThemeProvider(context); | ||
}), | ||
ChangeNotifierProvider(create: (_) { | ||
return OnBoardingProvider(); | ||
}), | ||
ChangeNotifierProvider( | ||
create: (context) => DatabaseService(), | ||
), | ||
ChangeNotifierProvider( | ||
create: (context) => AddPasswordProvider(), | ||
), | ||
ChangeNotifierProvider( | ||
create: (context) => GeneratedPasswordProvider(), | ||
), | ||
], | ||
builder: (context, child) { | ||
return Consumer<ThemeProvider>(builder: ( | ||
context, | ||
value, | ||
child, | ||
) { | ||
removesplash(); | ||
|
||
class _MyAppState extends State<MyApp> { | ||
ThemeProvider themeProvider = ThemeProvider(); | ||
void checkCurrentTheme() async { | ||
themeProvider.setTheme = await themeProvider.themePrefrences.getTheme(); | ||
SharedPreferences prefs = await SharedPreferences.getInstance(); | ||
isviewed = prefs.getInt('onBoard'); | ||
await Future.delayed(const Duration(seconds: 3)); | ||
FlutterNativeSplash.remove(); | ||
return MaterialApp( | ||
debugShowCheckedModeBanner: false, | ||
title: Consts.APP_NAME, | ||
theme: Styles.themeData( | ||
context: context, | ||
isDarkTheme: false, | ||
), | ||
darkTheme: Styles.themeData( | ||
context: context, | ||
isDarkTheme: true, | ||
), | ||
themeMode: context.watch<ThemeProvider>().themeMode, | ||
home: context.watch<OnBoardingProvider>().isBoardingCompleate | ||
? const LoginPage() | ||
: const OnBoardingSceen(), | ||
); | ||
}); | ||
}); | ||
} | ||
|
||
@override | ||
void initState() { | ||
checkCurrentTheme(); | ||
super.initState(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MultiProvider( | ||
providers: [ | ||
ChangeNotifierProvider( | ||
create: (context) => AddPasswordProvider(), | ||
), | ||
ChangeNotifierProvider( | ||
create: (context) => DatabaseService(), | ||
), | ||
ChangeNotifierProvider( | ||
create: (context) => GeneratedPasswordProvider(), | ||
), | ||
ChangeNotifierProvider(create: (_) { | ||
return themeProvider; | ||
}), | ||
], | ||
builder: (context, child) { | ||
return MaterialApp( | ||
debugShowCheckedModeBanner: false, | ||
title: Consts.APP_NAME, | ||
theme: Styles.themeData( | ||
context.watch<ThemeProvider>().getDarkTheme, context), | ||
home: isviewed != 0 ? const OnBoardingSceen() : const LoginPage(), | ||
); | ||
}, | ||
); | ||
void removesplash() async { | ||
return await Future.delayed(const Duration(seconds: 3), () { | ||
FlutterNativeSplash.remove(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'dart:developer'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
||
class OnBoardingProvider with ChangeNotifier { | ||
OnBoardingProvider() { | ||
getOnboardInfo(); | ||
} | ||
|
||
bool _isBoardingCompleate = false; | ||
bool get isBoardingCompleate => _isBoardingCompleate; | ||
set isBoardingCompleate(bool value) { | ||
_isBoardingCompleate = value; | ||
storeOnboardInfo(); | ||
notifyListeners(); | ||
} | ||
|
||
void storeOnboardInfo() async { | ||
SharedPreferences prefs = await SharedPreferences.getInstance(); | ||
await prefs.setBool('onBoard', _isBoardingCompleate); | ||
log(_isBoardingCompleate.toString(), name: 'setonBoard'); | ||
} | ||
|
||
void getOnboardInfo() async { | ||
SharedPreferences prefs = await SharedPreferences.getInstance(); | ||
isBoardingCompleate = prefs.getBool('onBoard') ?? false; | ||
log(isBoardingCompleate.toString(), name: 'onBoard'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,42 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import '../services/theme_prefrence.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
||
class ThemeProvider with ChangeNotifier { | ||
ThemePrefrences themePrefrences = ThemePrefrences(); | ||
ThemeProvider(BuildContext context) { | ||
getSystemTheme(context); | ||
getTheme(); | ||
} | ||
bool _isDarkTheme = false; | ||
bool get getDarkTheme => _isDarkTheme; | ||
bool get isDarkTheme => _isDarkTheme; | ||
|
||
ThemeMode _themeMode = ThemeMode.system; | ||
ThemeMode get themeMode => _themeMode; | ||
|
||
set setTheme(bool value) { | ||
_isDarkTheme = value; | ||
themePrefrences.setTheme(value); | ||
set themeMode(ThemeMode themeMode) { | ||
_themeMode = themeMode; | ||
saveTheme(themeMode: themeMode.name); | ||
notifyListeners(); | ||
} | ||
|
||
saveTheme({required String themeMode}) async { | ||
final SharedPreferences prefs = await SharedPreferences.getInstance(); | ||
await prefs.setString('themeMode', themeMode); | ||
} | ||
|
||
getTheme() async { | ||
final SharedPreferences prefs = await SharedPreferences.getInstance(); | ||
var theme = prefs.getString('themeMode') ?? 'system'; | ||
_themeMode = ThemeMode.values.firstWhere( | ||
(element) => element.toString() == 'ThemeMode.$theme', | ||
orElse: () => ThemeMode.system); | ||
// notifyListeners(); | ||
} | ||
|
||
getSystemTheme(BuildContext context) { | ||
_isDarkTheme = | ||
// WidgetsBinding.instance.window.platformBrightness == Brightness.dark; | ||
WidgetsBinding.instance.platformDispatcher.platformBrightness == | ||
Brightness.dark; | ||
// notifyListeners(); | ||
} | ||
} |
Oops, something went wrong.