Comments (3)
I matched your code with mine, they both are same, It ran on my system and worked well.
you should save the file and try to reopen on vscode and run the app,
it may work,
if not then you should create new project and paste all code in that project and try it there
from 30daysofflutter.
i will make sure it will work
validator: (String? value) {
if (value == null || value.isEmpty) {
return "Please enter some text";
}
return null;
},
from 30daysofflutter.
Fixed the form validation issue, have a look at my code
import 'package:flutter/material.dart';
import 'routes.dart';
class LoginPage extends StatefulWidget {
const LoginPage({Key? key}) : super(key: key);
@override
State<LoginPage> createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
bool buttonChanged = false;
String name = "";
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Material(
color: Colors.grey[500],
child: Form(
key: _formKey,
child: Column(
children: [
const CircleAvatar(backgroundImage: AssetImage('images/login.jpg')),
const SizedBox(height: 15.0),
Text('Welcome $name',
style: const TextStyle(
fontSize: 24.0, fontWeight: FontWeight.bold)),
const SizedBox(height: 15.0),
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 15, vertical: 32),
child: Column(
children: [
TextFormField(
decoration: const InputDecoration(
hintText: 'Enter the username',
labelText: 'UserName:'),
onChanged: (value) {
name = value;
setState(() {});
},
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter the username';
}
return null;
},
),
TextFormField(
obscureText: true,
decoration: const InputDecoration(
hintText: 'Enter the password',
labelText: 'Password:'),
validator: (value) {
if (value == null || value.isEmpty) {
return "Please enter password";
} else if (value.isNotEmpty && value.length < 6) {
return "Password must be at least 6 characters";
} else if (value.isNotEmpty && value.length > 12) {
return "Password must be less than 12 characters";
}
return null;
},
),
const SizedBox(height: 15.0),
Material(
borderRadius:
BorderRadius.circular(buttonChanged ? 50.0 : 10.0),
color: Colors.blue,
child: InkWell(
splashColor: Colors.grey[7],
onTap: () => moveToHome(context),
child: AnimatedContainer(
duration: const Duration(seconds: 1),
width: buttonChanged ? 50 : 130,
height: 50,
alignment: Alignment.center,
child: buttonChanged
? const Icon(Icons.done)
: const Text(
'Login',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 16),
),
),
))
],
))
],
),
),
);
}
moveToHome(BuildContext context) async {
if (_formKey.currentState!.validate()) {
setState(() {
buttonChanged = true;
}
);
await Future.delayed(const Duration(seconds: 1));
await Navigator.pushNamed(context, route.home);
setState(() {
buttonChanged = false;
});
}
else{
setState(() {
buttonChanged = false;
});
}
}
}
from 30daysofflutter.
Related Issues (20)
- Not an issue but an appreciation ❤
- Amazing tutorial series!!
- ฺิHow can I use it with a quick F-key?
- ISSUE IN "VxState.listen" HOT 1
- Error unexpected null value HOT 1
- Question
- The non-nullable variable 'items' must be initialized. Try adding an initializer expression. HOT 5
- Day 17
- if we have list of two pages then add to favorite not working
- Catalog Shop
- The left operand can't be null
- Encountered some issues HOT 1
- Issues with VxBuilder HOT 3
- Error: Field 'catalog' should be initialized because its type 'CatalogModels' doesn't allow null.
- items are not removing from cart
- ERROR in Chapter 27: Unhandled Exception: type 'Null' is not a subtype of type 'Iterable<dynamic>' HOT 1
- Error in `day8` code HOT 4
- Day 12 : I'm not able to scroll down in the catalog app when we are adding 50 items
- Error: Expected a value of type 'String', but got one of type 'Null' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from 30daysofflutter.