我在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'),
),
],
),
)
);
}
}
1条答案
按热度按时间yh2wf1be1#
从所显示的
questionChoices
的结构可以看出,它是Map
的List
。