rollback to material + app usage init
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import 'package:app_usage/app_usage.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:tasktracker/Data.dart';
|
||||
import 'DebugHelper.dart';
|
||||
import 'User.dart' as Users;
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'theme_provider.dart';
|
||||
@@ -18,18 +20,19 @@ class SplashScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _SplashScreenState extends State<SplashScreen> {
|
||||
Future<void> initSettings() async{
|
||||
Future<void> initSettings() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
bool value = true;
|
||||
if(prefs.containsKey("theme")){
|
||||
value = ((await prefs.getInt("theme"))==0);
|
||||
}else{
|
||||
if (prefs.containsKey("theme")) {
|
||||
value = ((await prefs.getInt("theme")) == 0);
|
||||
} else {
|
||||
await prefs.setInt("theme", 0);
|
||||
}
|
||||
print('Dark theme is : $value');
|
||||
final provider = Provider.of<ThemeProvider>(context, listen: false);
|
||||
provider.toggleTheme(value);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
@@ -38,14 +41,16 @@ class _SplashScreenState extends State<SplashScreen> {
|
||||
NotificationManager.RescheduleNotifications();
|
||||
}
|
||||
|
||||
|
||||
void notificationSelected(String? payload) {
|
||||
if(payload!=null){
|
||||
if(payload.toLowerCase().contains("activity")){
|
||||
Navigator.of(context).push(MaterialPageRoute(builder: (context) => NewActivity())).then((value) => {Users.refreshUserData()});
|
||||
if (payload != null) {
|
||||
if (payload.toLowerCase().contains("activity")) {
|
||||
Navigator.of(context)
|
||||
.push(MaterialPageRoute(builder: (context) => NewActivity()))
|
||||
.then((value) => {Users.refreshUserData()});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void init() async {
|
||||
await initSettings();
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
@@ -53,25 +58,29 @@ class _SplashScreenState extends State<SplashScreen> {
|
||||
// print(loginResponse.body);
|
||||
|
||||
if (!prefs.containsKey("password") || !prefs.containsKey("username")) {
|
||||
Navigator.of(context).pushNamedAndRemoveUntil('/welcome', (route) => false);
|
||||
Navigator.of(context)
|
||||
.pushNamedAndRemoveUntil('/welcome', (route) => false);
|
||||
} else {
|
||||
try {
|
||||
http.Response loginResponse = await Users.login(
|
||||
prefs.getString("username") ?? '',
|
||||
prefs.getString("password") ?? '');
|
||||
print(loginResponse.body);
|
||||
if (loginResponse.body.toLowerCase().contains("success")) { //Login Success
|
||||
if (loginResponse.body.toLowerCase().contains("success")) {
|
||||
//Login Success
|
||||
Continue();
|
||||
} else { //Login Failed
|
||||
} else {
|
||||
//Login Failed
|
||||
LoginFailed();
|
||||
}
|
||||
} catch (error) { //Login Failed
|
||||
} catch (error) {
|
||||
//Login Failed
|
||||
LoginFailed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LoginFailed() async{
|
||||
void LoginFailed() async {
|
||||
bool dbExist = await Users.cacheDbExist();
|
||||
if (dbExist) {
|
||||
print('cache Database exists, Lets go CACHE!');
|
||||
@@ -81,7 +90,7 @@ class _SplashScreenState extends State<SplashScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
void Continue() async{
|
||||
void Continue() async {
|
||||
await Users.initUserData();
|
||||
Navigator.of(context).pushReplacementNamed('/home');
|
||||
print('Going home!');
|
||||
@@ -91,9 +100,12 @@ class _SplashScreenState extends State<SplashScreen> {
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(colors: [Colors.lightBlue, Colors.blue],stops: [0,1],begin: Alignment.topLeft, end: Alignment.bottomRight)
|
||||
),
|
||||
// color: Colors.redAccent,
|
||||
gradient: LinearGradient(
|
||||
colors: [Colors.lightBlue, Colors.blue],
|
||||
stops: [0, 1],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight)),
|
||||
// color: Colors.redAccent,
|
||||
padding: EdgeInsets.all(80),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
@@ -106,11 +118,15 @@ class _SplashScreenState extends State<SplashScreen> {
|
||||
SpinKitPouringHourGlass(color: Colors.white),
|
||||
],
|
||||
),
|
||||
DefaultTextStyle(style: TextStyle(fontSize: 15,color: Colors.white,fontStyle: FontStyle.italic),
|
||||
child: Text('If you lie to me, That means you lie to yourself\n\n -This app (2022)',))
|
||||
DefaultTextStyle(
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
color: Colors.white,
|
||||
fontStyle: FontStyle.italic),
|
||||
child: Text(
|
||||
'If you lie to me, That means you lie to yourself\n\n -This app (2022)',
|
||||
))
|
||||
// Text('Loading', style:TextStyle(color: Colors.grey, fontSize: 20,fontStyle: FontStyle.italic))
|
||||
]));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user