Without user interaction how to navigate a second page?

2,256 views
Skip to first unread message

Niyazi Toros

unread,
May 31, 2018, 7:26:24 AM5/31/18
to Flutter Dev
Hi,

Without using swipe, ontap, oppressed, and gesture how to navigate a second page?

I have a main.dart (MyHomePage) and I have another 2 page as second.dart and third.dart.
In main.dart I have to load json data using Future<T>. Based on the data I need to navigate user
automatically to second.dart page or third.dart page.

Any help please?

Thanks

Eugenio Tesio

unread,
May 31, 2018, 7:28:39 AM5/31/18
to Niyazi Toros, Flutter Dev
Post the Future<T> method.

--
You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Eugenio Tesio
Zetus - Soluciones Empresariales
División Sistemas
(+549) 3564-15-599945
San Francisco - 2400
Pcia de Córdoba - Argentina



Niyazi Toros

unread,
May 31, 2018, 7:51:35 AM5/31/18
to Flutter Dev
Hi,

Here is the code:



// TODO: 4) _MyHomePageState Class

class _MyHomePageState extends State<MyHomePage> {


  @override

  void initState() {

    // TODO: implement initState

    super.initState();

    this.getCompanyJsonData();

  }


  Future<String> this.getCompanyJsonData() async {

    var response = await http.get(

        Uri.encodeFull("https://secur****-company-api-*****/fx.jsp"),

        headers: {'Accept': 'application/json'});


    setState(() {

      var resBody = json.decode(response.body);

      currencyData = resBody[“alis”];

      aAlis = currencyData["aalis"];

      bAlis = currencyData[[“balis"];

      cAlis = currencyData[“calis"];

    });


    return "Success!";

  }



// TODO: BUILD WIDGET

  @override

  Widget build(BuildContext context) {

    if (currencyData == null){

      return new Center(

          child: new CircularProgressIndicator(

            backgroundColor: lightMainGreen,

          )

      );

    } else if (aAlis != null) {

  // redirect to Second Page

    }

     else if (bAlis != null) {

              // redirect to Third Page

    }

     else if (cAlis != null) {

             // redirect to Fourth Page

    }

else {

      return new Scaffold(

        // APPBAR


        // title: ,

        appBar: new AppBar(

          title: new Text(

            trans(context, "main.appTitle"),

            style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.w500),

          ),

          //elevation: 1.0,

          backgroundColor: midMainGreen,

        ),


        // BODY

        body: new Center(

          child: new Text(‘No data found’),

        ),

      );

    }

  } // build Widget



Eugenio Tesio

unread,
May 31, 2018, 8:15:20 AM5/31/18
to Niyazi Toros, Flutter Dev
Try this:


// TODO: 4) _MyHomePageState Class

class _MyHomePageState extends State<MyHomePage> {


  @override

  void initState() {

    // TODO: implement initState

    super.initState();

    this.getCompanyJsonData();

  }


  Future<String> this.getCompanyJsonData() async {

    var response = await http.get(

        Uri.encodeFull("https://secur****-company-api-*****/fx.jsp"),

        headers: {'Accept': 'application/json'});


    aAlis = currencyData["aalis"];  


    setState(() {

      var resBody = json.decode(response.body);

      currencyData = resBody[“alis”];

      bAlis = currencyData[[“balis"];

      cAlis = currencyData[“calis"];

    });


   if (aAlis != null) {

  Navigator
.of(context)
.push(new MaterialPageRoute(builder: (BuildContext context) {
return new AlisPage(...);
}));
--
You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Niyazi Toros

unread,
May 31, 2018, 8:50:03 AM5/31/18
to Flutter Dev

I am getting error as shown below.
Before Navigator I need to use return statement and return widget and then make some magical thing to
use your code (Navigator...) But I am new to this and I don't have any clue.... :( Any more help please....



I/flutter (11771): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (11771): The following assertion was thrown building MyHomePage(dirty, state: _MyHomePageState#432fd):
I/flutter (11771): setState() or markNeedsBuild() called during build.
I/flutter (11771): This Overlay widget cannot be marked as needing to build because the framework is already in the
I/flutter (11771): process of building widgets. A widget can be marked as needing to be built during the build phase
I/flutter (11771): only if one of its ancestors is currently building. This exception is allowed because the framework
I/flutter (11771): builds parent widgets before children, which means a dirty descendant will always be built.
I/flutter (11771): Otherwise, the framework might not visit this widget during this build phase.
I/flutter (11771): The widget on which setState() or markNeedsBuild() was called was:
I/flutter (11771):   Overlay-[LabeledGlobalKey<OverlayState>#a22c7](state: OverlayState#23c67(entries:
I/flutter (11771):   [OverlayEntry#f0745(opaque: false; maintainState: false), OverlayEntry#a42a6(opaque: false;
I/flutter (11771):   maintainState: true), OverlayEntry#12173(opaque: false; maintainState: false),
I/flutter (11771):   OverlayEntry#6e9da(opaque: false; maintainState: true)]))
I/flutter (11771): The widget which was currently being built when the offending call was made was:
I/flutter (11771):   MyHomePage(dirty, state: _MyHomePageState#432fd)

Eugenio Tesio

unread,
May 31, 2018, 9:09:29 AM5/31/18
to Niyazi Toros, Flutter Dev
Ok, now i understand your code a little more. Maybe you can create methods that return a scaffold of your second, third and four page and put it all together. Something like this:

Widget secondPage() {
   return new Scaffod ...
}

Widget thirdPage() {
   return new Scaffod ...
}

Widget fourPage() {
   return new Scaffod ...
}

// TODO: BUILD WIDGET

  @override

  Widget build(BuildContext context) {

    if (currencyData == null){

      return new Center(

          child: new CircularProgressIndicator(

            backgroundColor: lightMainGreen,

          )

      );

    } else if (aAlis != null) {

   return secondPage();

    }

     else if (bAlis != null) {

             return thirdPage();

    }

     else if (cAlis != null) {

             return fourPage();

    }

else {

      return new Scaffold(

        // APPBAR


        // title: ,

        appBar: new AppBar(

          title: new Text(

            trans(context"main.appTitle"),

            style: TextStyle(fontSize: 18.0fontWeight: FontWeight.w500),

          ),

          //elevation: 1.0,

          backgroundColor: midMainGreen,

        ),


        // BODY

        body: new Center(

          child: new Text(‘No data found’),

        ),

      );

    }

  } // build Widget



--
You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Niyazi Toros

unread,
May 31, 2018, 9:36:35 AM5/31/18
to Flutter Dev
getting same error....

Here is my code of second page:

aalis.dart
import 'package:flutter/material.dart';

class AlisPage extends StatefulWidget {
@override
_AlisPageState createState() => new _AlisPageState();
}

class _AlisPageState extends State<AlisPage> {
@override
Widget build(BuildContext context) {
return new Container(
child: new Text('Welcome to Second Page...'),
);
}
}



The main.dart:

import 'package:flutter/material.dart';

import 'dart:async';

import 'dart:convert';

import 'package:http/http.dart' as http;

import 'package:navigator_capital/aalis.dart';



final Color darkMainGreen = const Color(0xFF689F38);

final Color midMainGreen = const Color(0xFF7CB342);

final Color lightMainGreen = const Color(0xFF8BC34A);


bool appLocaleSet;

Map companyData;

String aAlis;



// TODO: 1) MAIN **********************************************

void main() async {

  runApp(new MyApp());

}


// TODO: 2) MyApp *********************************************

class MyApp extends StatelessWidget {

  // This widget is the root of your application.

  @override

  Widget build(BuildContext context) {

    return new MaterialApp(

        debugShowCheckedModeBanner: false,

        title: "Company",

        home: new MyHomePage(),

    );

  }

}


// TODO: 3) Statefull MyHomePage Class ************************

class MyHomePage extends StatefulWidget {

  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;


  @override

  _MyHomePageState createState() => new _MyHomePageState();

}




// TODO: 4) _MyHomePageState Class ****************************

class _MyHomePageState extends State<MyHomePage> {


  @override

  void initState() {


    super.initState();

    getCompanyJsonData();

  }


  Future<String> getCompanyJsonData() async {

    var response = await http.get(

        Uri.encodeFull("https://*******************************”),

        headers: {'Accept': 'application/json'});


    setState(() {

      var resBody = json.decode(response.body);

      companyData = resBody[“alis”];

      aAlis = 'aalis';

    });


    return "Success!";

  }



// TODO: BUILD WIDGET ******************************************

  @override

  Widget build(BuildContext context) {

    if (companyData == null){

      return new Center(

          child: new CircularProgressIndicator(

            backgroundColor: lightMainGreen,

          )

      );

    } else if (aAlis != null) {

      // redirect to Second Page

      // ******* this is not work either ******************

      // ******* the AlisPage is in aalis.dart ************

       Navigator

      .of(context)

          .push(new MaterialPageRoute(builder: (BuildContext context){

            Widget AlisPage() {  

              return new Scaffold(

                body: new Center(

                  child: new Text("This is Second Page that returns"),

                ),

              );

            }

      }));

    }

    else {

      return new Scaffold(

        // APPBAR

        appBar: new AppBar(

          title: new Text('Company'),

          ),

          backgroundColor: midMainGreen,


        // BODY

        body: new Center(

          child: new Text(’Showing the Json Data’),

Reply all
Reply to author
Forward
0 new messages