Code :
xxxxxxxxxx
import 'package:flutter/material.dart';
​
void main() {
runApp(MaterialApp(
home: RegisterForm(),
));
}
​
class RegisterForm extends StatefulWidget {
RegisterForm({Key? key}) : super(key: key);
​
@override
State<RegisterForm> createState() => _RegisterFormState();
}
​
class _RegisterFormState extends State<RegisterForm> {
List<String> gender = ["Male", "Female", "Gay"];
String genderSelected = "Male";
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: buildForm(),
));
}
​
Container buildForm() {
return Container(
width: MediaQuery.of(context).size.width * 0.9,
height: MediaQuery.of(context).size.height * 0.5,
decoration: BoxDecoration(
color: const Color.fromARGB(255, 196, 190, 190),
borderRadius: BorderRadius.circular(15)),
child: Padding(
padding: const EdgeInsets.all(40),
child: Column(
children: [
const Text(
"Register Form",
style: TextStyle(
color: Colors.lightBlue, fontWeight: FontWeight.bold),
),
TextFormField(
keyboardType: TextInputType.emailAddress,
decoration: const InputDecoration(hintText: "Email"),
),
buildGender(),
TextFormField(
keyboardType: TextInputType.text,
obscureText: true,
decoration: const InputDecoration(hintText: "Password"),
),
const SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () => {},
child: const Text(
"Register",
style: TextStyle(color: Colors.white),
)),
const SizedBox(
width: 10,
),
ElevatedButton(
onPressed: () => {},
child: const Text(
"Cancel",
style: TextStyle(color: Color.fromARGB(255, 238, 34, 34)),
)),
],
)
],
),
),
);
}
​
DropdownButton buildGender() {
return DropdownButton(
value: genderSelected,
items: gender.map((item) {
return DropdownMenuItem(
child: Text(item),
value: item,
);
}).toList(),
onChanged: (getItem) {
setState(() {
genderSelected = getItem;
});
});
}
}
​