针对不同用户的不同内容
我一直在开发一个应用程序,用户可以在其中预订猫咪的毛发。我已经将应用程序连接到Firebase,用户可以在那里注册和登录应用程序。这就是问题所在,每次我使用不同的用户帐户登录时,其他用户的预订历史记录仍在那里。
?
?
如何为登录的不同用户制作不同的内容?因此,每个用户都可以拥有自己的内容。这是来自历史页面的代码。
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
class HistoryPage extends StatefulWidget {
static const String id = 'HistoryPage';
@override
_HistoryPageState createState() => _HistoryPageState();
}
class _HistoryPageState extends State<HistoryPage> {
final _firestore = Firestore.instance;
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(25.0, 68.0, 70.0, 25.0),
child: Text(
'History',
style: TextStyle(fontSize: 35.0),
),
),
Column(
children: <Widget>[
StreamBuilder<QuerySnapshot>(
stream: _firestore.collection('ReservationData').snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(),
);
}
final messages = snapshot.data.documents;
List<HistoryBox> historyWidgets = [];
for (var message in messages) {
final historyDate = message.data['Reservation Date'];
final historyTime = message.data['Reservation Time'];
final historyWidget =
HistoryBox(date: historyDate, time: historyTime);
historyWidgets.add(historyWidget);
}
return Column(
children: historyWidgets,
);
},
),
],
)
],
)),
);
}
}
class HistoryBox extends StatelessWidget {
final String date;
final String time;
HistoryBox({this.date, this.time});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 25.0),
child: Material(
elevation: 5.0,
child: Container(
child: Text(
'Date Reservation : \n $date and $time',
style: TextStyle(
fontSize: 20.0,
),
),
),
),
);
}
}
(更新版)
这是供用户注册的代码。
import 'package:flutter/material.dart';
import 'package:project_pi/screens/HomePage/home_page.dart';
import 'inputform_signup.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:modal_progress_hud/modal_progress_hud.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
class SignUpPage extends StatefulWidget {
static const String id = 'SignUpPage';
@override
_SignUpPageState createState() => _SignUpPageState();
}
class _SignUpPageState extends State<SignUpPage> {
final _firestore = Firestore.instance;
final _auth = FirebaseAuth.instance;
bool showSpinner = false;
String nama;
String email;
String password;
String phoneNumber;
@override
Widget build(BuildContext context) {
return Scaffold(
body: ModalProgressHUD(
inAsyncCall: showSpinner,
child: Form(
child: SafeArea(
child: Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'SIGN UP',
style: TextStyle(
fontSize: 28.0,
),
),
InputForm(
hint: 'Full Name',
hidetext: false,
onChanged: (value) {
nama = value;
},
),
InputForm(
hint: 'Email Address',
hidetext: false,
onChanged: (value) {
email = value;
},
),
InputForm(
hint: 'Phone Number',
hidetext: false,
onChanged: (value) {
phoneNumber = value;
},
),
InputForm(
hint: 'Password',
hidetext: true,
onChanged: (value) {
password = value;
},
),
InputForm(
hint: 'Confirm Password',
hidetext: true,
),
SizedBox(height: 15.0),
Container(
height: 45.0,
width: 270.0,
child: RaisedButton(
child: Text('SIGN UP'),
onPressed: () async {
setState(() {
showSpinner = true;
});
try {
final newUser =
await _auth.createUserWithEmailAndPassword(
email: email, password: password);
_firestore.collection('UserAccount').add({
'Email Address': email,
'Full Name': nama,
'Phone Number': phoneNumber,
});
if (newUser != null) {
Navigator.pushNamed(context, HomePage.id);
}
setState(() {
showSpinner = false;
});
} catch (e) {
print(e);
}
},
),
),
SizedBox(
height: 15.0,
),
Text('Have an Account?'),
SizedBox(
height: 7.5,
),
InkWell(
child: Text(
'SIGN IN',
style: TextStyle(
color: Colors.red,
),
),
onTap: () {
AlertDialog(
title: Text("Finish?"),
content: Text("Are you sure with the data?"),
actions: <Widget>[
FlatButton(onPressed: null, child: null)
],
);
},
),
],
),
),
),
),
),
),
);
}
}
这是已登录的当前用户的类
import 'package:flutter/material.dart';
import 'package:project_pi/screens/HomePage/homebutton.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:project_pi/screens/LiveMaps/live_maps.dart';
import 'package:project_pi/screens/LoginPage/HalamanLogin.dart';
import 'package:project_pi/screens/ReservationHistory/history_page.dart';
import 'package:project_pi/screens/ReservationPage/information_detail.dart';
class HomePage extends StatefulWidget {
static const String id = "HomePage";
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
final _auth = FirebaseAuth.instance;
FirebaseUser loggedInUser;
@override
void initState() {
super.initState();
getCurrentUser();
}
void getCurrentUser() async {
try {
final user = await _auth.currentUser();
if (user != null) {
loggedInUser = user;
}
} catch (e) {
print(e);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Expanded(
child: Container(
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(25.0, 68.0, 256.0, 47.0),
child: Text(
'Home',
style: TextStyle(fontSize: 35.0),
),
),
Center(
child: Column(
children: <Widget>[
HomeNavButton(
prefixIcon: Icons.date_range,
textbutton: 'Make Reservation',
onPressed: () {
Navigator.pushNamed(context, InformationDetail.id);
},
),
SizedBox(
height: 40.0,
),
HomeNavButton(
prefixIcon: Icons.list,
textbutton: 'Reservation History',
onPressed: () {
Navigator.pushNamed(context, HistoryPage.id);
},
),
SizedBox(
height: 40.0,
),
HomeNavButton(
prefixIcon: Icons.gps_fixed,
textbutton: 'Live Maps Track',
onPressed: () {
Navigator.pushNamed(context, LiveMaps.id);
},
),
SizedBox(
height: 40.0,
),
HomeNavButton(
prefixIcon: Icons.person,
textbutton: 'Account Profile',
onPressed: () {
FirebaseAuth.instance.signOut();
Navigator.pushNamed(context, HalamanLogin.id);
},
),
],
),
),
],
),
),
),
),
);
}
}
如何为每个当前登录的用户实现过滤,使其能够根据用户显示内容?
转载请注明出处:http://www.zhongtian365.com/article/20230526/1920989.html
随机推荐
-
针对不同类类型的并发生产者/消费者队列设计
我有两个线程在运行,生产者线程将具有不同类型的更新的并发队列(https://github.com/cameron314/readerwriterqueue.git)入队,另一个消费者线程将更新出队并根据更新类型执行不同的代码路径。这些更新...
-
针对不同组的加权ctable
我想计算几个组的加权交叉表。在摘要工具(https://cran.csiro.au/web/packages/summarytools/news/news.html)的新闻中提到,与stby()结合使用的ctable()也支持权重。然而,我...
-
针对不同的快照情况 我们该如何制定应对策略
作为站长,我们对于快照的一些神经质表现自然比较敏感,但是究竟什么样的表现才值得我们注意,究竟什么的表现又不值得我们大惊小怪呢? 对于快照,做过网站的朋友都能吐槽上两句。因为在建站的过程中,快照问题的出现总是能让我们胆战心惊。毕竟一...
-
Hibernate中的HQL查询针对不同的用户选择相同的结果集
我在JPA仓库中创建了一个名为findItemsByUser()的方法,并针对Item类开发了一个命名查询,如下所示:@NamedQuery(name = Item.findItemsByUser, query = SELECT ...
-
针对不同客户端的restful服务
我有一个后端restful服务,并希望将其用于2个不同的客户端(桌面和移动),具有不同的响应。我们需要为此创建两个不同的API吗?我们如何知道请求是从哪里发出的?
-
针对不同库存的用户的MongoDB数据结构
我想做一个小型的全栈home项目。如果项目结果良好,我想在申请工作时将其添加到我的投资组合中。我的计划是使用MERN堆栈来构建一个web应用程序,用户可以在其中创建自己的登录帐户,存储他们拥有的鲜花以及他们需要浇水的频率。创建浇水计划将是下...
-
针对不同iPhone大小的UI资产分辨率,包括iPhone 6+、iPhone X、iPhone Max
我正在开发一个应用程序,应该可以在所有最新的iPhone型号上运行,包括iPhone X,iPhone XR,iPhone 8 plus等。然而,我对3x图像的尺寸感到困惑,因为我在谷歌上搜索了一下,我得到了3种不同尺寸的iPhone X:...
-
针对不同的gradle任务有不同的Android lintOptions
我想在本地(IDE)和CI上运行Android Lint。我有一个这样的任务,当在CI上运行时,我希望abortOnError作为true,但当在本地运行时,我希望false。task lintCI { outputs.upToDateW...
-
针对不同的屏幕大小调整网格视图的大小
我们有一个3列11行的网格视图,其中包含文本视图,网格视图嵌套在相对布局中。当我在Nexus5X 5.2in fit perfect上渲染活动时。当网格视图在NexusS4英寸屏幕上渲染时,fit不会调整大小。所以我的问题是,我是否只需要G...
-
针对不同的助剂更换流体为拾取器
两个不同的代理进入一个队列,每个代理具有不同的容量。我希望流体拾取值根据从队列中拉出的代理进行更新。我已经尝试在流体拾取区域中放置一个条件语句(如果为agentOne,则为55000,否则为70000),但没有成功。