Home > Software design >  Passing values between widgets
Passing values between widgets

Time:05-04

I am trying to achieve a sign-up screen that is splinted between 7 screens, each screen should take single input. I tried passing around arguments to my page rout, but I feel not good for that, since I don't need it until the last screen where I make a server request. I don't know how should I do that. I tried with provider but i could not achieve a code with no errors I tried to create an instance of a provider class witch tack nullable parameters and then call it in the widget that should tack input and set the values to it, but I faced many errors. Any advice.

import 'package:flutter/cupertino.dart';

class UserSignUpModel with ChangeNotifier {
  final String? fName;
  final String? lName;
  final String? gender;

  UserSignUpModel(
      {
      this.fName,
      this.lName,
      this.gender,
      });
  var user = new UserSignUpModel();
}

CodePudding user response:

I think you should make this field static and then assign the values one by one to this UserSignUpModel. Like in the first page you can only take name and directly assign it to UserSignUpModel.name. Your UserSignUpModel would look like bellow

class UserSignUpModel {
  static String? fName;
  static String? lName;
  static String? gender;
}

CodePudding user response:

it was very easy to do

class UserSignUpModel with ChangeNotifier {
  String? fName;
  String? lName;
  String? gender;
  String? userLookingfor;
  String? userType;
  String? userTagLine;
  String? userEmail;
  String? userPhoneCode;
  String? userEmailCode;
  String? userPassword;
  String? age;
  void createUserName(String valFNmae, String valLname) {
    fName = valFNmae;
    lName = valLname;
  }

and in the other widget

final helper = Provider.of<UserSignUpModel>(context, listen: false);
    helper.createUserName(
        _firstNameController.value.text, _lastNameController.value.text);
  • Related