0% found this document useful (0 votes)
16 views4 pages

Main Runapp: 'Package:Flutter/Material - Dart'

The document defines a Flutter app that displays a student form with text fields for name, address, number, age, and year. It uses controllers to manage the text fields and navigates to an output page on submit to display the entered values.

Uploaded by

Vladimir Rustia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

Main Runapp: 'Package:Flutter/Material - Dart'

The document defines a Flutter app that displays a student form with text fields for name, address, number, age, and year. It uses controllers to manage the text fields and navigates to an output page on submit to display the entered values.

Uploaded by

Vladimir Rustia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

import 'package:flutter/material.

dart';

void main() {
runApp(MaterialApp(
home: MyApp(),
));
}

class MyApp extends StatelessWidget {


TextEditingController nameController = TextEditingController();
TextEditingController addressController = TextEditingController();
TextEditingController numberController = TextEditingController();
TextEditingController ageController = TextEditingController();
TextEditingController yearController = TextEditingController();

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Student Form'),
),
body: ListView(
padding: EdgeInsets.all(16.0),
children: <Widget>[
_buildTextField(
controller: nameController,
label: 'Name',
hint: 'Enter your name',
),
SizedBox(height: 10),
_buildTextField(
controller: addressController,
label: 'Address',
hint: 'Enter your address',
),
SizedBox(height: 10),
_buildTextField(
controller: numberController,
label: 'Number',
hint: 'Enter your phone number',
),
SizedBox(height: 10),
_buildTextField(
controller: ageController,
label: 'Age',
hint: 'Enter your age',
),
SizedBox(height: 10),
_buildTextField(
controller: yearController,
label: 'Year',
hint: 'Enter your academic year',
),
SizedBox(height: 20),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => OutputPage(
name: nameController.text,
address: addressController.text,
number: numberController.text,
age: ageController.text,
year: yearController.text,
),
),
);
},
style: ElevatedButton.styleFrom(
primary: Colors.blue,
onPrimary: Colors.white,
),
child: Text('Submit'),
),
],
),
);
}

Widget _buildTextField({
required TextEditingController controller,
required String label,
required String hint,
}) {
return TextFormField(
controller: controller,
decoration: InputDecoration(
labelText: label,
hintText: hint,
border: OutlineInputBorder(),
),
);
}
}

class OutputPage extends StatelessWidget {


final String name;
final String address;
final String number;
final String age;
final String year;

OutputPage({
required this.name,
required this.address,
required this.number,
required this.age,
required this.year,
});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Output Page'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Name: $name',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
SizedBox(height: 10),
Text(
'Address: $address',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
SizedBox(height: 10),
Text(
'Number: $number',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
SizedBox(height: 10),
Text(
'Age: $age',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
SizedBox(height: 10),
Text(
'Year: $year',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
],
),
),
);
}
}

You might also like