更改底部导航栏后,Flutter UI 未更新

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

我正在尝试从本地 json 数据文件检索所有子章节列表并将其传递到我的搜索屏幕。

我可以为 Chapter 执行此操作,但 SubChapter 是嵌套的,所以我不确定如何执行此操作。任何帮助或建议将非常感激。

我的本地 json 数据看起来像这样

{
        "id": 1,
        "bookClass": "Book Name",
        "bookChapters": [
            {
                "chapterId": 1,
                "chapterName": "Chapter 1 Name",
                "chapterPageNumber": 20,
                "chapterReadingTime": 4,
                "subChapter": [
                    {
                        "subTitle": "SubChapter Name",
                        "subpageNumber": 1,
                        "subChapterReadingTime": 5
                    }
                ]
            }
        ]
}    

  Widget build(BuildContext context) {
    var size = MediaQuery.of(context).size;
    final mainController = provider.Provider.of<MainController>(context);

//Chapter is working fine
    final allChapters = mainController.booksItems
        .map((book) => book.bookChapters ?? [])
        .expand((chapters) => chapters)
        .toList();

//not sure what to do here to get all SubChapters
    final allSubChapter = mainController.booksItems
        .map((book) => book.bookChapters.subChapter! ?? [])
        .expand((subchapters) => subchapters)
        .toList();

....

             onPressed: () {
                    Navigator.push(
                      context,
                      MaterialPageRoute(
                          builder: (context) => SearchScreen(
                                allChapters: allChapters,
                                allSubChapters: [],  //not sure what to do here to pass the data
                              )),
                    );
                  },
flutter dart flutter-dependencies flutter-animation
1个回答
0
投票

重新启动应用程序 不要进行热重载

© www.soinside.com 2019 - 2024. All rights reserved.