Problem with local variable - Global variable flutter dart2019 Community Moderator ElectionFlutter - How to pass user data to all viewsDart / flutter: Navigator.push - no such method errorAccessing the route's transition animation from a widget?Fully restart(discard and recreate) the whole flutter app programmaticallyFlutter - Setting the body of a ScaffoldFlutter BottomNavigationBar and advanced navigationtype 'Future<int>' is not a subtype of type 'int' with FlutterAsync function not being called on page creationHow to pass specific ListTile variables to new page route onTap?Flutter how to change the parent BottomNavigationBar index from a child widget

Are there other languages, besides English, where the indefinite (or definite) article varies based on sound?

Is it true that good novels will automatically sell themselves on Amazon (and so on) and there is no need for one to waste time promoting?

Are ETF trackers fundamentally better than individual stocks?

Why did it take so long to abandon sail after steamships were demonstrated?

What are the naunces between the use of 訊く instead of 聞く in the following sentence?

PTIJ: Who should I vote for? (21st Knesset Edition)

Life insurance that covers only simultaneous/dual deaths

Most cost effective thermostat setting: consistent temperature vs. lowest temperature possible

how to write formula in word in latex

Recruiter wants very extensive technical details about all of my previous work

Min function accepting varying number of arguments in C++17

Sailing the cryptic seas

A Cautionary Suggestion

Brexit - No Deal Rejection

Can a druid choose the size of its wild shape beast?

Is it normal that my co-workers at a fitness company criticize my food choices?

Are there verbs that are neither telic, or atelic?

How do anti-virus programs start at Windows boot?

Gantt Chart like rectangles with log scale

What approach do we need to follow for projects without a test environment?

What options are left, if Britain cannot decide?

Do the common programs (for example: "ls", "cat") in Linux and BSD come from the same source code?

If curse and magic is two sides of the same coin, why the former is forbidden?

Official degrees of earth’s rotation per day



Problem with local variable - Global variable flutter dart



2019 Community Moderator ElectionFlutter - How to pass user data to all viewsDart / flutter: Navigator.push - no such method errorAccessing the route's transition animation from a widget?Fully restart(discard and recreate) the whole flutter app programmaticallyFlutter - Setting the body of a ScaffoldFlutter BottomNavigationBar and advanced navigationtype 'Future<int>' is not a subtype of type 'int' with FlutterAsync function not being called on page creationHow to pass specific ListTile variables to new page route onTap?Flutter how to change the parent BottomNavigationBar index from a child widget










0















I want to pass dynamic data through different pages, when using a BottomAppBar. I currently switch between pages/widgets my storing them like this:



 @override
void initState()
super.initState();
final _pageOptions = [
SwipeScreen(currentUserId: currentUserId),
Requests(currentUserId: currentUserId),
Messages(currentUserId: currentUserId),
Settings(),
];


I then use _pageOptions in my Scaffold:



 body: _pageOptions[_selectedPage],
bottomNavigationBar: BottomNavigationBar(
currentIndex: _selectedPage,
onTap: (int index)
setState(()
_selectedPage = index;
);
,


As you may have guessed, I can't use _pageOptions as my body in my Scaffold, as it is a local variable when wrapped in an initState(). I have to use this initState though, as without it, I can only pass static members in my initializers.



I don't know how to fix this, as removing one just gives me a different error. I have looked for ways to make a variable global, for example having _pageOptions in a different file, but then it was still local, and therefore not defined when used in my Scaffold.



I hope my problem is clear.



Thanks in advance.










share|improve this question




























    0















    I want to pass dynamic data through different pages, when using a BottomAppBar. I currently switch between pages/widgets my storing them like this:



     @override
    void initState()
    super.initState();
    final _pageOptions = [
    SwipeScreen(currentUserId: currentUserId),
    Requests(currentUserId: currentUserId),
    Messages(currentUserId: currentUserId),
    Settings(),
    ];


    I then use _pageOptions in my Scaffold:



     body: _pageOptions[_selectedPage],
    bottomNavigationBar: BottomNavigationBar(
    currentIndex: _selectedPage,
    onTap: (int index)
    setState(()
    _selectedPage = index;
    );
    ,


    As you may have guessed, I can't use _pageOptions as my body in my Scaffold, as it is a local variable when wrapped in an initState(). I have to use this initState though, as without it, I can only pass static members in my initializers.



    I don't know how to fix this, as removing one just gives me a different error. I have looked for ways to make a variable global, for example having _pageOptions in a different file, but then it was still local, and therefore not defined when used in my Scaffold.



    I hope my problem is clear.



    Thanks in advance.










    share|improve this question


























      0












      0








      0








      I want to pass dynamic data through different pages, when using a BottomAppBar. I currently switch between pages/widgets my storing them like this:



       @override
      void initState()
      super.initState();
      final _pageOptions = [
      SwipeScreen(currentUserId: currentUserId),
      Requests(currentUserId: currentUserId),
      Messages(currentUserId: currentUserId),
      Settings(),
      ];


      I then use _pageOptions in my Scaffold:



       body: _pageOptions[_selectedPage],
      bottomNavigationBar: BottomNavigationBar(
      currentIndex: _selectedPage,
      onTap: (int index)
      setState(()
      _selectedPage = index;
      );
      ,


      As you may have guessed, I can't use _pageOptions as my body in my Scaffold, as it is a local variable when wrapped in an initState(). I have to use this initState though, as without it, I can only pass static members in my initializers.



      I don't know how to fix this, as removing one just gives me a different error. I have looked for ways to make a variable global, for example having _pageOptions in a different file, but then it was still local, and therefore not defined when used in my Scaffold.



      I hope my problem is clear.



      Thanks in advance.










      share|improve this question
















      I want to pass dynamic data through different pages, when using a BottomAppBar. I currently switch between pages/widgets my storing them like this:



       @override
      void initState()
      super.initState();
      final _pageOptions = [
      SwipeScreen(currentUserId: currentUserId),
      Requests(currentUserId: currentUserId),
      Messages(currentUserId: currentUserId),
      Settings(),
      ];


      I then use _pageOptions in my Scaffold:



       body: _pageOptions[_selectedPage],
      bottomNavigationBar: BottomNavigationBar(
      currentIndex: _selectedPage,
      onTap: (int index)
      setState(()
      _selectedPage = index;
      );
      ,


      As you may have guessed, I can't use _pageOptions as my body in my Scaffold, as it is a local variable when wrapped in an initState(). I have to use this initState though, as without it, I can only pass static members in my initializers.



      I don't know how to fix this, as removing one just gives me a different error. I have looked for ways to make a variable global, for example having _pageOptions in a different file, but then it was still local, and therefore not defined when used in my Scaffold.



      I hope my problem is clear.



      Thanks in advance.







      dart flutter






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 7 at 0:10









      cipli onat

      171210




      171210










      asked Mar 6 at 19:52









      maddeveloper123maddeveloper123

      276




      276






















          2 Answers
          2






          active

          oldest

          votes


















          1














          This isn't trying to be mean, just honest so please don't take offence, but from the sounds of things you need to start over with some of the basic tutorials on how flutter works and how to develop things in flutter. I'd recommend working through a couple of the tutorials & codelabs on the flutter website from start to finish (without looking at the final code until you're) and then seeing what you've done differently from them. And maybe even the getting started with Dart documentation...



          The simplest answer to your problem is to simply make _pageOptions a member variable of your class as that will allow you to access it from wherever else you need. But since you're running into the issue of only being able to "pass static members in my initializers", that probably means that you aren't initializing things in the right place.



          Here's a few things to keep in mind when developing with flutter:



          1. You shouldn't be creating widgets anywhere except the build function (unless you make a helper function called from the build function - but if you're doing that, it's probably because the widget is getting big and you should split it out into its own Stateful or Stateless widget)

          2. You shouldn't inherit widgets unless you know what you're doing. Most of the time you'll only inherit StatelessWidget and StatefulWidget, and everything else is done through encapsulation (i.e. using them in the build function)

          3. Simply switching pages by changing what you build using an array isn't a great way of doing it - you don't get things like animations when navigating, you potentially build things sooner than needed, and lose out on things like the state of the page unless you're careful about how you do it.

          4. Building widgets is cheap in flutter and you should generally be building most of them for each and every page. There are situations where this isn't true but for a basic app, build the navigation bar for each screen (but with the actual logic that builds it split out into a Stateless or Stateful widget!)

          The solution for #3 is to use a flutter's navigation and either define your pages in MaterialApp(routes: ...) or MaterialApp(onGenerateRoute: ...). So you'd be setting up routes for SwipeScreen, Requests, Messages, and Settings. You'd use Navigator.push or Navigator.pushNamed, or Navigator.pop to move between them.



          And so that you're not copying and pasting the bottom navigation bar everywhere, split it out into its own widget i.e. MyBottomNavigationBar extends StatelessWidget. And then in each of the pages you'd have a Scaffold(body: ..., bottomNavigationBar: MyBottomNavigationBar()). If your scaffold gets really complicated you could even move it to its own widget too.



          Oh and I've just read what might be an important part of your question: I want to pass dynamic data through different pages. Using the navigator as I described changes this slightly as you don't want to be passing it down through each layer of build.



          There's various ways of getting around this - the most basic is using an InheritedWidget, but as it needs a lot of boilerplate to make it work I recommend using a ScopedModel. That way, you simply have to make a class inherited from Model (i.e. UserModel), and then change the information within the model and notify listeners (i.e. the userId) when the user is chosen/logged in. Something like this:



          class UserModel extends Model 
          String _userId;

          String get userId => _userId;

          void setUser(String userId)
          _userId = userId;
          notifyListeners();


          static CounterModel of(BuildContext context, bool rebuildOnChange = false) =>
          ScopedModel.of<CounterModel>(context, rebuildOnChange = rebuildOnChange);



          You'd need to put that somewhere high in your widget tree (probably above the MaterialApp or in the MaterialApp(builder: ...)). And you could then add name, profile, color, etc to that model, and use all of that from wherever you need in your app.






          share|improve this answer

























          • appreciate the wake up call

            – maddeveloper123
            Mar 7 at 20:40


















          0














          Do you want to use _pageOptions in the same class ? if it is this should solve your problem.



           var _pageOptions;
          // declare a variable inside your class/outside of your initState to reach it from anywhere inside in your class
          @override
          void initState()
          super.initState();
          _pageOptions = [
          SwipeScreen(currentUserId: currentUserId),
          Requests(currentUserId: currentUserId),
          Messages(currentUserId: currentUserId),
          Settings(),
          ];






          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55031185%2fproblem-with-local-variable-global-variable-flutter-dart%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            This isn't trying to be mean, just honest so please don't take offence, but from the sounds of things you need to start over with some of the basic tutorials on how flutter works and how to develop things in flutter. I'd recommend working through a couple of the tutorials & codelabs on the flutter website from start to finish (without looking at the final code until you're) and then seeing what you've done differently from them. And maybe even the getting started with Dart documentation...



            The simplest answer to your problem is to simply make _pageOptions a member variable of your class as that will allow you to access it from wherever else you need. But since you're running into the issue of only being able to "pass static members in my initializers", that probably means that you aren't initializing things in the right place.



            Here's a few things to keep in mind when developing with flutter:



            1. You shouldn't be creating widgets anywhere except the build function (unless you make a helper function called from the build function - but if you're doing that, it's probably because the widget is getting big and you should split it out into its own Stateful or Stateless widget)

            2. You shouldn't inherit widgets unless you know what you're doing. Most of the time you'll only inherit StatelessWidget and StatefulWidget, and everything else is done through encapsulation (i.e. using them in the build function)

            3. Simply switching pages by changing what you build using an array isn't a great way of doing it - you don't get things like animations when navigating, you potentially build things sooner than needed, and lose out on things like the state of the page unless you're careful about how you do it.

            4. Building widgets is cheap in flutter and you should generally be building most of them for each and every page. There are situations where this isn't true but for a basic app, build the navigation bar for each screen (but with the actual logic that builds it split out into a Stateless or Stateful widget!)

            The solution for #3 is to use a flutter's navigation and either define your pages in MaterialApp(routes: ...) or MaterialApp(onGenerateRoute: ...). So you'd be setting up routes for SwipeScreen, Requests, Messages, and Settings. You'd use Navigator.push or Navigator.pushNamed, or Navigator.pop to move between them.



            And so that you're not copying and pasting the bottom navigation bar everywhere, split it out into its own widget i.e. MyBottomNavigationBar extends StatelessWidget. And then in each of the pages you'd have a Scaffold(body: ..., bottomNavigationBar: MyBottomNavigationBar()). If your scaffold gets really complicated you could even move it to its own widget too.



            Oh and I've just read what might be an important part of your question: I want to pass dynamic data through different pages. Using the navigator as I described changes this slightly as you don't want to be passing it down through each layer of build.



            There's various ways of getting around this - the most basic is using an InheritedWidget, but as it needs a lot of boilerplate to make it work I recommend using a ScopedModel. That way, you simply have to make a class inherited from Model (i.e. UserModel), and then change the information within the model and notify listeners (i.e. the userId) when the user is chosen/logged in. Something like this:



            class UserModel extends Model 
            String _userId;

            String get userId => _userId;

            void setUser(String userId)
            _userId = userId;
            notifyListeners();


            static CounterModel of(BuildContext context, bool rebuildOnChange = false) =>
            ScopedModel.of<CounterModel>(context, rebuildOnChange = rebuildOnChange);



            You'd need to put that somewhere high in your widget tree (probably above the MaterialApp or in the MaterialApp(builder: ...)). And you could then add name, profile, color, etc to that model, and use all of that from wherever you need in your app.






            share|improve this answer

























            • appreciate the wake up call

              – maddeveloper123
              Mar 7 at 20:40















            1














            This isn't trying to be mean, just honest so please don't take offence, but from the sounds of things you need to start over with some of the basic tutorials on how flutter works and how to develop things in flutter. I'd recommend working through a couple of the tutorials & codelabs on the flutter website from start to finish (without looking at the final code until you're) and then seeing what you've done differently from them. And maybe even the getting started with Dart documentation...



            The simplest answer to your problem is to simply make _pageOptions a member variable of your class as that will allow you to access it from wherever else you need. But since you're running into the issue of only being able to "pass static members in my initializers", that probably means that you aren't initializing things in the right place.



            Here's a few things to keep in mind when developing with flutter:



            1. You shouldn't be creating widgets anywhere except the build function (unless you make a helper function called from the build function - but if you're doing that, it's probably because the widget is getting big and you should split it out into its own Stateful or Stateless widget)

            2. You shouldn't inherit widgets unless you know what you're doing. Most of the time you'll only inherit StatelessWidget and StatefulWidget, and everything else is done through encapsulation (i.e. using them in the build function)

            3. Simply switching pages by changing what you build using an array isn't a great way of doing it - you don't get things like animations when navigating, you potentially build things sooner than needed, and lose out on things like the state of the page unless you're careful about how you do it.

            4. Building widgets is cheap in flutter and you should generally be building most of them for each and every page. There are situations where this isn't true but for a basic app, build the navigation bar for each screen (but with the actual logic that builds it split out into a Stateless or Stateful widget!)

            The solution for #3 is to use a flutter's navigation and either define your pages in MaterialApp(routes: ...) or MaterialApp(onGenerateRoute: ...). So you'd be setting up routes for SwipeScreen, Requests, Messages, and Settings. You'd use Navigator.push or Navigator.pushNamed, or Navigator.pop to move between them.



            And so that you're not copying and pasting the bottom navigation bar everywhere, split it out into its own widget i.e. MyBottomNavigationBar extends StatelessWidget. And then in each of the pages you'd have a Scaffold(body: ..., bottomNavigationBar: MyBottomNavigationBar()). If your scaffold gets really complicated you could even move it to its own widget too.



            Oh and I've just read what might be an important part of your question: I want to pass dynamic data through different pages. Using the navigator as I described changes this slightly as you don't want to be passing it down through each layer of build.



            There's various ways of getting around this - the most basic is using an InheritedWidget, but as it needs a lot of boilerplate to make it work I recommend using a ScopedModel. That way, you simply have to make a class inherited from Model (i.e. UserModel), and then change the information within the model and notify listeners (i.e. the userId) when the user is chosen/logged in. Something like this:



            class UserModel extends Model 
            String _userId;

            String get userId => _userId;

            void setUser(String userId)
            _userId = userId;
            notifyListeners();


            static CounterModel of(BuildContext context, bool rebuildOnChange = false) =>
            ScopedModel.of<CounterModel>(context, rebuildOnChange = rebuildOnChange);



            You'd need to put that somewhere high in your widget tree (probably above the MaterialApp or in the MaterialApp(builder: ...)). And you could then add name, profile, color, etc to that model, and use all of that from wherever you need in your app.






            share|improve this answer

























            • appreciate the wake up call

              – maddeveloper123
              Mar 7 at 20:40













            1












            1








            1







            This isn't trying to be mean, just honest so please don't take offence, but from the sounds of things you need to start over with some of the basic tutorials on how flutter works and how to develop things in flutter. I'd recommend working through a couple of the tutorials & codelabs on the flutter website from start to finish (without looking at the final code until you're) and then seeing what you've done differently from them. And maybe even the getting started with Dart documentation...



            The simplest answer to your problem is to simply make _pageOptions a member variable of your class as that will allow you to access it from wherever else you need. But since you're running into the issue of only being able to "pass static members in my initializers", that probably means that you aren't initializing things in the right place.



            Here's a few things to keep in mind when developing with flutter:



            1. You shouldn't be creating widgets anywhere except the build function (unless you make a helper function called from the build function - but if you're doing that, it's probably because the widget is getting big and you should split it out into its own Stateful or Stateless widget)

            2. You shouldn't inherit widgets unless you know what you're doing. Most of the time you'll only inherit StatelessWidget and StatefulWidget, and everything else is done through encapsulation (i.e. using them in the build function)

            3. Simply switching pages by changing what you build using an array isn't a great way of doing it - you don't get things like animations when navigating, you potentially build things sooner than needed, and lose out on things like the state of the page unless you're careful about how you do it.

            4. Building widgets is cheap in flutter and you should generally be building most of them for each and every page. There are situations where this isn't true but for a basic app, build the navigation bar for each screen (but with the actual logic that builds it split out into a Stateless or Stateful widget!)

            The solution for #3 is to use a flutter's navigation and either define your pages in MaterialApp(routes: ...) or MaterialApp(onGenerateRoute: ...). So you'd be setting up routes for SwipeScreen, Requests, Messages, and Settings. You'd use Navigator.push or Navigator.pushNamed, or Navigator.pop to move between them.



            And so that you're not copying and pasting the bottom navigation bar everywhere, split it out into its own widget i.e. MyBottomNavigationBar extends StatelessWidget. And then in each of the pages you'd have a Scaffold(body: ..., bottomNavigationBar: MyBottomNavigationBar()). If your scaffold gets really complicated you could even move it to its own widget too.



            Oh and I've just read what might be an important part of your question: I want to pass dynamic data through different pages. Using the navigator as I described changes this slightly as you don't want to be passing it down through each layer of build.



            There's various ways of getting around this - the most basic is using an InheritedWidget, but as it needs a lot of boilerplate to make it work I recommend using a ScopedModel. That way, you simply have to make a class inherited from Model (i.e. UserModel), and then change the information within the model and notify listeners (i.e. the userId) when the user is chosen/logged in. Something like this:



            class UserModel extends Model 
            String _userId;

            String get userId => _userId;

            void setUser(String userId)
            _userId = userId;
            notifyListeners();


            static CounterModel of(BuildContext context, bool rebuildOnChange = false) =>
            ScopedModel.of<CounterModel>(context, rebuildOnChange = rebuildOnChange);



            You'd need to put that somewhere high in your widget tree (probably above the MaterialApp or in the MaterialApp(builder: ...)). And you could then add name, profile, color, etc to that model, and use all of that from wherever you need in your app.






            share|improve this answer















            This isn't trying to be mean, just honest so please don't take offence, but from the sounds of things you need to start over with some of the basic tutorials on how flutter works and how to develop things in flutter. I'd recommend working through a couple of the tutorials & codelabs on the flutter website from start to finish (without looking at the final code until you're) and then seeing what you've done differently from them. And maybe even the getting started with Dart documentation...



            The simplest answer to your problem is to simply make _pageOptions a member variable of your class as that will allow you to access it from wherever else you need. But since you're running into the issue of only being able to "pass static members in my initializers", that probably means that you aren't initializing things in the right place.



            Here's a few things to keep in mind when developing with flutter:



            1. You shouldn't be creating widgets anywhere except the build function (unless you make a helper function called from the build function - but if you're doing that, it's probably because the widget is getting big and you should split it out into its own Stateful or Stateless widget)

            2. You shouldn't inherit widgets unless you know what you're doing. Most of the time you'll only inherit StatelessWidget and StatefulWidget, and everything else is done through encapsulation (i.e. using them in the build function)

            3. Simply switching pages by changing what you build using an array isn't a great way of doing it - you don't get things like animations when navigating, you potentially build things sooner than needed, and lose out on things like the state of the page unless you're careful about how you do it.

            4. Building widgets is cheap in flutter and you should generally be building most of them for each and every page. There are situations where this isn't true but for a basic app, build the navigation bar for each screen (but with the actual logic that builds it split out into a Stateless or Stateful widget!)

            The solution for #3 is to use a flutter's navigation and either define your pages in MaterialApp(routes: ...) or MaterialApp(onGenerateRoute: ...). So you'd be setting up routes for SwipeScreen, Requests, Messages, and Settings. You'd use Navigator.push or Navigator.pushNamed, or Navigator.pop to move between them.



            And so that you're not copying and pasting the bottom navigation bar everywhere, split it out into its own widget i.e. MyBottomNavigationBar extends StatelessWidget. And then in each of the pages you'd have a Scaffold(body: ..., bottomNavigationBar: MyBottomNavigationBar()). If your scaffold gets really complicated you could even move it to its own widget too.



            Oh and I've just read what might be an important part of your question: I want to pass dynamic data through different pages. Using the navigator as I described changes this slightly as you don't want to be passing it down through each layer of build.



            There's various ways of getting around this - the most basic is using an InheritedWidget, but as it needs a lot of boilerplate to make it work I recommend using a ScopedModel. That way, you simply have to make a class inherited from Model (i.e. UserModel), and then change the information within the model and notify listeners (i.e. the userId) when the user is chosen/logged in. Something like this:



            class UserModel extends Model 
            String _userId;

            String get userId => _userId;

            void setUser(String userId)
            _userId = userId;
            notifyListeners();


            static CounterModel of(BuildContext context, bool rebuildOnChange = false) =>
            ScopedModel.of<CounterModel>(context, rebuildOnChange = rebuildOnChange);



            You'd need to put that somewhere high in your widget tree (probably above the MaterialApp or in the MaterialApp(builder: ...)). And you could then add name, profile, color, etc to that model, and use all of that from wherever you need in your app.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 6 at 21:48

























            answered Mar 6 at 21:38









            rmtmckenziermtmckenzie

            7,2811429




            7,2811429












            • appreciate the wake up call

              – maddeveloper123
              Mar 7 at 20:40

















            • appreciate the wake up call

              – maddeveloper123
              Mar 7 at 20:40
















            appreciate the wake up call

            – maddeveloper123
            Mar 7 at 20:40





            appreciate the wake up call

            – maddeveloper123
            Mar 7 at 20:40













            0














            Do you want to use _pageOptions in the same class ? if it is this should solve your problem.



             var _pageOptions;
            // declare a variable inside your class/outside of your initState to reach it from anywhere inside in your class
            @override
            void initState()
            super.initState();
            _pageOptions = [
            SwipeScreen(currentUserId: currentUserId),
            Requests(currentUserId: currentUserId),
            Messages(currentUserId: currentUserId),
            Settings(),
            ];






            share|improve this answer



























              0














              Do you want to use _pageOptions in the same class ? if it is this should solve your problem.



               var _pageOptions;
              // declare a variable inside your class/outside of your initState to reach it from anywhere inside in your class
              @override
              void initState()
              super.initState();
              _pageOptions = [
              SwipeScreen(currentUserId: currentUserId),
              Requests(currentUserId: currentUserId),
              Messages(currentUserId: currentUserId),
              Settings(),
              ];






              share|improve this answer

























                0












                0








                0







                Do you want to use _pageOptions in the same class ? if it is this should solve your problem.



                 var _pageOptions;
                // declare a variable inside your class/outside of your initState to reach it from anywhere inside in your class
                @override
                void initState()
                super.initState();
                _pageOptions = [
                SwipeScreen(currentUserId: currentUserId),
                Requests(currentUserId: currentUserId),
                Messages(currentUserId: currentUserId),
                Settings(),
                ];






                share|improve this answer













                Do you want to use _pageOptions in the same class ? if it is this should solve your problem.



                 var _pageOptions;
                // declare a variable inside your class/outside of your initState to reach it from anywhere inside in your class
                @override
                void initState()
                super.initState();
                _pageOptions = [
                SwipeScreen(currentUserId: currentUserId),
                Requests(currentUserId: currentUserId),
                Messages(currentUserId: currentUserId),
                Settings(),
                ];







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 6 at 21:21









                cipli onatcipli onat

                171210




                171210



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55031185%2fproblem-with-local-variable-global-variable-flutter-dart%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    1928 у кіно

                    Захаров Федір Захарович

                    Ель Греко