I am very new to Dart, and coding in general. I have produced this code after watching tutorials on YouTube. For the most part, I have been able to troubleshoot most of my problems on my own, yet I cannot figure out my most recent errors. Here I made a TextEditingController on a page(Which worked fine BTW), and later I shifted to another page to make the code clean. But they stopped working.
import 'package:care_ls/model/userProfileModel.dart';
import 'package:care_ls/services/database.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:care_ls/views/views.dart';
import 'package:care_ls/controllers/controllers.dart';
class ProfilePage extends StatelessWidget {
const ProfilePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(
children: [
TextFormField(
controller: profilePageTextControllers().fnameController,
onChanged: (e)=> print(e),
obscureText: false,
decoration: const InputDecoration(
hintText: 'First Name',
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Color(0xff2AA8A1),
width: 1,
),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4.0),
topRight: Radius.circular(4.0),
),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Color(0xff272361),
width: 1,
),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4.0),
topRight: Radius.circular(4.0),
),
),
),
//style: FlutterFlowTheme.of(context).bodyText1,
),
TextFormField(
controller: profilePageTextControllers().lnameController,
obscureText: false,
decoration: const InputDecoration(
hintText: 'Second Name',
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Color(0xff2AA8A1),
width: 1,
),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4.0),
topRight: Radius.circular(4.0),
),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Color(0xff272361),
width: 1,
),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4.0),
topRight: Radius.circular(4.0),
),
),
),
//style: FlutterFlowTheme.of(context).bodyText1,
),
ElevatedButton(
onPressed: () async {
final userprofile = UserProfileModel(
firstName: profilePageTextControllers().fnameController.text.trim(),
lastName: profilePageTextControllers().lnameController.text.trim(),
);
await Database.addProfile(userprofile);
profilePageTextControllers().fnameController.clear();
profilePageTextControllers().lnameController.clear();
print('Data Sent');
},
child: Text('Done')),
ElevatedButton(
onPressed: () => Get.to(HomePage()), child: Text('Back')),
],
),
),
);
}
}
Here is My controller that I move to another file
import 'package:flutter/material.dart';
class profilePageTextControllers {
TextEditingController fnameController = TextEditingController();
TextEditingController lnameController = TextEditingController();
}
Can anyone help me in understanding what I did wrong?