从上层打印出Flutter

zazmityj  于 2023-01-14  发布在  Flutter
关注(0)|答案(1)|浏览(117)

我在Supabase中有两个表,我想在flutter app中显示。一个是标题,另一个应该是用户的选择。但是我不知道如何打印出第二个表。肯定需要一些简单的东西。感谢帮助下面的例子给了我questioChoices的原始代码,但是我只想要words.

//List of question from database
  List? questList;
  Future<void> question() async {
    final response = await supabase
        .from('questionHeader')
        .select('''
        header, questionChoices (choices)
        ''')
        .order('id', ascending: true)
        .execute();

    setState(() {
      questList = response.data.toList();
    });
    print(questList);
  }
@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: const MyAppBar(
        title: 'Upptäck',
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [
            fullName != null ?
              Padding(
                padding: const EdgeInsets.only(left: 10, top: 15, right: 10),
                child: questList != null ?
                    ListView.builder(
                      shrinkWrap: true,
                      itemCount: questList?.length,
                      itemBuilder: (context, index) {
                          return Wrap(
                            children: [
                              Text((questList![index] ['header']).toString()),
                              Text((questList![index] ['questionChoices']).toString())
                            ],
                          );
                      }
                    )

                    : Text('No connection to database'),
              )

            :
            const Center(
              child: Text('No data'),
            ),
          ],
        ),
      )
    );
  }

}

yh2wf1be

yh2wf1be1#

从所显示的questionChoices的结构可以看出,它是MapList

Wrap(
  children: [
    Text(questList![index]['header']),
    ...(questList![index]['questionChoices'] as List)
        .map((item) => Text(item['choice']))
        .toList()
  ],
),

相关问题