UserController
import 'package:get/get.dart';
class UserController extends GetxController {
var name = 'John Doe'.obs;
var email = 'john@example.com'.obs;
var age = 30.obs;
}
view screen
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class UserForm extends StatelessWidget {
final UserController userController = Get.put(UserController());
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('User Information'),
),
body: Padding(
padding: EdgeInsets.all(16.0),
child: Form(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Obx(
() => TextFormField(
initialValue: userController.name.value,
decoration: InputDecoration(labelText: 'Name'),
readOnly: true,
// You can add validation logic or change handlers here
),
),
Obx(
() => TextFormField(
initialValue: userController.email.value,
decoration: InputDecoration(labelText: 'Email'),
readOnly: true,
// You can add validation logic or change handlers here
),
),
Obx(
() => TextFormField(
initialValue: userController.age.value.toString(),
decoration: InputDecoration(labelText: 'Age'),
readOnly: true,
keyboardType: TextInputType.number,
// You can add validation logic or change handlers here
),
),
// Add more form fields as needed
],
),
),
),
);
}
}