我的应用程序有两种类型的用户:管理员和普通用户。我向管理员显示管理屏幕,向普通用户显示普通屏幕。所有用户都需要访问Provider model1。但只有 admin 需要 access model2。
我如何只能model2为管理员用户初始化?
例如:
class MyApp extends StatelessWidget {
final model1 = Model1();
final model2 = Model2();
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(builder: (_) => model1),
ChangeNotifierProvider(builder: (_) => model2),
],
child: MaterialApp(
Run Code Online (Sandbox Code Playgroud)
我想提出model2只在AdminScreen。但是,如果我这样做,其他管理页面将无法访问model2,Navigator.push因为它们不是AdminScreen.
感谢帮助!
我想使用provider( ChangeNotifierProvider) 和ChangeNotifier管理应用程序状态。但是我如何从另一个模型中的一个模型访问状态?
用例:在聊天应用程序中,一种用于存储用户信息的模型。其他模型使用用户信息(例如用户 ID)调用数据库(Firestore)并获取聊天数据流。
例如:
class Model1 extends ChangeNotifier {
final List<Item> items = [];
class Model2 extends ChangeNotifier {
//Access items from Model1 here
items;
Run Code Online (Sandbox Code Playgroud)
这可能吗?我不喜欢非常大的模型,因为很难维护。
??谢谢!
dart firebase flutter google-cloud-firestore flutter-packages
我正在尝试将 facebook 登录添加到 Flutter 应用程序。我正在使用flutter_facebook_login。但是当我尝试为 iOS 构建时出现错误:
Resolving dependencies of `Podfile`
[!] CocoaPods could not find compatible versions for pod "FBSDKLoginKit":
In Podfile:
flutter_facebook_login (from `.symlinks/plugins/flutter_facebook_login/ios`) was resolved to 0.0.1, which depends on
FBSDKLoginKit (= 4.39.1)
None of your spec sources contain a spec satisfying the dependency: `FBSDKLoginKit (= 4.39.1)`.
You have either:
* out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
* mistyped the name or version.
* not …Run Code Online (Sandbox Code Playgroud) 我需要Model2从homepageto传递 provider( )Page2以便当用户返回homepage( onWillPop) 我可以从 provider( Model2)进行 API 调用并更新homepage。
但是当我打电话时_onPaidBackPress(context)出现错误:
未处理的异常:错误:在此消费者小部件上方找不到正确的提供者
StatefulWidget 在主页:
@override
Widget build(BuildContext context) {
return ChangeNotifierProxyProvider<Model1, Model2>(
initialBuilder: (_) => Model2(),
builder: (_, model1, model2) => model2
..string = model1.string,
),
child: Consumer<Model2>(
builder: (context, model2, _) =>
...
await Navigator.push(
context,
new MaterialPageRoute(
builder: (BuildContext context) =>
new Page2(
context: context)));
Run Code Online (Sandbox Code Playgroud)
在第 2 页:
class Page2 extends StatefulWidget {
final BuildContext …Run Code Online (Sandbox Code Playgroud) 我正在制作设置页面,想要制作像 iOS 设置(灰色背景和白色瓷砖)。我尝试添加容器,以便可以向 ListTile 添加颜色,但总是出错。
有人知道如何在此处添加容器吗?
body: new SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Column(
children: <Widget>[
ListTile(
leading: Icon(
Icons.person,
color: Colors.grey,
),
title: Text("Account"),
trailing: Icon(Icons.keyboard_arrow_right),
),
Run Code Online (Sandbox Code Playgroud) 发送到 Sentry 的 Flutter Web 错误报告不可读,因为已缩小。
https://github.com/flutter/flutter/issues/37875 https://github.com/flutter/flutter/issues/16883#issue-316793104
我正在使用: https: //pub.dev/packages/sentry
如何使报告不缩小以便我可以阅读?
我已经实现了 Facebook 和 Google 登录。
但是 FireBase 文档说,如果同一用户首先注册 Facebook,然后尝试使用 Google(使用相同的电子邮件)登录,这将导致错误。
所以我按照 doc 并尝试配置帐户链接。
但我不知道该怎么做。
每次用户登录时我都应该尝试链接帐户吗?问题是我不知道用户是否已经通过其他身份验证提供商登录。
例如,原代码有:
谷歌:
void _signInWithGoogle() async {
final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
final GoogleSignInAuthentication googleAuth =
await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
final FirebaseUser user = await _auth.signInWithCredential(credential);
}
Run Code Online (Sandbox Code Playgroud)
Facebook:
void _signInWithFacebook() async {
final AuthCredential credential = FacebookAuthProvider.getCredential(
accessToken: _tokenController.text,
);
final FirebaseUser user = await _auth.signInWithCredential(credential);
}
Run Code Online (Sandbox Code Playgroud)
每次在_signInWithFacebook()and 中调用是正确的_signInWithGoogle():
user …Run Code Online (Sandbox Code Playgroud) 我有 Flutter 应用程序的开发和生产风格。
问题是开发和生产应用程序的标签和启动器是相同的,所以看不出区别。(实际上不能同时安装在设备上)
根据风味更改 Flutter 应用程序名称的简单方法是什么?
我知道可以通过修改 AndroidManifest.xml 和 Xcode info.plist 来更改应用程序标签和启动器。但这并不简单:必须在xml和plist文件中制作额外的文件以供参考。像这样修改有悖于 Flutter 的目的。
有人知道解决方案吗?
谢谢!
我需要获取snapshot元数据,以便检查写入 Firestore 是否成功。我查看源代码 ,发现有SnapshotMetadata和 boolean hasPendingWrites()。但我找不到如何实施。没有开源 dart 项目使用过它。
Firebase文档说可以使用:.onSnapshot/.addSnapshotListener来指定includeMetadataChanges: true。
但我需要确保在查询QuerySnapshot. 我用的query不是。streamaddSnapshotListener
像这样:
child: new FirestoreAnimatedList(
query: Firestore.instance.collection('Collection')
.orderBy('timestamp', descending: true)
.snapshots(),
padding: new EdgeInsets.all(8.0),
reverse: true,
itemBuilder: (_, DocumentSnapshot snapshot,
Animation<double> animation, int x) {
return new Chat(
snapshot: snapshot, animation: animation);
},
),
Run Code Online (Sandbox Code Playgroud)
我尝试指定:
query: Firestore.instance.collection('Collection')
.snapshots(includeMetadataChanges: true),
Run Code Online (Sandbox Code Playgroud)
但这是不可能的:
错误:未定义命名参数“includeMetadataChanges”。
我也尝试:
snapshot.getMetadata().hasPendingWrites()
Run Code Online (Sandbox Code Playgroud)
但给出错误:
错误:未为类“DocumentSnapshot”定义方法“getMetaData”。
有谁知道在 Flutter 中如何做到这一点?有可能吗?
我尝试了很长时间但找不到如何..帮助! …
dart firebase google-cloud-platform flutter google-cloud-firestore
我使用 ChangeNotifier 从 Stateful Widget 中提取一些逻辑到 Provider: class Model extends ChangeNotifier {...}
在我的有状态小部件中,我有:
if (mounted) {
setState(() {});
}
Run Code Online (Sandbox Code Playgroud)
如何检查 Widget 是否安装在模型中?
例如,我如何调用:
if (mounted) {
notifyListeners();
}
Run Code Online (Sandbox Code Playgroud)