简体   繁体   English

颤动中的 AppBar

[英]AppBar in flutter

I have designed a news application in flutter where I have an app bar with tabs following it.我在 Flutter 中设计了一个新闻应用程序,其中有一个带有标签的应用栏。 In the tabbarview I have a list of news.tabbarview我有一个新闻列表。 on click of the news, it will show details description and image of the news(as shown in the image).点击新闻,将显示新闻的详细描述和图片(如图所示)。 When I try to put the app bar in that file.当我尝试将应用栏放在该文件中时。 Two app bar appears.出现两个应用栏。 What would the possible way sort it out?可能的方法是什么?

在此处输入图片说明

Here is the code:这是代码:

appBar: AppBar(
            title: Text(""),
            backgroundColor: Color(0xFF125688), //#125688 //FFFF1744
            actions: <Widget>[
              Container(
                alignment: Alignment.topRight,
                child: FlatButton(
                    onPressed: () {},
                    padding: EdgeInsets.fromLTRB(0, 10.0, 8.0, 0),
                    child: Text(
                      date,
                      style: TextStyle(
                        color: Colors.white,
                      ),
                    )),
              )
            ],
            bottom: TabBar(
              tabs: <Widget>[
                Tab(text: "TOP-HEADLINES"),
                Tab(text: "LATEST-NEWS"),
                Tab(text: "SPORTS"),
                Tab(text: "CRIME-NEWS"),
              ],
              isScrollable: true,
            ),
          ),
          body: TabBarView(children: [
            TopHeadlines(),
            LatestNews(),
            Sports(),
            CrimeNews(),
              ],
            ),

CODE FOR TOPHEADLINES() TOPHEADLINES 代码()

class TopHeadlines extends StatefulWidget {
  int index;
  String value_image,value_description,value_title;


  TopHeadlines({Key key,this.value_image,this.value_description,this.value_title,this.index}) : super(key:key);
  @override
  _topHeadlines createState() => _topHeadlines();


}

class _topHeadlines extends State<TopHeadlines> {
  List<News> dataList = List();
  bool _isLoading = false;
  BuildContext context1;


  Future<String> loadFromAssets() async {
    DateTime oops = DateTime.now();
    String d_date = DateFormat('ddMMyyyy').format(oops);


    var url = 'https://www.example.com/json-12.json';


    print(url);
    var response = await http
        .get('$url', headers: {"charset": "utf-8", "Accept-Charset": "utf-8"});
    String utfDecode = utf8.decode(response.bodyBytes);

    return utfDecode;
  }

  Future loadyourData() async {
    setState(() {
      _isLoading = true;
    });

    String jsonString = await loadFromAssets();

    String newStr = jsonString.substring(1, jsonString.length - 1);

    print(newStr);
    Map newStringMap = json.decode(newStr);
    var list = new List();
    newStringMap.forEach((key, value) {
      list.add(value);
    });

    for (var newsList in list) {
      var news = News.fromJson(newsList);
      dataList.add(news);
    }
    print('This is the length' + dataList.length.toString());
    print(dataList[0].title);
    setState(() {
      _isLoading = false;
    });
  }

  @override
  void initState() {
    super.initState();

    loadyourData();
  }

  @override
  Widget build(BuildContext context) {
    DateTime oops = DateTime.now();

    return MaterialApp(
        debugShowCheckedModeBanner: false,
        home: Container(
          child: _isLoading ? Center(
            child: CircularProgressIndicator(),) :
          ListView.builder(
            itemCount: dataList.length, itemBuilder: (context, index) {
            return SizedBox(
                          height: 130.0,
                          child: Card(
                            color: Colors.white,
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: <Widget>[
                                InkWell(
                                  onTap: (){
                                 //   dataList;
                                      Navigator.push(context, MaterialPageRoute(builder: (context) {
                                        print(index);
                                        return Newsdetail(value_image: dataList[index].image,value_description: dataList[index].description,value_title: dataList[index].title, );
                                    }));
                                  },
                                  child: Padding(
                                    padding: const EdgeInsets.all(8.0),
                                    child: Row(
                                      children: <Widget>[
                                        Expanded(
                                            child: Image.network(
                                              dataList[index].image,
                                              height: 92.5,
                                              width: 75.0,
                                            )),
                                        Expanded(
                                          child: Text(
                                            dataList[index].title,
                                            style: TextStyle(
                                              //title
                                              fontSize: 15.0, color: Colors.grey,
                                            ),
                                          ),
                                        )
                                      ],
                                    ),
                                  ),
                                ),
                              ],
                            ),
                          ),
                        );
                },
            ),
    ));
  }
}

Remove the appBars from these views:从这些视图中删除 appBars:

TopHeadlines(),
LatestNews(),
Sports(),
CrimeNews(),

Only return the Content you want to display by return a Container or the widget you want to display仅通过返回容器或要显示的小部件来返回要显示的内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM