Flutter – ‘initialValue == null || controller == null’: is not true. error
Posted by
Dharmendra Kumar, Senior Software Engineer & Co founder at MyhospitalNow
–
Error:
The relevant error-causing widget was:
PaypalPaymentPage PaypalPaymentPage:file:///C:/Users/dharm/AndroidStudioProjects/mhn_app_doctor/lib/pages/doctor_profile_page.dart:495:33
When the exception was thrown, this was the stack:
#2 new TextFormField (package:flutter/src/material/text_form_field.dart:176:15)
text_form_field.dart:176
#3 _PaypalPaymentPageState.build (package:my_hospital_now_doctor/pages/paypal_payment.dart:157:19)
Solution:
To fix this, follow these steps:
Remove initialValue when you’re using a controller.
If you’re using controller, only rely on that and don’t set initialValue.
If you want to display the value without editing it, use initialValue and remove the controller.
Hereās the corrected code:
Dharmendra Kumar, Senior Software Engineer & Co founder at MyhospitalNow
Experienced software developer proficient in HTML, CSS, and Bootstrap for crafting elegant and responsive user interfaces.
Skilled in Laravel and PHP, with a focus on building robust and scalable web applications.
Proficient in JavaScript for both frontend and backend development, leveraging frameworks like React and Vue.js.
Experienced in designing and consuming RESTful APIs to enable seamless communication between client and server.
Expertise in integrating payment gateways such as PayPal, Stripe, and Paytm for secure online transactions.
Familiar with Flutter, enabling the creation of natively compiled applications for mobile, web, and desktop.
Proficient in Android Studio, the primary IDE for developing Android applications.
Knowledgeable in Linux and Docker for efficient server management and application deployment.
Experienced in using Redis as an in-memory data structure store, enhancing application performance.
Passionate about staying updated with the latest technologies and continuously learning to deliver high-quality solutions.