NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

lib => data => sharepref => shared_pref_helper

import 'package:alanis/export.dart';

class PrefManger {
static SharedPreferences _sharedPreference;

/*======================================================== Save Login Data ===========================================*/

static Future<bool> getFirstTime() async {
_sharedPreference = await SharedPreferences.getInstance();
return Future.value(_sharedPreference.getBool(LocalStorage.isFirstTime));
}

/*=================================================== get login data================================================= */

static isFirstTime(bool isFirst) async {
_sharedPreference = await SharedPreferences.getInstance();
_sharedPreference.setBool(LocalStorage.isFirstTime, isFirst);
}

static saveAccessToken(String token) async {
_sharedPreference = await SharedPreferences.getInstance();
_sharedPreference.setString(LocalStorage.accessToken, token);
}

static Future<String> getAcessToken() async {
_sharedPreference = await SharedPreferences.getInstance();
return Future.value(_sharedPreference.getString(LocalStorage.accessToken));
}

static saveRoleID(String roleid) async {
_sharedPreference = await SharedPreferences.getInstance();
_sharedPreference.setString(LocalStorage.professional, roleid);
}

static Future<String> getRoleID() async {
_sharedPreference = await SharedPreferences.getInstance();
return Future.value(_sharedPreference.getString(LocalStorage.professional));
}

static saveRegisterData(LoginDataModel loginRepsonseModel) async {
_sharedPreference = await SharedPreferences.getInstance();
_sharedPreference.setString(
LocalStorage.loginRepsonseModel, jsonEncode(loginRepsonseModel));
}

static Future<LoginDataModel> getRegisterData() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();

Map<String, dynamic> userMap;
final String userStr = prefs.getString(LocalStorage.loginRepsonseModel);
if (userStr != null) userMap = jsonDecode(userStr) as Map<String, dynamic>;
if (userMap != null) {
LoginDataModel user = LoginDataModel.fromJson(userMap);
return user;
}
return null;
}

static saveRemberMeData({String email, String password}) async {
_sharedPreference = await SharedPreferences.getInstance();
_sharedPreference.setString(LocalStorage.email, email);
_sharedPreference.setString(LocalStorage.password, password);
}

static Future<Map<String, String>> getRemberData() async {
Map<String, String> data = Map<String, String>();
_sharedPreference = await SharedPreferences.getInstance();
data[LocalStorage.email] = _sharedPreference.getString(LocalStorage.email);
data[LocalStorage.password] =
_sharedPreference.getString(LocalStorage.password);
return Future.value(data);
}




static Future<bool> getlabel1() async {
_sharedPreference = await SharedPreferences.getInstance();
return Future.value(_sharedPreference.getBool(LocalStorage.label1));
}

static Future<bool> getlabel2() async {
_sharedPreference = await SharedPreferences.getInstance();
return Future.value(_sharedPreference.getBool(LocalStorage.label2));
}

static Future<bool> getlabel3() async {
_sharedPreference = await SharedPreferences.getInstance();
return Future.value(_sharedPreference.getBool(LocalStorage.label3));
}

static Future<bool> getlabel4() async {
_sharedPreference = await SharedPreferences.getInstance();
return Future.value(_sharedPreference.getBool(LocalStorage.label4));
}

static Future<bool> getlabel5() async {
_sharedPreference = await SharedPreferences.getInstance();
return Future.value(_sharedPreference.getBool(LocalStorage.label5));
}

static setlabel1(bool isFirst) async {
_sharedPreference = await SharedPreferences.getInstance();
_sharedPreference.setBool(LocalStorage.isFirstTime, isFirst);
}

static setlabel2(bool isFirst) async {
_sharedPreference = await SharedPreferences.getInstance();
_sharedPreference.setBool(LocalStorage.isFirstTime, isFirst);
}

static setlabel3(bool isFirst) async {
_sharedPreference = await SharedPreferences.getInstance();
_sharedPreference.setBool(LocalStorage.isFirstTime, isFirst);
}

static setlabel4(bool isFirst) async {
_sharedPreference = await SharedPreferences.getInstance();
_sharedPreference.setBool(LocalStorage.isFirstTime, isFirst);
}

static setlabel5(bool isFirst) async {
_sharedPreference = await SharedPreferences.getInstance();
_sharedPreference.setBool(LocalStorage.isFirstTime, isFirst);
}

}

/*=================================================== Local Storage ================================================= */


lib => data => sharepref => local_storage

class LocalStorage {
LocalStorage._();

static String professional = "professional";
static const String isLoggedin = "isLoggedin";
static const String isFirstTime = "isFirstTime";
static const String accessToken = "accessToken";
static const String email = "email";
static const String password = "password";
static const String loginRepsonseModel = "loginRepsonseModel";
static const String label1 = "label1";
static const String label2 = "label2";
static const String label3 = "label3";
static const String label4 = "label4";
static const String label5 = "label5";


/*=================================================== Sign In================================================= */



import 'package:alanis/export.dart';

class LoginScreen extends StatefulWidget {
@override
_LoginScreenState createState() => _LoginScreenState();
}

class _LoginScreenState extends State<LoginScreen> {
final _formKey = GlobalKey<FormState>();
TextEditingController _emailTextController;
TextEditingController _passwordTextController;
FocusNode _emailNode;
FocusNode _passwordNode;
bool rememberme;
DeviceInfoPlugin deviceInfo;
DateTime _lastPressedAt;
LoginResponseModel _loginResponseModel = LoginResponseModel();
LoginDataModel _loginDataModel = LoginDataModel();
CustomLoader _customLoader = CustomLoader();
bool isAndroid;
IosDeviceInfo iosInfo;
AndroidDeviceInfo androidInfo;
Map map;
bool checkValue;
bool eye = true;

_getRemberMeData() {
PrefManger.getRemberData().then((value) {
map = value;
if (map != null) {
if (mounted)
setState(() {
_emailTextController.text = map["email"];
_passwordTextController.text = map["password"];
if (_emailTextController.text.length == 0 &&
_passwordTextController.text.length == 0) {
checkValue = false;
} else {
checkValue = true;
}
});
}
});
}

@override
void initState() {
super.initState();
_emailNode = new FocusNode();
_passwordNode = new FocusNode();
_emailTextController = new TextEditingController();
_passwordTextController = new TextEditingController();
rememberme = false;
isAndroid = Platform.isAndroid ? true : false;
deviceInfo = DeviceInfoPlugin();
deviceDetail();
checkValue = false;
_getRemberMeData();
}

@override
void dispose() {
_customLoader.hide();
super.dispose();
}

@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
if (_lastPressedAt == null ||
DateTime.now().difference(_lastPressedAt) > Duration(seconds: 1)) {
Fluttertoast.showToast(
fontSize: 12.0,
msg: Strings.pressAgain,
toastLength: Toast.LENGTH_SHORT,
timeInSecForIosWeb: 1,
textColor: Colors.black87,
gravity: ToastGravity.BOTTOM,
);
_lastPressedAt = DateTime.now();
return false;
}
return true;
},
child: Container(
color: Colors.white,
child: SafeArea(
child: Scaffold(
backgroundColor: Colors.white,
body: _body(),
),
),
),
);
}

_body() {
return Stack(
children: [
SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
imageWidget(),
HelperWidget.sizeBox(height: Dimens.margin_20),
loginHeading(),
_form(),
HelperWidget.sizeBox(height: Dimens.height_10),
_rememberAndForget(),
HelperWidget.sizeBox(height: Dimens.margin_20),
_onLoginPress(),
HelperWidget.sizeBox(height: Dimens.margin_20),
_socialButton(),
HelperWidget.sizeBox(height: Dimens.margin_20),
_dontHaveAccountText(),
HelperWidget.sizeBox(height: Dimens.margin_20),
],
),
),
// _backButton()
],
);
}

Future<void> deviceDetail() async {
!isAndroid
? await deviceInfo.iosInfo.then((value) {
iosInfo = value;
})
: await deviceInfo.androidInfo.then((value) {
androidInfo = value;
});
}

void loginApiCall() async {
hideKeyBoard(context: context);
_customLoader.show(context);
var response = AuthRequestModel.loginRequestData(
email: _emailTextController.text.trim(),
password: _passwordTextController.text.trim(),
deviceName: isAndroid ? androidInfo.device : iosInfo.name,
deviceType: isAndroid ? androidInfo.type : iosInfo.model,
deviceToken:
isAndroid ? androidInfo.host : iosInfo.identifierForVendor);

await APIRepository.loginApiCall(response, context).then((value) {
if (value != null) {
_customLoader.hide();
_loginResponseModel = value;
_loginDataModel = _loginResponseModel.detail;
saveDataToLcoalStorage(_loginResponseModel, _loginDataModel);
rememberMeData(checkValue);
if (_loginResponseModel.detail.roleId == ROLE_PROFESSIONAL) {
PrefManger.saveRoleID(ROLE_PROFESSIONAL.toString());
if (_loginDataModel.checkProfessionalDetail == true)
HelperUtility.pushAndRemoveUntil(
context: context, route: BottomNavigationScreen());
else
HelperUtility.pushAndRemoveUntil(
context: context, route: ProfessionalQuestion());
} else if (_loginResponseModel.detail.roleId == ROLE_RISING_STAR) {
PrefManger.saveRoleID(ROLE_RISING_STAR.toString());
if (_loginDataModel.checkRisingDetail == true)
HelperUtility.pushAndRemoveUntil(
context: context, route: BottomNavigationScreen());
else
HelperUtility.pushAndRemoveUntil(
context: context, route: RisingStarQuestion());
}
HelperWidget.toast(_loginResponseModel.message);
} else {
_customLoader.hide();
}
}).onError((error, stackTrace) {
_customLoader.hide();
HelperWidget.toast(error);
});
}

void saveDataToLcoalStorage(
LoginResponseModel loginResponseModel, LoginDataModel loginDataModel) {
PrefManger.saveRegisterData(loginDataModel);
PrefManger.saveAccessToken(_loginResponseModel.accessToken);
}

void rememberMeData(bool checkValue) {
if (checkValue == true) {
PrefManger.saveRemberMeData(
email: _emailTextController.text.toString(),
password: _passwordTextController.text.toString());
} else {
PrefManger.saveRemberMeData(email: "", password: "");
}
}

Widget imageWidget() {
return Container(
height: 250.0,
width: HelperUtility.fullWidthScreen(context: context),
child: Image.asset(Assets.bg_2, fit: BoxFit.fill));
}

Widget loginHeading() => Text(
Strings.signIn,
style: HelperUtility.textStyleBold(
fontWeight: FontWeight.w400,
color: Colors.black,
fontsize: Dimens.font_30),
);

Widget loginSubTitle() => Text(
Strings.loginTitle,
style: HelperUtility.textStyle(
color: Colors.grey, fontsize: Dimens.font_16),
);

/*================================================================ Creation of From ========================================================*/

_form() => Form(
key: _formKey,
child: Column(
children: <Widget>[_emailEditText(), _passWordField()],
),
);

/*=================================================================== Email Edit Text ====================================================================*/

Widget _emailEditText() => Padding(
padding: EdgeInsets.only(left: 20, right: 20.0),
child: TextFieldWidget(
focusNode: _emailNode,
textController: _emailTextController,
hint: Strings.email,
inputAction: TextInputAction.next,
inputType: TextInputType.emailAddress,
validate: (String val) {
return EmailFormValidator.validate(val);
},
icon: Assets.email,
));

/*====================================================================== Password Edit Text Field ==========================================================*/

Widget _passWordField() => Padding(
padding: EdgeInsets.only(left: 20, right: 20.0),
child: TextFieldWidget(
focusNode: _passwordNode,
textController: _passwordTextController,
hint: Strings.password,
isObsecure: eye,
onFieldSubmitted: (String val) {
_passwordNode.unfocus();
_passwordNode.canRequestFocus = false;
},
inputFormatters: [
FilteringTextInputFormatter.allow(RegExp("[A-Za-z0-9#+-./:@] *"))
],
inputAction: TextInputAction.done,
validate: (String val) {
if (val.length < 1)
return "Password can't be empty.";
else
return null;
},
inputType: TextInputType.visiblePassword,
icon: Assets.password,
suffixIcon: eye ? Assets.eyeon : Assets.eyeoff,
onTapSufix: () {
_passwordNode.unfocus();
_passwordNode.canRequestFocus = false;
setState(() {
eye = !eye;
});
},
));

Widget _textRememberMe() => Container(
padding: EdgeInsets.only(left: 25, right: 8.0),
height: 25,
width: HelperUtility.fullWidthScreen(context: context),
child: Row(
children: [
Flexible(
child: Checkbox(
activeColor: primaryColor,
value: checkValue,
onChanged: (newValue) {
if (mounted)
setState(() {
checkValue = newValue;
rememberMeData(checkValue);
});
},
),
),
SizedBox(width: 4),
Text(
Strings.rememberme,
style: HelperUtility.textStyle(
color: Colors.grey, fontsize: Dimens.font_14),
),
],
),
);

Widget _textForgotPassWord() => Align(
alignment: Alignment.centerRight,
child: Padding(
padding: EdgeInsets.only(right: Dimens.margin_25),
child: Row(
children: [
Image.asset(
Assets.forgetIcon,
height: 15,
width: 15,
),
SizedBox(width: 4),
HelperWidget.getInkwell(
onTap: () {
HelperUtility.pushNamed(
context: context, route: Routes.forgotPassword);
},
widget: Text(
Strings.forgotPassword,
style: HelperUtility.textStyle(
color: Colors.grey, fontsize: Dimens.font_14),
)),
],
)),
);

Widget _rememberAndForget() => Align(
alignment: Alignment.centerLeft,
child: Row(
children: [Expanded(child: _textRememberMe()), _textForgotPassWord()],
),
);

Widget _socialButton() => Padding(
padding: EdgeInsets.only(left: 20, right: 20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
_facbookButton(),
HelperWidget.sizeBox(width: Dimens.radius_10),
Expanded(child: _googleButton()),
],
),
);

Widget _facbookButton() => Container(
padding: EdgeInsets.all(Dimens.margin_10),
height: Dimens.margin_50,
width: HelperUtility.fullWidthScreen(context: context) * 0.43,
decoration: HelperWidget.decorationBoxColor(
outlineColor: Colors.blue,
roundCorner: Dimens.margin_50,
fillColor: Colors.blue),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(Assets.facebook),
SizedBox(width: 10),
Text(
Strings.facebookF,
style: HelperUtility.textStyleBold(
color: Colors.white, fontsize: 16),
),
],
),
);

Widget _googleButton() => Container(
padding: EdgeInsets.all(Dimens.margin_10),
height: Dimens.margin_50,
width: HelperUtility.fullWidthScreen(context: context) * 0.43,
decoration: HelperWidget.decorationBoxColor(
outlineColor: Colors.red,
roundCorner: Dimens.margin_50,
fillColor: Colors.red),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(Assets.google),
SizedBox(width: 10),
Text(
Strings.googleS,
style: HelperUtility.textStyleBold(
color: Colors.white, fontsize: 16),
),
],
),
);

Widget _onLoginPress() => Padding(
padding: EdgeInsets.only(left: 20, right: 20.0),
child: CustomButton(
height: Dimens.height_45,
isbold: true,
buttonText: Strings.signIn,
fontsize: Dimens.font_18,
textColor: Colors.white,
buttonIcon: Assets.facebook,
isIcon: false,
onPressed: () {
if (_formKey.currentState.validate()) {
loginApiCall();
}
},
buttonColor: primaryColor,
),
);

Widget _dontHaveAccountText() => Align(
alignment: Alignment.bottomCenter,
child: Container(
height: Dimens.width_30,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
Strings.textDontAccount,
style: HelperUtility.textStyle(
color: Colors.grey, fontsize: Dimens.font_16),
),
HelperWidget.sizeBox(width: Dimens.radius_3),
GestureDetector(
onTap: () {
HelperUtility.push(context: context, route: SignUpPage());
},
child: Text(
Strings.signUp,
style: HelperUtility.textStyleBold(
color: primaryColor, fontsize: Dimens.font_16),
),
),
],
),
));
}

}


lib => widgets => textfield_widget
/*============================================== TextFieldWidget ==============================================*/



import 'package:alanis/export.dart';

class TextFieldWidget extends StatelessWidget {
final String hint;
final Function validate;
final Function onTapSufix;
final TextInputType inputType;
final TextEditingController textController;
final FocusNode focusNode;
final String icon;
final String suffixIcon;
final Function onFieldSubmitted;
final TextInputAction inputAction;
final bool isObsecure;
final int maxline;
final bool readonly;
final List<TextInputFormatter> inputFormatters;
final int maxLength;
final Function onTap;

const TextFieldWidget({
this.hint,
this.inputType,
this.onTapSufix,
this.textController,
this.icon,
this.validate,
this.isObsecure = false,
this.focusNode,
this.onFieldSubmitted,
this.inputAction,
this.suffixIcon,
this.maxline = 1,
this.readonly = false,
this.inputFormatters,
this.maxLength,
this.onTap,
});

@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.symmetric(vertical: 8),
child: TextFormField(
onTap: onTap,
autovalidateMode: AutovalidateMode.onUserInteraction,
readOnly: readonly,
controller: textController,
focusNode: focusNode,
style: HelperUtility.textStyle(
color: Colors.black, fontsize: Dimens.font_14),
keyboardType: inputType,
textInputAction: inputAction,
obscureText: isObsecure,
validator: validate,
maxLines: maxline,
inputFormatters: inputFormatters,
onFieldSubmitted: onFieldSubmitted,
maxLength: maxLength,
decoration: new InputDecoration(
counterText: "",
prefixIcon: icon != null
? Container(
padding: EdgeInsets.all(15.0),
height: 15.0,
width: 15.0,
child: Image(
image: AssetImage(icon),
height: 5.0,
width: 5.0,
))
: null,
suffixIcon: suffixIcon != null
? GestureDetector(
onTap: onTapSufix,
child: Container(
padding: EdgeInsets.all(15.0),
height: 15.0,
width: 15.0,
child: Image(
image: AssetImage(suffixIcon),
height: 5.0,
width: 5.0,
)),
)
: null,
contentPadding: EdgeInsets.all(15),
hintText: hint,
hintStyle:
HelperUtility.textStyle(color: Colors.grey, fontsize: 14.0),
border: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.grey.withOpacity(0.5), width: 0),
borderRadius: BorderRadius.circular(Dimens.height_30)),
enabledBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.grey.withOpacity(0.5), width: 0),
borderRadius: BorderRadius.circular(Dimens.height_30)),
focusedBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.grey.withOpacity(0.5), width: 0),
borderRadius: BorderRadius.circular(Dimens.height_30)),
),
),
);
}
}

/*===================================================== Custom Button ==================================================*/

class CustomButton extends StatelessWidget {
final String buttonText;
final String buttonIcon;
final Color textColor;
final Function onPressed;
final double fontsize;
final Color buttonColor;
final bool isIcon;
final double height;
final double width;
final bool isbold;

const CustomButton(
{this.buttonText,
this.textColor = Colors.white,
this.onPressed,
this.fontsize,
this.buttonIcon,
this.height,
this.isbold,
this.width,
this.buttonColor,
this.isIcon});

@override
Widget build(BuildContext context) {
return HelperWidget.getInkwell(
onTap: onPressed,
widget: ClipRRect(
borderRadius: BorderRadius.circular(Dimens.height_30),
child: Container(
height: height,
width: width,
child: ElevatedButton(
onPressed: onPressed,
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(
buttonColor ?? primaryColor),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
isIcon == true
? Row(
children: [
Image.asset(
buttonIcon,
width: Dimens.height_25,
height: Dimens.height_25,
),
HelperWidget.sizeBox(width: Dimens.width_10),
],
)
: Container(),
Text(
buttonText,
style: isbold == true
? HelperUtility.textStyleBold(
color: textColor, fontsize: fontsize)
: HelperUtility.textStyle(
color: textColor, fontsize: fontsize),
)
],
)),
),
));
}
}

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.