首页 > 解决方案 > 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(),
              );
            },
          ),
        ),
      ),
    );
  }
}

标签: flutterdartgoogle-cloud-firestore

解决方案


推荐阅读