flutter - Flutter 通过 Firestore 参考
问题描述
我按照这个视频https://www.youtube.com/watch?v=WuYOGBEEOEOo将 FireStore 添加到我的应用程序中。它工作得很好,我能够在卡内显示我的 FireStore 的内容。现在我用多个文本制作了另一个页面。如何在卡片印刷机上获取 FireStore 参考并将其传递到另一个页面以在新页面中显示它的信息 Text's
这是我的代码:
class FacultyPage extends StatefulWidget {
const FacultyPage({Key? key}) : super(key: key);
@override
_FacultyPageState createState() => _FacultyPageState();
}
class _FacultyPageState extends State<FacultyPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: MainTheme.lightTheme.primaryColor,
automaticallyImplyLeading: true,
title: Text('Факультеты',
textAlign: TextAlign.center,
style: MainTheme.lightTheme.textTheme.headline2),
actions: [],
centerTitle: false,
elevation: 4,
),
drawer: Drawer(
elevation: 16,
child: NavigationDrawer(),
),
body: SafeArea(
child: Center(
child: StreamBuilder(
stream:
FirebaseFirestore.instance.collection('faculty').snapshots(),
builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) {
return Center(child: CircularProgressIndicator());
}
return ListView(
children: snapshot.data!.docs.map((faculties) {
return Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
color: MainTheme.lightTheme.primaryColor,
child: InkWell(
onTap: () {},
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.all(8),
child: Image(
image: NetworkImage(faculties['facultyIcon']),
width: MediaQuery.of(context).size.width * 0.28,
height: MediaQuery.of(context).size.height * 0.15,
fit: BoxFit.fill,
),
),
Expanded(
child: Padding(
padding: EdgeInsets.fromLTRB(0, 8, 8, 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
faculties['facultyName'],
style: MainTheme
.lightTheme.textTheme.headline5,
textAlign: TextAlign.center,
),
SizedBox(height: 16),
Text(
faculties['decan'],
style: MainTheme
.lightTheme.textTheme.headline4,
textAlign: TextAlign.center,
),
],
),
),
),
],
),
),
);
}).toList(),
);
},
),
),
),
);
}
}
解决方案
推荐阅读
- java - 单击其他显示器时 Windows 退出全屏模式
- mongodb - 为什么“distinct”和“count”命令在 MongoDB 中的索引项上发生得如此缓慢?
- arrays - 如何将数组中的数字相加
- r - 如何在ggplot2 geombar中打印最上面的y轴刻度
- c - 如何编写一个程序,让用户输入尽可能多的字符串并计算出现次数?
- csv - 如何将 CSV 附件附加到现有的 Google 表格
- assembly - 将 16 位复制到内存位置
- python - 如何将python3命令更改为python
- azure - 带有转义特殊字符的 Azure 搜索自动完成
- julia - 这个 Julia 函数有什么问题?