我正在开发一个使用 firebase 的 next.js 应用程序。我需要使用 firebase auth 包来限制对页面的访问。with-firebase-authentication 示例不显示多个页面的身份验证。
import React from 'react';
import Router from 'next/router';
import { firebase } from '../../firebase';
import * as routes from '../../constants/routes';
const withAuthorization = (needsAuthorization) => (Component) => {
class WithAuthorization extends React.Component {
componentDidMount() {
firebase.auth.onAuthStateChanged(authUser => {
if (!authUser && needsAuthorization) {
Router.push(routes.SIGN_IN)
}
});
}
render() {
return (
<Component { ...this.props } />
);
}
}
return WithAuthorization;
}
export default withAuthorization;
Run Code Online (Sandbox Code Playgroud) 我的架构中有以下实体。
我如何建模User和Post类型之间的一对多关系,其中Post可以是两种类型LinkPost或NormalPost.
我试图让一个圆圈看起来更物质。所以我想给它一个阴影,我如何在颤振中使用 Paint 类来做到这一点
thumbPaint = Paint()
..color = Colors.white,
..style = PaintingStyle.fill;
Run Code Online (Sandbox Code Playgroud) 通过一些混乱的源代码,发现了两种不同类型的导入。
两者之间有什么区别,哪个更好?
#1
import 'folder/filename.dart';
#2
import 'package:projectname/folder1/folder2/folder/filename.dart';
Run Code Online (Sandbox Code Playgroud) 我想在文本小部件中显示一个图标。我该怎么做呢 ?
以下代码仅显示 IconData
Text("Click ${Icons.add} to add");
Run Code Online (Sandbox Code Playgroud) 我正在从 firestore 查询一些文档。如何从快照对象获取用户信息。
用户 ID 和用户名等信息。
假设用户使用社交 OAuth 提供商登录。如果这很重要的话。
firebase.firestore().collection('sample').get()
.then(function(snapshot) {
console.log('SNAPSHOT', snapshot);
snapshot.forEach(function(doc) {
console.log(doc.exists);
console.log(doc);
console.log(doc.id);
console.log(doc.metadata);
console.log(doc.ref);
console.log(doc.data());
console.log(doc.ref.path);
console.log(doc);
})
}).catch(console.log);
Run Code Online (Sandbox Code Playgroud) 我有一个sqlite从中读取数据的数据库。我也有一个很长的小部件树。所以经过一番研究,我找到了providerFlutter 包。但是我不知道如何在扩展类中使用 FuturesChangeNotifier或如何在我的小部件树中的任何地方使用它?
class MyProvider with ChangeNotifier {
dynamic _myValue;
dynamic get myValue => _myValue;
set myValue(dynamic newValue) {
_myValue = newValue;
notifyListeners();
}
MyProvider(){
loadValue();
}
Future<void> loadValue async {
myValue = await db.instance().getValue();
}
Future<void> refetch async {
myValue = await db.instance().newValue();
notifyListeners();
}
}
Run Code Online (Sandbox Code Playgroud) 我正在创建一个可能有两个或更多输入字段的基本表单。我应该为每个输入创建一个控制器,还是有办法为所有输入文本字段使用单个控制器。