Skip to content

Commit

Permalink
fixed guest login and navigator errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Hareesh-Nandigrama committed Sep 14, 2023
1 parent a928dbf commit 4781549
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 46 deletions.
20 changes: 10 additions & 10 deletions lib/pages/login/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:onestop_dev/globals/size_config.dart';
import 'package:onestop_dev/pages/login/welcome.dart';
import 'package:onestop_dev/widgets/login/login_webview.dart';
import 'package:webview_flutter/webview_flutter.dart';

Expand All @@ -15,7 +16,7 @@ class LoginPage extends StatefulWidget {
}

class _LoginPageState extends State<LoginPage> {
// bool loading = false;
bool loading = false;
final Completer<WebViewController> _controller =
Completer<WebViewController>();

Expand All @@ -30,15 +31,14 @@ class _LoginPageState extends State<LoginPage> {
SizeConfig().init(context);
return Scaffold(
body:
// loading
// ?
loading
?
SafeArea(child: LoginWebView(controller: _controller))
// : WelcomePage(setLoading: () {
// setState(() {
// loading = true;
// });
// })

);
: WelcomePage(setLoading: () {
setState(() {
loading = true;
});
}
));
}
}
40 changes: 15 additions & 25 deletions lib/pages/login/splash.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,24 @@ class _SplashPageState extends State<SplashPage> {
@override
void initState() {
super.initState();
LoginStore()
.isAlreadyAuthenticated()
.then((result) {
if (result == SplashResponse.authenticated && LoginStore.isProfileComplete){
Navigator.of(context).pushNamedAndRemoveUntil(HomePage.id, (Route<dynamic> route) => false);
}
else if(result == SplashResponse.blocked){
Navigator.of(context).pushNamedAndRemoveUntil(BlockedPage.id, (Route<dynamic> route) => false);
}
else {
Navigator.of(context).pushNamedAndRemoveUntil(LoginPage.id, (Route<dynamic> route) => false);
}
});
}


@override
Widget build(BuildContext context) {
return FutureBuilder<SplashResponse>(
future: LoginStore().isAlreadyAuthenticated(),
builder: (context, snapshot){
if(snapshot.hasData)
{
SplashResponse result = snapshot.data!;
if (result == SplashResponse.authenticated && LoginStore.isProfileComplete){
return const HomePage();
} else if(result == SplashResponse.blocked){
return const BlockedPage();
}else{
return const LoginPage();
}
}
else if(snapshot.hasError)
{
return const Scaffold();
}
else
{
//Waiting State
return Scaffold(
);
}
});
return const Scaffold();
}
}
6 changes: 3 additions & 3 deletions lib/pages/login/welcome.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import '../../globals/size_config.dart';

class WelcomePage extends StatelessWidget {
static String id = "/login2";
// final Function setLoading;
final Function setLoading;
const WelcomePage({Key? key,
// required this.setLoading
required this.setLoading
}) : super(key: key);

@override
Expand Down Expand Up @@ -38,7 +38,7 @@ class WelcomePage extends StatelessWidget {
padding: EdgeInsets.symmetric(
horizontal: MySpaces.horizontalScreenPadding
),
child: const LoginButton(),
child: LoginButton(setLoading: setLoading,),
),
),
],
Expand Down
1 change: 0 additions & 1 deletion lib/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,5 @@ final routes = {
Scoreboard.id: (context) => const Scoreboard(),
Upsp.id: (context) => const Upsp(),
GuestHouse.id: (context) => const GuestHouse(),
WelcomePage.id:(context)=> const WelcomePage(),
ComplaintsPage.id:(context)=> const ComplaintsPage()
};
12 changes: 6 additions & 6 deletions lib/widgets/login/login_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import 'package:provider/provider.dart';
class LoginButton extends StatelessWidget {
const LoginButton({
Key? key,
// required this.setLoading,
required this.setLoading,
}) : super(key: key);

// final Function setLoading;
final Function setLoading;

@override
Widget build(BuildContext context) {
Expand All @@ -32,10 +32,10 @@ class LoginButton extends StatelessWidget {
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18))),
onPressed: () {
// setLoading();
Navigator.of(context).pushNamed(
'/login',
);
setLoading();
// Navigator.of(context).pushNamed(
// '/login',
// );
},
child: FittedBox(
fit: BoxFit.fitWidth,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 2.1.1+44
version: 2.1.2+45

environment:
sdk: ">=2.17.0 <3.0.0"
Expand Down

0 comments on commit 4781549

Please sign in to comment.