flutter login
flutterlogin is a ready-made login/signup widget with many animation effects to demonstrate the capabilities of flutter.
installation
follow the install instructions here
reference
property | type | desciption |
---|---|---|
onsignup | authcallback |
called when the user hit the submit button when in sign up mode |
onlogin | authcallback |
called when the user hit the submit button when in login mode |
onrecoverpassword | recovercallback |
called when the user hit the submit button when in recover password mode |
title | string |
the large text above the login [card], usually the app or company name |
logo | string |
the path to the asset image that will be passed to the image.asset() |
messages | loginmessages |
describes all of the labels, text hints, button texts and other auth descriptions |
theme | logintheme |
flutterlogin’s theme. if not specified, it will use the default theme as shown in the demo gifs and use the colorsheme in the closest theme widget |
emailvalidator | formfieldvalidator<string> |
email validating logic, returns an error string to display if the input is invalid, or null otherwise |
passwordvalidator | formfieldvalidator<string> |
same as emailvalidator but for password |
onsubmitanimationcompleted | function |
called after the submit animation’s completed. put your route transition logic here |
logotag | string |
hero tag for logo image. if not specified, it will simply fade out when changing route |
titletag | string |
hero tag for title text. need to specify logintheme.beforeherofontsize and logintheme.afterherofontsize if you want different font size before and after hero animation |
showdebugbuttons | bool |
display the debug buttons to quickly forward/reverse login animations. in release mode, this will be overrided to false regardless of the value passed in |
note: it is recommended that the child widget of the hero
widget should be the
same in both places. for title’s hero animation use the
loginthemehelper.logintextstyle
in the next screen to get the style of the
exact text widget in the login screen. loginthemehelper
can be accessed by adding
this line
import 'package:flutter_login/theme.dart';
loginmessages
property | type | desciption |
---|---|---|
usernamehint | string |
hint text of the user name [textfield] |
passwordhint | string |
hint text of the password [textfield] |
confirmpasswordhint | string |
hint text of the confirm password [textfield] |
forgotpasswordbutton | string |
forgot password button’s label |
loginbutton | string |
login button’s label |
signupbutton | string |
signup button’s label |
recoverpasswordbutton | string |
recover password button’s label |
recoverpassworddescription | string |
description in password recovery form |
gobackbutton | string |
go back button’s label. go back button is used to go back to to login/signup form from the recover password form |
confirmpassworderror | string |
the error message to show when the confirm password not match with the original password |
recoverpasswordsuccess | string |
the success message to show after submitting recover password |
logintheme
property | type | desciption |
---|---|---|
primarycolor | color |
the background color of major parts of the widget like the login screen and buttons |
accentcolor | color |
the secondary color, used for title text color, loading icon, etc. should be contrast with the [primarycolor] |
errorcolor | color |
the color to use for [textfield] input validation errors |
cardtheme | cardtheme |
the colors and styles used to render auth [card] |
inputtheme | inputdecorationtheme |
defines the appearance of all [textfield]s |
buttontheme | loginbuttontheme |
a theme for customizing the shape, elevation, and color of the submit button |
titlestyle | textstyle |
text style for the big title |
bodystyle | textstyle |
text style for small text like the recover password description |
textfieldstyle | textstyle |
text style for [textfield] input text |
buttonstyle | textstyle |
text style for button text |
beforeherofontsize | double |
defines the font size of the title in the login screen (before the hero transition) |
afterherofontsize | double |
defines the font size of the title in the screen after the login screen (after the hero transition) |
examples
you can view the complete example in the [example project] which resulted in the
gif above
basic example
import 'package:flutter/material.dart';
import 'package:flutter_login/flutter_login.dart';
import 'dashboard_screen.dart';
const users = const {
'[email protected]': '12345',
'[email protected]': 'hunter',
};
class loginscreen extends statelesswidget {
duration get logintime => duration(milliseconds: 2250);
future<string> _authuser(logindata data) {
print('name: ${data.name}, password: ${data.password}');
return future.delayed(logintime).then((_) {
if (!users.containskey(data.name)) {
return 'username not exists';
}
if (users[data.name] != data.password) {
return 'password does not match';
}
return null;
});
}
future<string> _recoverpassword(string name) {
print('name: $name');
return future.delayed(logintime).then((_) {
if (!users.containskey(name)) {
return 'username not exists';
}
return null;
});
}
@override
widget build(buildcontext context) {
return flutterlogin(
title: 'ecorp',
logo: 'assets/images/ecorp-lightblue.png',
onlogin: _authuser,
onsignup: _authuser,
onsubmitanimationcompleted: () {
navigator.of(context).pushreplacement(materialpageroute(
builder: (context) => dashboardscreen(),
));
},
onrecoverpassword: _recoverpassword,
);
}
}
theming via themedata
login theme can be customized indectly by using themedata
like this
// main.dart
import 'package:flutter/material.dart';
import 'login_screen.dart';
void main() => runapp(myapp());
class myapp extends statelesswidget {
@override
widget build(buildcontext context) {
return materialapp(
title: 'login demo',
theme: themedata(
primaryswatch: colors.deeppurple,
accentcolor: colors.orange,
cursorcolor: colors.orange,
texttheme: texttheme(
display2: textstyle(
fontfamily: 'opensans',
fontsize: 45.0,
color: colors.orange,
),
button: textstyle(
fontfamily: 'opensans',
),
subhead: textstyle(fontfamily: 'notosans'),
body1: textstyle(fontfamily: 'notosans'),
),
),
home: loginscreen(),
);
}
}
// login_screen.dart
import 'package:flutter/material.dart';
import 'package:flutter_login/flutter_login.dart';
import 'dashboard_screen.dart';
class loginscreen extends statelesswidget {
@override
widget build(buildcontext context) {
return flutterlogin(
title: 'ecorp',
logo: 'assets/images/ecorp.png',
onlogin: (_) => future(null),
onsignup: (_) => future(null),
onsubmitanimationcompleted: () {
navigator.of(context).pushreplacement(materialpageroute(
builder: (context) => dashboardscreen(),
));
},
onrecoverpassword: (_) => future(null),
);
}
}
custom labels
import 'package:flutter/material.dart';
import 'package:flutter_login/flutter_login.dart';
import 'dashboard_screen.dart';
class loginscreen extends statelesswidget {
@override
widget build(buildcontext context) {
return flutterlogin(
title: 'ecorp',
logo: 'assets/images/ecorp.png',
onlogin: (_) => future(null),
onsignup: (_) => future(null),
onsubmitanimationcompleted: () {
navigator.of(context).pushreplacement(materialpageroute(
builder: (context) => dashboardscreen(),
));
},
onrecoverpassword: (_) => future(null),
messages: loginmessages(
usernamehint: 'username',
passwordhint: 'pass',
confirmpasswordhint: 'confirm',
loginbutton: 'log in',
signupbutton: 'register',
forgotpasswordbutton: 'forgot huh?',
recoverpasswordbutton: 'help me',
gobackbutton: 'go back',
confirmpassworderror: 'not match!',
recoverpassworddescription:
'lorem ipsum is simply dummy text of the printing and typesetting industry',
recoverpasswordsuccess: 'password rescued successfully',
),
);
}
}
login/signup | password recovery |
---|---|
theme customization
import 'package:flutter/material.dart';
import 'package:flutter_login/flutter_login.dart';
import 'dashboard_screen.dart';
class loginscreen extends statelesswidget {
@override
widget build(buildcontext context) {
final inputborder = borderradius.vertical(
bottom: radius.circular(10.0),
top: radius.circular(20.0),
);
return flutterlogin(
title: 'ecorp',
logo: 'assets/images/ecorp-lightgreen.png',
onlogin: (_) => future(null),
onsignup: (_) => future(null),
onsubmitanimationcompleted: () {
navigator.of(context).pushreplacement(materialpageroute(
builder: (context) => dashboardscreen(),
));
},
onrecoverpassword: (_) => future(null),
theme: logintheme(
primarycolor: colors.teal,
accentcolor: colors.yellow,
errorcolor: colors.deeporange,
titlestyle: textstyle(
color: colors.greenaccent,
fontfamily: 'quicksand',
letterspacing: 4,
),
bodystyle: textstyle(
fontstyle: fontstyle.italic,
decoration: textdecoration.underline,
),
textfieldstyle: textstyle(
color: colors.orange,
shadows: [shadow(color: colors.yellow, blurradius: 2)],
),
buttonstyle: textstyle(
fontweight: fontweight.w800,
color: colors.yellow,
),
cardtheme: cardtheme(
color: colors.yellow.shade100,
elevation: 5,
margin: edgeinsets.only(top: 15),
shape: continuousrectangleborder(
borderradius: borderradius.circular(100.0)),
),
inputtheme: inputdecorationtheme(
filled: true,
fillcolor: colors.purple.withopacity(.1),
contentpadding: edgeinsets.zero,
errorstyle: textstyle(
backgroundcolor: colors.orange,
color: colors.white,
),
labelstyle: textstyle(fontsize: 12),
enabledborder: underlineinputborder(
borderside: borderside(color: colors.blue.shade700, width: 4),
borderradius: inputborder,
),
focusedborder: underlineinputborder(
borderside: borderside(color: colors.blue.shade400, width: 5),
borderradius: inputborder,
),
errorborder: underlineinputborder(
borderside: borderside(color: colors.red.shade700, width: 7),
borderradius: inputborder,
),
focusederrorborder: underlineinputborder(
borderside: borderside(color: colors.red.shade400, width: 8),
borderradius: inputborder,
),
disabledborder: underlineinputborder(
borderside: borderside(color: colors.grey, width: 5),
borderradius: inputborder,
),
),
buttontheme: loginbuttontheme(
splashcolor: colors.purple,
backgroundcolor: colors.pinkaccent,
highlightcolor: colors.lightgreen,
elevation: 9.0,
highlightelevation: 6.0,
shape: beveledrectangleborder(
borderradius: borderradius.circular(10),
),
// shape: roundedrectangleborder(borderradius: borderradius.circular(5)),
// shape: circleborder(side: borderside(color: colors.green)),
// shape: continuousrectangleborder(borderradius: borderradius.circular(55.0)),
),
),
);
}
}
Comments are closed.