没有出现BottomNavigationBar

时间:2020-04-13 16:15:37

标签: flutter

我正在尝试制作一个应用,并且我使用firebase登录/注册。登录时,我的主页没有显示我创建的底部栏。这是底部栏的脚本:

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

class MainScreen extends StatefulWidget{

@override
_MainScreenState createState() => _MainScreenState();

}

class _MainScreenState extends State<MainScreen>{

int currentTabIndex = 0;

List<Widget> pages;
Widget currentPage;
HomePage homePage;


@override 

void initState(){

  super.initState();
  homePage = HomePage();
  pages = [homePage];

  currentPage = homePage;
}


Widget build (BuildContext context){
  return Scaffold(
    bottomNavigationBar: BottomNavigationBar(
      onTap: (int index){
setState(() {
  currentTabIndex = index;
  currentPage = pages[index];

});
      },
currentIndex: currentTabIndex,
type: BottomNavigationBarType.fixed,

      items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon:Icon(Icons.home),
title: Text("Home")


),
BottomNavigationBarItem(
  icon: Icon(Icons.shopping_cart),
  title: Text("Cumparaturi")
  ),
BottomNavigationBarItem(
  icon: Icon(Icons.favorite),
  title: Text("Favorite")
),

BottomNavigationBarItem(
  icon: Icon(Icons.person),
  title: Text("Profile")
  ),
      ]
      
      
      ),
body: currentPage,
  );
}

}

这是main.dart的脚本:

import 'package:flutter/material.dart';
import 'auth.dart';
import 'root_page.dart';
import 'auth_provider.dart';
import 'main_screen.dart';



void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return AuthProvider(
      auth: Auth(),
      child: MaterialApp(
        title: 'Login',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: RootPage(),
      ),
    );
  }
}

我应该在home_page.dart中进行更改吗?

import 'package:flutter/material.dart';
import 'package:food4me/food_category.dart';
import 'auth.dart';
import 'auth_provider.dart';
import 'home_top_info.dart';
import 'food_category.dart';
import 'search_field.dart';
import 'bought_foods.dart';
import 'food_data.dart';
import 'food_model.dart';

class HomePage extends StatelessWidget {
  
   HomePage({this.onSignedOut});
  final VoidCallback onSignedOut;

  Future<void> _signOut(BuildContext context) async {
    try {
      final BaseAuth auth = AuthProvider.of(context).auth;
      await auth.signOut();
      onSignedOut();
    } catch (e) {
      print(e);
    }
  }
    List<Food> _foods = foods;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        actions: <Widget>[
          FlatButton(
            child: Text('Logout', style: TextStyle(fontSize: 17.0, color: Colors.white)),
            onPressed: () => _signOut(context),
          )
        ],
      ),
      body: ListView(
        padding: EdgeInsets.only(top:20.0, left: 20.0, right:20.0),
        children: <Widget>[
        HomeTopInfo(),
        FoodCategory(),
        SizedBox(height: 20.0 ,),
        SearchField(),
        SizedBox(height: 20.0 ,),
        Row( 
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Text("Cele mai accesate magazine",
            style: TextStyle(
              fontSize:18.0,
              fontWeight: FontWeight.bold,



            )
            
            ),
            
            GestureDetector(
              onTap: () {},
                          child: Text("View All",
              style:TextStyle(
                fontSize: 18.0,
                fontWeight: FontWeight.bold,
                color: Colors.orangeAccent



              ),
              
              
              ),
            ),



          ],






        ),
        SizedBox(height: 20.0 ,),
        Column(
          children: _foods.map(_buildFoodItems).toList()
          
          ),
        ],
        ),
      );
  }
  Widget _buildFoodItems(Food food){
    return Container(
      margin:EdgeInsets.only(bottom: 20.0),
child: BoughtFoods(
  id: food.id,
  name: food.name,
  imagePath: food.imagePath,
  category: food.category,
  discount: food.discount,
  price: food.price,
  ratings: food.ratings,
),


    );
   
  }
}

当我在main.dart主页:主页中进行更改时,底部栏出现,但是我的注销不再起作用。我该怎么办?

0 个答案:

没有答案