我有一个颤振应用程序,我使用屏幕中的文本表单字段捕获数据。我有第二个屏幕,我想在其中显示从第一个屏幕的文本表单字段中捕获的数据。
但首先我想从第二个屏幕控制器将它打印到终端,看看已经通过了什么。我尝试使用 GetX 导航和传递,但出现此错误
The method '[]' was called on null.
Receiver: null
Tried calling: [](0)
这是我用来获取数据作为输入的文本表单字段
TextFormField(
controller: controller._phoneNumberController,
keyboardType: TextInputType.text,
validator: (value) => validatePhoneNumber(value!),
style: TextStyle(
color: accentColor,
fontSize: 15,
fontFamily: 'PoppinsRegular',
),
decoration: InputDecoration(
hintText: "Phone Number",
hintStyle: TextStyle(
fontSize: 14,
color: Colors.black45,
fontWeight: FontWeight.w500),
fillColor: Color(0xffEBEDF4),
filled: true,
border: InputBorder.none,
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide(
color: Color(0xff1D275C),
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide(
color: formFieldColor,
width: 2.0,
),
),
),
),
这是我用来将数据发送到下一页的方法
GestureDetector(
onTap: () {
Get.to(SecondPage(), arguments: [
controller._phoneNumberController.text
]);
},
child: Container(
height: 40,
width: double.infinity,
decoration: BoxDecoration(
color: Color(0xffEF5E41),
),
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Padding(
padding:
const EdgeInsets.only(right: 130),
child: Text(
"Proceed",
style: TextStyle(
color: Color(0xffFCFCFC),
fontSize: 14,
fontWeight: FontWeight.w500,
),
),
),
Padding(
padding:
const EdgeInsets.only(right: 16),
child: Icon(
Icons.arrow_forward_ios,
color: Color(0xffFCFCFC),
),
)
],
),
),
),
),
这是我尝试打印从第一页发送的数据的地方
dynamic argumentData = Get.arguments;
@override
void onInit() {
print(argumentData[0]);
super.onInit();
}
我怎样才能解决这个问题