我想检查 Firebase 集合中是否存在特定文档。据此,我的应用程序应该显示一个彩色图标或灰色图标。我试图用一种方法来解决这个问题,它返回一个布尔值。在我的 Build Widget 中,我调用该方法并分配正确的图标。
这是我检查文档是否存在的方法:
checkIfLikedOrNot(reference) async{
DocumentSnapshot ds = await reference.collection("likes").document(currentUser.uid).get();
print(ds.exists);
return ds.exists;
}
Run Code Online (Sandbox Code Playgroud)
打印在控制台中显示了正确的值,但我的构建小部件似乎忽略了一个事实,即布尔值为 true 并始终返回应该在集合中没有文档时显示的图标。
这是我的构建小部件的一部分:
GestureDetector(
child: checkIfLikedOrNot(list[index].reference) == true
?
Icon(
Icons.favorite,
color: Colors.red,
)
:
Icon(
FontAwesomeIcons.heart,
color: null,
),
)
Run Code Online (Sandbox Code Playgroud)
这个说法哪里有问题?有任何想法吗?
conditional-statements firebase flutter google-cloud-firestore
I am using React Helmet in my React Application (CRA) to boost up my SEO. The App does not use SSR! I want to keep the client side rendering.
\nMy current set up is as follows:
\n<title> </title>
from index.html
<noscript> </noscript>
from index.html
Added to my App.js
(here my React Router is set up):
<Helmet> <title>VOYD Fabrics | Streetwear Online | Keine Versandkosten</title> <meta name="description" content="Willkommen bei VOYD Fabrics. Wir …
每当我的 GetX 状态发生变化时,如何调用无状态小部件中的特定函数?例如,每当我的底部导航栏的索引发生变化时,如何触发事件?
Obx(
() =>
BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.explore),
label: 'Erkunden',
),
],
currentIndex: bottomNavigationController.index.value,
onTap: (index) {
bottomNavigationController.changeIndex(index);
},
)
),
Run Code Online (Sandbox Code Playgroud)
编辑:
class BottomNavigationController extends GetxController {
RxInt index = 0.obs;
void changeIndex(int val) {
index.value = val;
}
}
Run Code Online (Sandbox Code Playgroud) 我想将一个项目添加到列表中:
void submitAll() async {
List<UserSearchItem> userSearchItems = [];
Firestore.instance
.collection('insta_users')
.snapshots()
.listen((data) =>
data.documents.forEach((doc){
print(data.documents.length);
User user = new User.fromDocument(doc);
UserSearchItem searchItem = new UserSearchItem(user);
userSearchItems.add(searchItem);
print(user.bio);
}));
print("Loaded");
print(userSearchItems.length);
}
Run Code Online (Sandbox Code Playgroud)
但是如果我将列表的长度打印到控制台,它总是说,列表长为0 ...
print(userSearchItems.length);
Run Code Online (Sandbox Code Playgroud)
有任何建议吗?
最好的祝福
我正在尝试从我的 flutter 应用程序构建一个 apk。\n我正在使用 algolia 本机 api 并根据此官方文档修改了我的 FlutterActivity ( https://www.algolia.com/doc/guides/building-search-ui/入门/操作方法/flutter/android/)如下:
\nclass MainActivity: FlutterActivity() {\n\nval algoliaAPIAdapter = AlgoliaAPIFlutterAdapter(ApplicationID("****"), APIKey("*********************"))\n\n override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {\n super.configureFlutterEngine(flutterEngine)\n MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "com.algolia/api").setMethodCallHandler { call, result ->\n algoliaAPIAdapter.perform(call, result)\n }\n }\n}\n
Run Code Online (Sandbox Code Playgroud)\n不幸的是构建抛出以下错误:
\ne: /Users/martinseubert/development/flutter/.pub-cache/hosted/pub.dartlang.org/twitter_login-4.1.0/android/src/main/kotlin/com/maru/twitter_login/TwitterLoginPlugin.kt: (21, 8): \'public open fun onNewIntent(Intent): Boolean defined in com.maru.twitter_login.TwitterLoginPlugin\' clashes with \'protected/*protected and package*/ open fun onNewIntent(Intent): Unit defined in io.flutter.embedding.android.FlutterActivity\': return types are incompatible\ne: /Users/martinseubert/development/flutter/.pub-cache/hosted/pub.dartlang.org/twitter_login-4.1.0/android/src/main/kotlin/com/maru/twitter_login/TwitterLoginPlugin.kt: (21, 14): Cannot infer visibility for \'fun onNewIntent(p0: Intent): Boolean\'. …
Run Code Online (Sandbox Code Playgroud) 我想构建一个类似 instagram 的个人资料页面,其中当前用户的所有帖子都列在提要中。在此之上,应显示有关用户的一些信息(头像、粉丝数、帖子数、个人简介等)。用户应该能够滚动整个页面。目前页面只能滚动到我的 ListView.builder 中的 sizedBox-widget 的高度。就像这样:
ProfilePage类的构建方法如下所示:
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(),
body: ListView(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 25.0, top: 30.0),
child: Text(_user.displayName,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 20.0)),
),
...(all the other information for the "header-part")
postImagesWidget(),
])));}
Run Code Online (Sandbox Code Playgroud)
在postImagesWidget 中,我使用 ListView.builder 来构建提要:
Widget postImagesWidget(){
return FutureBuilder(
future: _future,
builder:
((context, AsyncSnapshot<List<DocumentSnapshot>> snapshot) {
if (snapshot.hasData) {
if (snapshot.connectionState == ConnectionState.done) {
return SizedBox(
height: …
Run Code Online (Sandbox Code Playgroud)