【发布时间】:2022-01-18 00:57:42
【问题描述】:
我是新来的颤振。我想从 firebase firestore 数据库中检索数据并将其显示在应用程序中。我的要求是在屏幕上以文本的形式显示数据。为了更好地理解,我附上了下面的代码。
注意:我已经在我的项目中配置了 firebase。
代码:
class dashboard extends StatefulWidget {
@override
_dashboardState createState() => _dashboardState();
}
// ignore: camel_case_types
class _dashboardState extends State<dashboard> {
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
int _selectedIndex = 0;
@override
Widget build(BuildContext context) {
MediaQueryData screen = MediaQuery.of(context);
final authService = Provider.of<AuthService>(context);
return Scaffold(
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 80.0, right: 250),
child: Center(
child: Container(
width: screen.size.width,
// height: 20.0,
decoration:
BoxDecoration(borderRadius: BorderRadius.circular(15.0)),
child: (const Text(
'I need the data retreievd from firebase firestore to be displayed here.',
textAlign: TextAlign.justify,
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.black),
)),
),
),
),
Padding(
padding: EdgeInsets.only(left: 300.0, top: 1.0),
child: IconButton(
icon: new Icon(Icons.account_circle, size: 30.0),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ProfilePage(),
),
);
},
),
),
Padding(
padding: EdgeInsets.only(left: 300.0, top: 5.0),
child: IconButton(
icon: const Icon(
Icons.notifications,
size: 25.0,
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Notifications(),
),
);
},
),
),
Padding(
padding: const EdgeInsets.only(top: 0.0),
child: Center(
child: Container(
width: 390,
height: 450,
decoration: BoxDecoration(
color: Colors.green.shade100,
borderRadius: BorderRadius.circular(10.0),
),
),
),
),
],
),
),
floatingActionButton: FloatingActionButton(onPressed: () async {
await authService.signOut();
}),
// : _children[_currentIndex],
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
backgroundColor: Colors.green[100],
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.book_online),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(Icons.read_more),
label: 'Settings',
),
BottomNavigationBarItem(
icon: Icon(Icons.account_circle),
label: 'Profile',
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.green[800],
onTap: _onItemTapped,
),
);
}
}
【问题讨论】:
标签: firebase flutter dart google-cloud-firestore mobile-application