Sign Up Form (Error)
main.dart
import 'package:flutter/material.dart';
import 'SignUpPage.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'User Details',
debugShowCheckedModeBanner: false,
theme: ThemeData.dark(),
home: SignUpPage(),
);
}
}
SignUpPage.dart
Error in strings and input
import 'package:flutter/material.dart';
import 'HomePage.dart';
import 'https://flutlab.io/root/app/lib/HomePage.dart';
class SignUpPage extends StatefulWidget {
const SignUpPage({Key? key}) : super(key: key);
_SignUpPageState createState() => _SignUpPageState();
}
class _SignUpPageState extends State<SignUpPage> {
GlobalKey<FormState> _key = new GlobalKey();
String name, email, mobile, collegename;
// String name = "", email = "", mobile = "", collegename = "";
bool _autovalidate = false;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.orange,
appBar: AppBar(
title: Text('SignUp'),
),
body: SingleChildScrollView(
child: Form(
key: _key,
child: Card(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.0)),
child: Column(
children: [
Padding(
padding: EdgeInsets.all(10.0),
),
Image(
image: AssetImage('images/logo.png'),
width: 100.0,
height: 100.0,
),
ListTile(
leading: Icon(Icons.person),
title: TextFormField(
validator: (input) {
if (input == null || input.isEmpty) {
return "Enter Name";
}
return null;
},
decoration: InputDecoration(labelText: 'Name'),
onSaved: (input) => name = input,
),
),
ListTile(
leading: Icon(Icons.email),
title: TextFormField(
validator: (input) {
if (input == null || input.isEmpty) {
return "Enter Email";
}
return null;
},
decoration: InputDecoration(labelText: 'E-mail'),
onSaved: (input) => email = input,
),
),
ListTile(
leading: Icon(Icons.phone),
title: TextFormField(
validator: (input) {
if (input == null || input.isEmpty) {
return "Enter Number";
}
return null;
},
decoration: InputDecoration(labelText: 'Phone'),
onSaved: (input) => mobile = input,
),
),
ListTile(
leading: Icon(Icons.school),
title: TextFormField(
validator: (input) {
if (input == null || input.isEmpty) {
return "Enter College Name";
}
return null;
},
decoration: InputDecoration(labelText: 'College Name'),
onSaved: (input) => collegename = input,
),
),
Padding(
padding: EdgeInsets.all(10.0),
),
ButtonTheme(
height: 40.0,
minWidth: 200.0,
child: RaisedButton(
onPressed: _sendtoNextScreen,
color: Colors.redAccent,
child: Text(
"Save",
style: TextStyle(
color: Colors.white,
),
),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
),
),
Padding(
padding: EdgeInsets.all(10.0),
),
],
),
),
),
),
);
}
_sendtoNextScreen() {
if (_key.currentState.validate()) {
_key.currentState.save();
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HomePage(
name: name,
email: email,
mobile: mobile,
collegename: collegename,
),
),
);
} else {
setState(() {
_autovalidate = true;
});
}
}
}
HomePage.dart
import 'package:flutter/material.dart';
class HomePage extends StatelessWidget {
final String name, email, mobile, collegename;
//const HomePage({Key? key}) : super(key: key);
HomePage({
Key? key,
required this.name,
required this.email,
required this.mobile,
required this.collegename,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.orange,
appBar: AppBar(
title: Text('Student Information'),
),
body: Form(
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.all(50.0),
),
Image(
image: AssetImage('images/logo.png'),
width: 100.0,
height: 100.0,
),
ListTile(
leading: Icon(Icons.people),
title: Text(name),
),
Image(
image: AssetImage('images/logo.png'),
width: 100.0,
height: 100.0,
),
ListTile(
leading: Icon(Icons.people),
title: Text(name),
),
],
),
),
),
);
}
}
Comments
Post a Comment