Syntax formatting

This commit is contained in:
Phani Pavan K
2023-04-05 19:29:24 +05:30
parent a8ece76392
commit 84b8a51cb0

View File

@@ -57,7 +57,7 @@ class _MyAppState extends State<MyApp> {
class LoginPage extends StatefulWidget { class LoginPage extends StatefulWidget {
final VoidCallback _onSignIn; final VoidCallback _onSignIn;
LoginPage({required onSignIn}) const LoginPage({required onSignIn})
: assert(onSignIn != null), : assert(onSignIn != null),
_onSignIn = onSignIn; _onSignIn = onSignIn;
@@ -115,7 +115,7 @@ class _LoginPageState extends State<LoginPage> {
_loginFormKey.currentState!.save(); _loginFormKey.currentState!.save();
// dismiss keyboard during async call // dismiss keyboard during async call
FocusScope.of(context).requestFocus(new FocusNode()); FocusScope.of(context).requestFocus(FocusNode());
// start the modal progress HUD // start the modal progress HUD
setState(() { setState(() {
@@ -123,7 +123,7 @@ class _LoginPageState extends State<LoginPage> {
}); });
// Simulate a service call // Simulate a service call
Future.delayed(Duration(seconds: 1), () { Future.delayed(const Duration(seconds: 1), () {
final _accountUsername = 'username1'; final _accountUsername = 'username1';
final _accountPassword = 'password1'; final _accountPassword = 'password1';
_isLoggedIn = false; _isLoggedIn = false;
@@ -134,9 +134,10 @@ class _LoginPageState extends State<LoginPage> {
// username and password are correct // username and password are correct
_isInvalidAsyncPass = false; _isInvalidAsyncPass = false;
_isLoggedIn = true; _isLoggedIn = true;
} else } else {
// username is correct, but password is incorrect // username is correct, but password is incorrect
_isInvalidAsyncPass = true; _isInvalidAsyncPass = true;
}
} else { } else {
// incorrect username and have not checked password result // incorrect username and have not checked password result
_isInvalidAsyncUser = true; _isInvalidAsyncUser = true;
@@ -146,9 +147,10 @@ class _LoginPageState extends State<LoginPage> {
// stop the modal progress HUD // stop the modal progress HUD
_isInAsyncCall = false; _isInAsyncCall = false;
}); });
if (_isLoggedIn) if (_isLoggedIn) {
// do something // do something
widget._onSignIn(); widget._onSignIn();
}
}); });
} }
} }
@@ -157,23 +159,23 @@ class _LoginPageState extends State<LoginPage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text('Modal Progress HUD Demo'), title: const Text('Modal Progress HUD Demo'),
backgroundColor: Colors.blue, backgroundColor: Colors.blue,
), ),
// display modal progress HUD (heads-up display, or indicator) // display modal progress HUD (heads-up display, or indicator)
// when in async call // when in async call
body: ModalProgressHUD( body: ModalProgressHUD(
inAsyncCall: _isInAsyncCall,
// demo of some additional parameters
opacity: 0.5,
blur: bur,
progressIndicator: const CircularProgressIndicator(),
child: SingleChildScrollView( child: SingleChildScrollView(
child: Container( child: Container(
padding: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(16.0),
child: buildLoginForm(context), child: buildLoginForm(context),
), ),
), ),
inAsyncCall: _isInAsyncCall,
// demo of some additional parameters
opacity: 0.5,
blur: bur,
progressIndicator: CircularProgressIndicator(),
), ),
); );
} }
@@ -183,16 +185,17 @@ class _LoginPageState extends State<LoginPage> {
// run the validators on reload to process async results // run the validators on reload to process async results
_loginFormKey.currentState?.validate(); _loginFormKey.currentState?.validate();
return Form( return Form(
key: this._loginFormKey, key: _loginFormKey,
child: Column( child: Column(
children: [ children: [
Padding( Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: TextFormField( child: TextFormField(
key: Key('username'), key: const Key('username'),
decoration: InputDecoration( decoration: const InputDecoration(
hintText: 'enter username', labelText: 'User Name'), hintText: 'enter username', labelText: 'User Name'),
style: TextStyle(fontSize: 20.0, color: textTheme.button!.color), style:
TextStyle(fontSize: 20.0, color: textTheme.labelLarge!.color),
validator: _validateUserName, validator: _validateUserName,
onSaved: (value) => _username = value, onSaved: (value) => _username = value,
), ),
@@ -200,11 +203,12 @@ class _LoginPageState extends State<LoginPage> {
Padding( Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: TextFormField( child: TextFormField(
key: Key('password'), key: const Key('password'),
obscureText: true, obscureText: true,
decoration: InputDecoration( decoration: const InputDecoration(
hintText: 'enter password', labelText: 'Password'), hintText: 'enter password', labelText: 'Password'),
style: TextStyle(fontSize: 20.0, color: textTheme.button!.color), style:
TextStyle(fontSize: 20.0, color: textTheme.labelLarge!.color),
validator: _validatePassword, validator: _validatePassword,
onSaved: (value) => _password = value, onSaved: (value) => _password = value,
), ),
@@ -213,25 +217,25 @@ class _LoginPageState extends State<LoginPage> {
padding: const EdgeInsets.all(32.0), padding: const EdgeInsets.all(32.0),
child: ElevatedButton( child: ElevatedButton(
onPressed: _submit, onPressed: _submit,
child: Text('Login'), child: const Text('Login'),
), ),
), ),
Padding( Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: _isLoggedIn child: _isLoggedIn
? Text( ? const Text(
'Login successful!', 'Login successful!',
key: Key('loggedIn'), key: Key('loggedIn'),
style: TextStyle(fontSize: 20.0), style: TextStyle(fontSize: 20.0),
) )
: Text( : const Text(
'Not logged in', 'Not logged in',
key: Key('notLoggedIn'), key: Key('notLoggedIn'),
style: TextStyle(fontSize: 20.0), style: TextStyle(fontSize: 20.0),
), ),
), ),
Divider(), const Divider(),
Text("Set amount of blur:", style: TextStyle(fontSize: 20)), const Text("Set amount of blur:", style: TextStyle(fontSize: 20)),
Slider( Slider(
min: 0, min: 0,
max: 10, max: 10,