Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Access values from constructor, from passing data to stateless widget Flutter

here is my code,

class ProfileOthers extends StatefulWidget {
  const ProfileOthers({super.key, required this.data});

  final Map<String, dynamic> data; //I am hoping to make use of this data

  @override
  State<ProfileOthers> createState() => _ProfileOthersState();
}

Want to pass arguments in stateless widget from another screen, I’m new in flutter.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

class UserProfileScreen extends StatefulWidget {
   final Map<String, dynamic> userData;
   const UserProfileScreen ({super.key, required this.userData});

  @override
  State<UserProfileScreen> createState() => _UserProfileScreenState();
}

you can access this parameter as shown below,

Text(widget.userData['name']),
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading