Reputation: 1630
Here I have one signup flow when I filled up all the details of the first page and when I press next it will store into shared preferences and go to the next page. after filling all page and the end of the page I want to print all data using shared preferences in a flutter.
Here is full source code of project where you can get all pages with code, https://github.com/rutvikgumasana/signup
Upvotes: 0
Views: 193
Reputation: 2386
Just pass data in navigation from one class to another class, just have a look at below code I have made some changes
Sign Up Model class
import 'dart:convert';
SignUpModel signUpModelFromJson(String str) => SignUpModel.fromJson(json.decode(str));
String signUpModelToJson(SignUpModel data) => json.encode(data.toJson());
class SignUpModel {
String businessLegalName;
int businessPhoneNo;
int businessYear;
SignUpModel({
this.businessLegalName,
this.businessPhoneNo,
this.businessYear,
});
factory SignUpModel.fromJson(Map<String, dynamic> json) => SignUpModel(
businessLegalName: json["business_legal_name"] == null ? null : json["business_legal_name"],
businessPhoneNo: json["business_phone_no"] == null ? null : json["business_phone_no"],
businessYear: json["business_year"] == null ? null : json["business_year"],
);
Map<String, dynamic> toJson() => {
"business_legal_name": businessLegalName == null ? null : businessLegalName,
"business_phone_no": businessPhoneNo == null ? null : businessPhoneNo,
"business_year": businessYear == null ? null : businessYear,
};
}
changes in BspSignupPage class
SignUpModel model = SignUpModel();
model.businessLegalName = clrbusinessname.text;
model.businessPhoneNo = clrphone.text as int;
model.businessYear = clrestablishedyear.text as int;
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => BspUnlicensedSignupPage(
signUpModel: model,
),
),
);
changes in BspUnlicensedSignupPage
class BspUnlicensedSignupPage extends StatefulWidget {
static const String routeName = "/bspUnlicensedSignup";
final SignUpModel signUpModel;
BspUnlicensedSignupPage({
Key key,
@required this.signUpModel,
}) : super(key: key);
@override
_BspUnlicensedSignupPageState createState() =>
_BspUnlicensedSignupPageState();
}
and in init state method
@override
void initState() {
// TODO: implement initState
super.initState();
debugPrint('Page1 Data: ${widget.signUpModel.businessLegalName}');
}
Upvotes: 1
Reputation: 705
Try This, Create one Object class(POJO Class) and store the data in shared preference, whenever user click next/ submit button. And then, once you reach to final screen get the data from preference and show.
Upvotes: 0
Reputation: 1187
I suggest you should use only one page instead and use PageView
or IndexedStack
for this purpose.
Using IndexedStack
, you can show only one child widget at a time and switch the current index on button click. But in this case you have to create the animation yourself as IndexedStack
don't provide default animation.
If you use PageView
, you have default animation and can also switch it on button click.
It provides you swipe gesture as well which can be disabled using
PageView(physics:new NeverScrollableScrollPhysics())
Upvotes: 0