Berikut Codinganya :
import 'package:flutter/material.dart';
class Biodata {
String name;
String address;
String dateOfBirth;
String education;
String workExperience;
Biodata({
required this.name,
required this.address,
required this.dateOfBirth,
required this.education,
required this.workExperience,
});
}
class BiodataApp extends StatefulWidget {
@override
_BiodataAppState createState() => _BiodataAppState();
}
class _BiodataAppState extends State<BiodataApp> {
final TextEditingController nameController = TextEditingController();
final TextEditingController addressController = TextEditingController();
final TextEditingController dateOfBirthController = TextEditingController();
final TextEditingController educationController = TextEditingController();
final TextEditingController workExperienceController =
TextEditingController();
Biodata? biodata;
void saveBiodata() {
setState(() {
biodata = Biodata(
name: nameController.text,
address: addressController.text,
dateOfBirth: dateOfBirthController.text,
education: educationController.text,
workExperience: workExperienceController.text,
);
});
}
void clearFields() {
nameController.clear();
addressController.clear();
dateOfBirthController.clear();
educationController.clear();
workExperienceController.clear();
setState(() {
biodata = null;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Biodata App',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
title: Text('Biodata App'),
),
body: SingleChildScrollView(
padding: EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Fill in the Biodata:',
style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold),
),
SizedBox(height: 16.0),
TextField(
controller: nameController,
decoration: InputDecoration(labelText: 'Name'),
),
TextField(
controller: addressController,
decoration: InputDecoration(labelText: 'Address'),
),
TextField(
controller: dateOfBirthController,
decoration: InputDecoration(labelText: 'Date of Birth'),
),
TextField(
controller: educationController,
decoration: InputDecoration(labelText: 'Education'),
),
TextField(
controller: workExperienceController,
decoration: InputDecoration(labelText: 'Work Experience'),
),
SizedBox(height: 16.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: saveBiodata,
child: Text('Save'),
),
SizedBox(width: 16.0),
ElevatedButton(
onPressed: clearFields,
child: Text('Clear'),
),
],
),
SizedBox(height: 16.0),
if (biodata != null) ...[
Text(
'Biodata:',
style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold),
),
SizedBox(height: 8.0),
Text('Name: ${biodata!.name}'),
Text('Address: ${biodata!.address}'),
Text('Date of Birth: ${biodata!.dateOfBirth}'),
Text('Education: ${biodata!.education}'),
Text('Work Experience: ${biodata!.workExperience}'),
],
],
),
),
),
);
}
}
void main() {
runApp(BiodataApp());
}
Berikut Hasilnya :