错误。在切换多个标签时出现问题。翩翩

问题描述 投票:0回答:1

因此,我试图创建一个有3个标签的个人资料界面......个人资料,最近的和审查,但是在尝试这样做时,我面临着一个错误。我无法表示所有3个标签。最近的标签页有这样的小工具

  Widget RecentItems() {
   return Padding(
      padding: const EdgeInsets.all(10.0),
      child: StreamBuilder(
          stream: Firestore.instance
              .collection("users")
              .document(uid)
              .collection("recent")
              .snapshots(),
          builder: (context, snapshot) {
            print(snapshot.data);
            List orders = List.from(Map.from(snapshot.data.data)['orders']);
            Map order;
            for (int i = 0; i < orders.length; i++) {
              if (orders[i]['orderId'] == widget.map['orderId'] &&
                  orders[i]['homemaker'] == widget.map['homemaker']) {
                order = orders[i];
                break;
              }
            }
            if (snapshot.data.isEmpty) {
              return Center(
                  child:
                  Text("OOPS, Looks like no one is serving!"));
            }
            print(order);
            if (snapshot.connectionState == ConnectionState.waiting) {
              return Center(child: CircularProgressIndicator());
            } else if (snapshot.hasData) {
              print(snapshot.data.documents[0].data);
              return Container(
                height: 400,
                child: ListView.builder(
                    itemCount: snapshot.data.documents.length,
                    itemBuilder: (BuildContext context, int index) {
                      return Container(
                        margin: EdgeInsets.all(10.0),
                        width: MediaQuery
                            .of(context)
                            .size
                            .width,
                        height: 85,
                        decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.circular(10.0),),
                        child: Padding(
                          padding: const EdgeInsets.all(10.0),
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.start,
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: <Widget>[
                              Row(
                                children: <Widget>[
                                  Expanded(child: Text(
                                    "${snapshot.data.documents[index]
                                        .data["dishname"]}", style: TextStyle(
                                      fontSize: 15,
                                      fontWeight: FontWeight.bold),)),
                                  //Icon: how to access if food is veg or not
                                ],
                              ),
                              // SizedBox(height:5),
                              Row(
                                children: <Widget>[
                                  Expanded(child: Text(
                                    "${snapshot.data.documents[index]
                                        .data["homemaker"]}",
                                    style: TextStyle(fontSize: 10),)),
                                  Text("${snapshot.data.documents[index]
                                      .data["rating"]}",
                                      style: TextStyle(fontSize: 15)),
                                  Icon(
                                    Icons.star, color: Colors.yellow.shade800,
                                    size: 20,)
                                ],
                              ),
                              SizedBox(height: 5),
                              //How to access order date
                              Text(
                                "Ordered ${DateTime
                                    .parse(order['order_placed_at']
                                    .toDate()
                                    .toString())
                                    .day}/${DateTime
                                    .parse(order['order_placed_at']
                                    .toDate()
                                    .toString())
                                    .month}/${DateTime
                                    .parse(order['order_placed_at']
                                    .toDate()
                                    .toString())
                                    .year}}",
                                style: TextStyle(fontSize: 15.0,
                                    fontWeight: FontWeight.bold),
                              ),
                            ],
                          ),
                        ),
                      );
                    }),
              );
            } //
          }),
    );
  }

我是这样显示它们的...

int _selectedIndex = 3;

  var uid;

  Future<String> getUser() async {
    final FirebaseUser user = await _auth.currentUser().then((val) {
      setState(() {
        uid = val.uid;
      });
    });
  }

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
    if (_selectedIndex == 0) {
      Navigator.pushReplacementNamed(context, "/ExplorePage");
    } else if (_selectedIndex == 1) {
      Navigator.pushReplacementNamed(context, "/SearchPage");
    } else if (_selectedIndex == 2) {
      Navigator.pushReplacementNamed(context, "/FavoriteScreenPage",
          arguments: uid);
    }
  }
  TabController tabController;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: Padding(
          padding: EdgeInsets.fromLTRB(20, 0, 20, 20),
          child: SizedBox(
            height: 54,
            child: BottomNavigationBar(
              showSelectedLabels: false,
              showUnselectedLabels: false,
              backgroundColor: Color.fromRGBO(255, 255, 255, 0.8),
              currentIndex: _selectedIndex,
              selectedItemColor: Color(0xffFE506D),
              onTap: _onItemTapped,
              items: [
                BottomNavigationBarItem(
                  icon: Icon(
                    Icons.explore,
                    color: Colors.black,
                  ),
                  title: Text("Explore"),
                ),
                BottomNavigationBarItem(
                  icon: Icon(Icons.search, color: Colors.black),
                  title: Text("Search"),
                ),
                BottomNavigationBarItem(
                  icon: Icon(Icons.bookmark_border, color: Colors.black),
                  title: Text("Faavorites"),
                ),
                BottomNavigationBarItem(
                  icon: Icon(Icons.perm_identity, color: Color(0xffFE506D)),
                  title: Text("Shop"),
                )
              ],
            ),
          )),
      drawer: DrawerWidget(uid: this.uid),
      appBar: AppBar(
        backgroundColor: Colors.white,
        iconTheme: IconThemeData(color: Colors.black),
        elevation: 0,
      ),
      backgroundColor: Color(0xffE5E5E5),
      body: SingleChildScrollView(
        child: Column(
          children: <Widget>[
            ClipRRect(
              borderRadius: BorderRadius.only(
                  bottomRight: Radius.circular(25),
                  bottomLeft: Radius.circular(25)),
              child: Container(
                height: 230,
                width: MediaQuery.of(context).size.width,
                decoration: new BoxDecoration(
                  // border: new Border.all(width: 1.0, color: Colors.black),
                  shape: BoxShape.rectangle,
                  color: Colors.white,
                  boxShadow: <BoxShadow>[
                    BoxShadow(
                      color: Colors.black,
                      offset: Offset(20.0, 30.0),
                      blurRadius: 40.0,
                    ),
                  ],
                ),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    Container(
                        width: 155,
                        height: 155,
                        decoration: new BoxDecoration(
                            shape: BoxShape.circle,
                            image: new DecorationImage(
                                fit: BoxFit.cover,
                                image: new NetworkImage("$_image")))),
                    SizedBox(height: 10),
                    Text("$_name",
                        style: TextStyle(
                            fontSize: 25, fontWeight: FontWeight.bold))
                  ],
                ),
              ),
            ),
            SizedBox(
              height: 20,
            ),
            Padding(
              padding: const EdgeInsets.only(left: 15.0),
              child: Container(
                // margin: EdgeInsets.only(left: 15.0),
                child: Container(
                // margin: EdgeInsets.only(left: 15.0),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    GestureDetector(
                      onTap: () {
                        setState(() {
                          menuType = "profile";
                        });
                      },
                      child: Container(
                          margin: EdgeInsets.all(5.0),
                          child: Text(
                            getTranslated(context, "profile"),
                            style: TextStyle(
                                fontSize: menuType == "profile" ? 20.0 : 17.0,
                                color: menuType == "profile"
                                    ? Colors.black
                                    : Colors.black45,
                                fontWeight: FontWeight.bold,
                                fontFamily: "Gilroy"),
                          )),
                    ),
                    GestureDetector(
                      onTap: () {
                        setState(() {
                          menuType = "reviews";
                        });
                      },
                      child: Container(
                          margin: EdgeInsets.all(5.0),
                          child: Text(
                            getTranslated(context, "reviews"),
                            style: TextStyle(
                                fontSize: menuType == "reviews" ? 20.0 : 17.0,
                                color: menuType == "reviews"
                                    ? Colors.black
                                    : Colors.black45,
                                fontWeight: FontWeight.bold,
                                fontFamily: "Gilroy"),
                          )),
                    ),
                    GestureDetector(
                      onTap: () {
                        setState(() {
                          menuType = "recent";
                        });
                      },
                      child: Container(
                          margin: EdgeInsets.all(5.0),
                          child: Text(
                            getTranslated(context, "recent"),
                            style: TextStyle(
                                fontSize: menuType == "recent" ? 20.0 : 17.0,
                                color: menuType == "recent"
                                    ? Colors.black
                                    : Colors.black45,
                                fontWeight: FontWeight.bold,
                                fontFamily: "Gilroy"),
                          )),
                    )
                  ],
                ),
              ),
              ),
            ),
            menuType== "profile"? this.ProfileItems() : this.ReviewItems() : this.RecentItems(),
          ],
        ),
      ),
    );
  }
}

我是这样声明菜单类型的

final FirebaseAuth _auth = FirebaseAuth.instance;
  Firestore firestore = Firestore.instance;
  var _name, _uid, _phone, _language, _location, _image, menuType = "profile";
  Language language;

我无法显示3个标签。当我删除最近的小部件时,它开始显示.显示错误。

The following assertion was thrown building UserProfilePage(dirty, dependencies: [MediaQuery, _LocalizationsScope-[GlobalKey#47da7]], state: _UserProfilePageState#87b63):
A non-null String must be provided to a Text widget.
'package:flutter/src/widgets/text.dart':
Failed assertion: line 285 pos 10: 'data != null'


Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=BUG.md

The relevant error-causing widget was: 
  UserProfilePage file:///C:/Flutter/Naniz_eats/lib/main.dart:166:59
When the exception was thrown, this was the stack: 
#2      new Text (package:flutter/src/widgets/text.dart:285:10)
#3      _UserProfilePageState.build (package:econoomaccess/UserProfilePage.dart:708:34)
#4      StatefulElement.build (package:flutter/src/widgets/framework.dart:4334:27)
#5      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4223:15)
#6      Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
...
firebase flutter dart flutter-layout flutter-dependencies
1个回答
0
投票

似乎文本不存在于你的AppLocalization中,所以你应该像这样进行null检查。

String getTranslated(BuildContext context, String key) { 
   return AppLocalizations.of(context).translate(key) ?? "**text not found"; 
}
© www.soinside.com 2019 - 2024. All rights reserved.