颤振:无法导航到其他页面

时间:2020-05-16 23:02:35

标签: flutter flutter-layout flutter-web flutter-navigation

因此,在构建了第一个页面之后,我开始为我的应用程序处理其他页面。我成功制作了另外两个浮动页面,并且能够允许用户在这两个浮动页面之间导航,但是当我尝试允许用户在原始浮动页面上导航到其他两个浮动页面时,什么也没有发生。

注意:导航代码似乎正确编写了(它适用于其他两个页面)

注2:我导航到另一页的行链接到标有“查看记录”的凸起按钮

有人可以指出此页面中不允许用户导航到另一页面的任何内容吗?谢谢!

import 'package:flutter/material.dart';
import 'package:faui/faui.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:provendor3/FlutterAuthUiDemoy.dart';
import 'main.dart';

void firestore_page() => runApp(firestore_pagey());
class firestore_pagey extends StatefulWidget {
   @override
  MyApps createState() => MyApps();
 }

class MyApps extends State<firestore_pagey> {

final databaseReference = Firestore.instance;
@override
Widget build(BuildContext context) {
return MaterialApp(home:
  Scaffold(
  appBar: AppBar(
    title: Text('FireStore Demo'),
  ),
  body: Center(
      child: Column(
    crossAxisAlignment: CrossAxisAlignment.stretch,

    children: <Widget>[

      RaisedButton(
        child: Text('Create Record'),
        onPressed: () {
          createRecord();
        },
      ),
      RaisedButton(
        child: Text('View Record'),
        onPressed: () {
         Navigator.push(
                  context,
                  MaterialPageRoute(builder: (context) => MyApp()),
                );
        },
      ),
      RaisedButton(
        child: Text('Update Record'),
        onPressed: () {
          updateData();
        },
      ),
      RaisedButton(
        child: Text('Delete Record'),
        onPressed: () {
          deleteData();
        },
      ),
  new Expanded(child:
    new StreamBuilder<QuerySnapshot>(
    stream: databaseReference.collection('books').snapshots(),
    builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
      if (!snapshot.hasData) return new Text('Loading...');
      return new ListView(
        children: snapshot.data.documents.map((DocumentSnapshot document) {
          return new ListTile(
            title: new Text(document['title']),
            subtitle: new Text('${document['description']} description'),
          );
        }).toList(),
      );
    },
    )
  )
    ],
  )),
 ) //center
);
}

Main.dart

  import 'package:flutter/material.dart';
  import 'FlutterAuthUiDemoy.dart';
  import "firestore_page.dart";

   void main() {  
    runApp(MyApp());
    }


  class MyApp extends StatelessWidget {
     @override
     Widget build(BuildContext context) {
     return MaterialApp(
       home: Builder(
        builder: (context) => Scaffold(
        appBar: AppBar(
           title: Text("Page 1"),
        ),
      body: Center(
        child: Column(
          children: <Widget>[
            MaterialButton(
              child: Text("Next Page"),
              onPressed: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(builder: (context) => FlutterAuthUiDemo()),
                );
              },
              color: Colors.red,
            )
          ],
        ),
      ),
    ),
  ),
);

2 个答案:

答案 0 :(得分:0)

您可以删除MaterialApp然后再试一次吗?我假设您的main.dart中已经有一个MaterialApp。

public class NafMaintest extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_naf_main);
        BottomNavigationView bottomNav = findViewById(R.id.bottom_navigation);
            BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
            bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
                    Fragment selectedFragment = null;
                    switch (menuItem.getItemId()) {
                        case R.id.nav_home:
                           selectedFragment = new MainActivityOderLIstFargmant();//I try like that but not work 
                            break;
                        case R.id.nav_favorites:
                            selectedFragment = new FragmentHome();
                            break;
                        case R.id.nav_search:
                            selectedFragment = new FragmentProfile();
                            break;
                        case R.id.nav_s:
                            selectedFragment = new MainActivity();
                            break;
                    }
                    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
                            selectedFragment).commit();
                    return true;

                }
            });

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
                    new FragmentHome()).commit();
        }
    }



}



答案 1 :(得分:0)

因此,问题似乎出在我正在浏览的页面上。我使用的库似乎在使用后会阻止导航,因此我从页面上将其删除之前,现在可以在页面上正常浏览了!感谢您的所有帮助!