Created
October 5, 2022 10:31
-
-
Save vikilinho/264b7d7bce3cc4c5e716662e25fdfcf9 to your computer and use it in GitHub Desktop.
Splashscreen
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
import 'dart:async'; | |
import 'dart:convert'; | |
import 'dart:developer'; | |
import 'package:cached_network_image/cached_network_image.dart'; | |
import 'package:connectivity_plus/connectivity_plus.dart'; | |
import 'package:easy_localization/easy_localization.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:helvtica_transfers/base/apis/api_url.dart'; | |
import 'package:helvtica_transfers/base/theme/palette.dart'; | |
import 'package:helvtica_transfers/generated/%20locale_keys.g.dart'; | |
import 'package:helvtica_transfers/launchscreen/language_screen.dart'; | |
import 'package:helvtica_transfers/launchscreen/launch_screen.dart'; | |
import 'package:helvtica_transfers/launchscreen/mobile_branding.dart'; | |
import 'package:helvtica_transfers/launchscreen/new_mobile.dart'; | |
import 'package:helvtica_transfers/login/hex_color.dart'; | |
import 'package:helvtica_transfers/main.dart'; | |
import 'package:shared_preferences/shared_preferences.dart'; | |
import 'package:http/http.dart' as http; | |
import '../base/theme/styles.dart'; | |
String mykolor = "#ffffff"; | |
String klogo = | |
"https://mta-cdn-public-test.s3.eu-west-1.amazonaws.com/organisations/remitter/images/_U1nSNqnb6f3JaLpp.png"; | |
bool hasloaded = false; | |
class SplashScreen extends StatefulWidget { | |
const SplashScreen({Key key}) : super(key: key); | |
@override | |
State<SplashScreen> createState() => _SplashScreenState(); | |
} | |
class _SplashScreenState extends State<SplashScreen> { | |
double screenHeight = 0.0; | |
double screenWidth = 0.0; | |
@override | |
void initState() { | |
mobileBrand().whenComplete(() => Timer( | |
Duration(seconds: 3), | |
() => Navigator.push( | |
context, | |
MaterialPageRoute( | |
builder: (context) => LaunchScreenPage(), | |
), | |
))); | |
log("load completed"); | |
super.initState(); | |
} | |
Widget _centerLayout() { | |
return RichText( | |
textAlign: TextAlign.center, | |
text: TextSpan( | |
children: [ | |
// TextSpan( | |
// text: "Simply" + " ", //LocaleKeys.Move_money.tr() | |
// style: Styles.customTextStyle( | |
// color: Palette.mainBackgroundColour, | |
// fontSize: 21.0, | |
// fontWeight: FontWeight.w300, | |
// ), | |
// ), | |
// TextSpan( | |
// text: "Simply Reliable and Fast" + | |
// "\n ", // "Simply Reliable and Fast" | |
// style: Styles.customTextStyle( | |
// color: Colors.black, | |
// fontSize: 21.0, | |
// fontWeight: FontWeight.bold, | |
// ), | |
// ), | |
// TextSpan( | |
// text: "and Fast", //LocaleKeys.In_the_world.tr() | |
// style: Styles.customTextStyle( | |
// color: Palette.mainBackgroundColour, | |
// fontSize: 21.0, | |
// fontWeight: FontWeight.w300, | |
// ), | |
// ), | |
], | |
), | |
); | |
} | |
Future<MobileBranding> mobileBrand() async { | |
// var box = await Hive.openBox('testBox'); | |
var connectivityResult = await (Connectivity().checkConnectivity()); | |
if (connectivityResult == ConnectivityResult.mobile || | |
connectivityResult == ConnectivityResult.wifi) { | |
try { | |
var url = ApiUrls.MOBILE_BRANDING; | |
var response = await http.get(Uri.parse(url), headers: { | |
"Content-Type": "application/json", | |
'Accept': 'application/json', | |
}); | |
if (response.statusCode == 200) { | |
print("I am fetching the data"); | |
log(response.body); | |
var mybody = MobileBranding.fromJson(json.decode(response.body)); | |
final SharedPreferences prefs = await SharedPreferences.getInstance(); | |
print(" What is the logo ${mybody.data.logo}"); | |
prefs.setString( | |
'mainbgColor', mybody.data.mobileMainBackgroundColour); | |
prefs.setString('applogo', mybody.data.logo); | |
prefs.setString( | |
'mobileSubPagesColour', mybody.data.mobileSubPagesColour); | |
prefs.setString( | |
'mobileMenuBarColour', mybody.data.mobileMenuBarColour); | |
prefs.setString('mobileLaunchScreenHeaderColour', | |
mybody.data.mobileLaunchScreenHeaderColour); | |
prefs.setString( | |
'mobileMainFooterColour', mybody.data.mobileMainFooterColour); | |
prefs.setString( | |
'mobileBorderLineColour', mybody.data.mobileBorderLineColour); | |
prefs.setString( | |
'mobileBorderLineColour', mybody.data.mobileBorderLineColour); | |
prefs.setString( | |
'mobilePrimaryIconColour', mybody.data.mobilePrimaryIconColour); | |
prefs.setString('mobileSecondaryIconColour', | |
mybody.data.mobileSecondaryIconColour); | |
prefs.setString( | |
'mobileOtherIconsColour', mybody.data.mobileOtherIconsColour); | |
prefs.setString('mobileMainLoginBoxButtonColour', | |
mybody.data.mobileMainLoginBoxButtonColour); | |
prefs.setString( | |
'mobileInputTextColour', mybody.data.mobileInputTextColour); | |
prefs.setString('mobileFooterHoverButtonColour', | |
mybody.data.mobileFooterHoverButtonColour); | |
prefs.setString('mobileMenuBarHoverButtonColour', | |
mybody.data.mobileMenuBarHoverButtonColour); | |
prefs.setString( | |
'mobileInputBoxColour', mybody.data.mobileInputBoxColour); | |
prefs.setString('mobileOtherButtonTextColour', | |
mybody.data.mobileOtherButtonTextColour); | |
prefs.setString( | |
'mobileLoginBoxTextColour', mybody.data.mobileLoginBoxTextColour); | |
prefs.setString( | |
'mobileOtherButtonColour', mybody.data.mobileOtherButtonColour); | |
prefs.setString( | |
'mobileSubPagesColour', mybody.data.mobileSubPagesColour); | |
prefs.setString('mobileTransactionHistoryValueTextColour', | |
mybody.data.mobileTransactionHistoryValueTextColour); | |
prefs.setString('mobileSubMenuValueTextColour', | |
mybody.data.mobileSubMenuValueTextColour); | |
setState(() { | |
mykolor = mybody.data.mobileLaunchScreenHeaderColour; | |
klogo = mybody.data.logo; | |
appLogo = klogo; | |
hasloaded = true; | |
brandName = prefs.getString('companyName'); | |
mMainBackgroundColour = prefs.getString('mainbgColor'); | |
appLogo = prefs.getString("applogo"); | |
log(appLogo); | |
mSubPagesColour = prefs.getString('mobileSubPagesColour'); | |
mMenuBarColour = prefs.getString('mobileMenuBarColour'); | |
mLaunchScreenHeaderColour = | |
mybody.data.mobileLaunchScreenHeaderColour; | |
mMainFooterColour = prefs.getString('mobileMainFooterColour'); | |
mBorderLineColour = prefs.getString('mobileBorderLineColour'); | |
mDividerLineColour = prefs.getString('mobileDividerLineColour'); | |
mPrimaryIconColour = prefs.getString('mobilePrimaryIconColour'); | |
mSecondaryIconColour = prefs.getString('mobileSecondaryIconColour'); | |
mOtherIconsColour = prefs.getString('mobileOtherIconsColour'); | |
mMainLoginBoxButtonColour = | |
prefs.getString('mobileMainLoginBoxButtonColour'); | |
mOtherButtonColour = prefs.getString('mobileOtherButtonColour'); | |
mLoginBoxTextColour = prefs.getString('mobileLoginBoxTextColour'); | |
mOtherButtonTextColour = | |
prefs.getString('mobileOtherButtonTextColour'); | |
mInputBoxColour = prefs.getString('mobileInputBoxColour'); | |
mMenuBarHoverButtonColour = | |
prefs.getString('mobileMenuBarHoverButtonColour'); | |
mFooterHoverButtonColour = | |
prefs.getString('mobileFooterHoverButtonColour'); | |
mInputTextColour = prefs.getString('mobileInputTextColour'); | |
mSubMenuLabelTextColour = prefs.getString('mobileSubPagesColour'); | |
mTransactionHistoryValueTextColour = | |
prefs.getString('mobileTransactionHistoryValueTextColour'); | |
mSubMenuValueTextColour = | |
prefs.getString('mobileSubMenuValueTextColour'); | |
print(mMainBackgroundColour); | |
}); | |
// Navigator.push( | |
// context, | |
// MaterialPageRoute(builder: (context) => LaunchScreenPage()), | |
// ); | |
return mybody; | |
} else { | |
// Navigator.push( | |
// context, | |
// MaterialPageRoute(builder: (context) => LaunchScreenPage()), | |
// ); | |
} | |
} catch (e) { | |
print(e.toString()); | |
print("error caugth"); | |
return Navigator.push( | |
context, | |
MaterialPageRoute(builder: (context) => LaunchScreenPage()), | |
); | |
} | |
} else if (connectivityResult == ConnectivityResult.none) { | |
_showSnakBarMsg( | |
'Please check your internet connection and try again later'); | |
// I am connected to a wifi network. | |
} | |
Navigator.push( | |
context, | |
MaterialPageRoute(builder: (context) => LaunchScreenPage()), | |
); | |
} | |
void _showSnakBarMsg(String msg) { | |
ScaffoldMessenger.of(context).showSnackBar(SnackBar( | |
behavior: SnackBarBehavior.floating, | |
backgroundColor: Colors.red[700], | |
content: Text(msg), | |
duration: Duration(seconds: 3), | |
action: SnackBarAction( | |
textColor: Colors.white, | |
label: 'Ok', | |
onPressed: () { | |
// Some code to undo the change. | |
}))); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
backgroundColor: HexColor.fromHex(mykolor) ?? "#ffffff", | |
body: SafeArea( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: [ | |
SizedBox( | |
height: MediaQuery.of(context).size.height * 0.08, | |
), | |
Center( | |
child: Container( | |
height: MediaQuery.of(context).size.height * 0.3, | |
width: MediaQuery.of(context).size.width * 0.6, | |
child: hasloaded | |
? CachedNetworkImage( | |
imageUrl: klogo, | |
placeholder: (context, url) => | |
CircularProgressIndicator( | |
color: Colors.transparent, | |
), | |
errorWidget: (context, url, error) => | |
Image.asset("assets/Unispay_Logo.png"), | |
) | |
: SizedBox()), | |
), | |
hasloaded ? _centerLayout() : Container(), | |
]), | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment