Mobile_App_Development_Practicals
Mobile_App_Development_Practicals
This app demonstrates basic Flutter widgets such as Text, Image, TextField, and ElevatedButton.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
import 'package:flutter/material.dart';
void main() {
runApp(FormApp());
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Interactive Form')),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Form(
key: _formKey,
child: Column(
children: [
TextFormField(
decoration: InputDecoration(labelText: 'Email'),
validator: (value) => value == null || !value.contains('@') ? 'Enter a
valid email' : null,
onSaved: (value) => email = value!,
),
SizedBox(height: 16),
TextFormField(
decoration: InputDecoration(labelText: 'Password'),
obscureText: true,
validator: (value) => value!.length < 6 ? 'Password must be at least 6
characters' : null,
onSaved: (value) => password = value!,
),
SizedBox(height: 16),
ElevatedButton(
child: Text('Submit'),
onPressed: () {
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
print('Email: $email, Password: $password');
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content:
Text('Form submitted')));
}
},
),
],
),
),
),
);
}
}