Hi i was experienced ionic developer but i am new to flutter i was trying to pass data between screens in flutter but when it navigates it shows null value , in debug mode before navigate there is values after navigate it shows null , here is my code please correct my code thanks.
Screen 1
import 'package:flutter/material.dart';
import 'package:date_field/date_field.dart';
import 'package:headletter/screens/Add_horoscope/marriage_info.dart';
class AddBasicInfo extends StatefulWidget {
const AddBasicInfo({Key? key}) : super(key: key);
@override
_AddBasicInfoState createState() => _AddBasicInfoState();
}
class _AddBasicInfoState extends State<AddBasicInfo>{
@override
void initState() {
super.initState();
}
Widget build(BuildContext context) {
return MaterialApp()....
bottomNavigationBar: BottomAppBar(
child: GestureDetector(
onTap: (){
final data1 = [
{
"Name": inputName.text,
"Gender": _selectedGender,
"DOB":dobDate,
"DobTime":dobTime,
"Place": birthPlace.text,
"Landmark": landmark.text,
"birthNo": _selectedChild
}
];
final String passingValue = "checking for passing";
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
MarriageInfo(passingValue: passingValue)),
);
}
}
},
Screen 2
class MarriageInfo extends StatefulWidget {
final String passingValue;
const MarriageInfo({Key? key, required this.passingValue}) : super(key: key);
@override
_MarriageInfoState createState() => _MarriageInfoState();
}
CodePudding user response:
Far now this is correct but while using passingValue
on Screen2 you have to use widget.passingValue
e.g. print(widget.passingValue);
CodePudding user response:
you are using statefulwidget
You can describe constructor of statefullwidget like that
final String passingValue;
const MarriageInfo(this.number);
and than you can excess this value by
widget.passingValue
CodePudding user response:
You should use widget.passingValue instead of just that variable name. The property is assigned to that widget, not to that state class.