Flutter - How to pass user data to all views

前端 未结 5 626
醉酒成梦
醉酒成梦 2021-01-30 03:10

I\'m new to the flutter world and mobile app development and struggling with how I should pass user data throughout my app.

I\'ve tried several things, but none seem gre

5条回答
  •  盖世英雄少女心
    2021-01-30 03:52

    For my lazy mathod, i just create new file like userdata.dart and then put any variable on it for example like dynamic Profile = null

    inside userdata.dart

    //only put this or anything u want.
    dynamic Profile = null;
    

    at startingpage.dart

    //import that file
    import '../userdata.dart';
    
    class startingpage extends ...{
    ...
    //set data to store..
       Profile = 'user profile';
    ...
    }
    

    to use the data just declare and use in anotherpage.dart

    //import that file
    import '../userdata.dart';
    
    class anotherpage extends...{
    ...
    }
    
    class .. State ...{
    ...
    //set the data to variable
       dynamic userdata = Profile;
       print('this is my lazy pass data' + userdata.toString());
    ...
    }
    

提交回复
热议问题