import 'package:flutter/material.dart';
class Test extends StatelessWidget {
final controller;
final String hintText;
final bool obscureText;
const Test({
Key? key,
required controller,
required this.hintText,
required this.obscureText,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final formFieldKey = GlobalKey<FormFieldState<String>>();
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 25.0),
child: Column(
children: [
TextFormField(
key: formFieldKey,
controller: controller,
obscureText: obscureText,
decoration: InputDecoration(
enabledBorder: const OutlineInputBorder(
borderSide: BorderSide(color: Colors.orange),
),
focusedBorder: const OutlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
fillColor: Colors.red,
filled: true,
labelText: hintText,
// Add any other desired properties
),
validator: (value) {
if (value == null || value.isEmpty) {
return 'This field is required';
}
return null;
},
),
ElevatedButton(
onPressed: () {
// Validate the field
formFieldKey.currentState?.validate();
},
child: const Text('Submit'),
),
],
),
);
}
}
I am trying to use controller member but can't, I'll try , var , text editingcontroller but still facing same error,
One most , I don't know why my complier not avoiding this type of error to execute my code , Thanks, hope you answer me as soon as possible.
You did not specify the
controllertype asTextEditingControllerand you defined it incorrectly in the constructor method.