小编Raj*_*kad的帖子

Flutter:从 firestore 延迟加载数据

注意:我已经看到了关于 ListView 的延迟加载的答案,但这些是针对自定义 API 的,而不是针对 firestore 数据库的!

我有一个书籍摘要应用程序,应用程序从我的Firebase/Firestore数据库中获取数据,然后使用包装ListView.builderStreamBuilder.

现在,我想延迟获取数据,我的意思是当用户滚动列表时,所需的数据会被加载,而不是立即加载数据然后延迟显示。

//The Widget used to display data:

Widget feed() {
  return Container(
    width: deviceWidth,
    height: deviceHeight / 3,
    child: StreamBuilder(
        stream: Firestore.instance
            .collection('feedItem')
            .orderBy('feedId', descending: true)
            .snapshots(),

        builder: (BuildContext context, AsyncSnapshot snapshot) {
          if (snapshot.hasData) {
            int totalLength = snapshot.data.documents.length;
            return ListView.builder(
              scrollDirection: Axis.horizontal,
              itemCount: totalLength > 10 ? 10 : totalLength,
              itemBuilder: (BuildContext context, int index) {
                return Container(
                  width: deviceWidth / 2.5,
                  child: GestureDetector( …
Run Code Online (Sandbox Code Playgroud)

asynchronous dart firebase flutter google-cloud-firestore

8
推荐指数
1
解决办法
8339
查看次数

如何减少颤振应用程序中的 Firestore 读取?

注意:我是 flutter、Android 和 Firebase 的新手。

所以,我有一个 logo Maker 应用程序,资产(PNG 图像)如脸、帽子等都保存在firestore数据库中。我的数据库中目前共有 71 个文档。

目前,我使用cached_network_image插件。使用此插件,图像对于单个用户将只读一次。因为从下一次图像将从缓存存储中检索。但是图片标题的检索还是个问题。

尽管如此,对于单个用户,我还是可以阅读大约 100 次!这是我的数据库的架构。

有点明显不同部分的不同集合,一个图像一个文档。 数据库架构

使用 StreamBuilder 检索数据,

代码 代码 2

有什么方法可以通过代码或更改数据库架构或其他方式来减少读取请求的数量?

android firebase flutter google-cloud-firestore

8
推荐指数
1
解决办法
805
查看次数

Flutter:如何获取 Firebase 身份验证凭据来更新电子邮件和密码

因此,在我的 flutter 应用程序中,我尝试添加更改电子邮件的功能。

我使用了 userData.updateEmail(email) 方法,但它给出了这个错误:

未处理的异常:PlatformException(ERROR_REQUIRES_RECENT_LOGIN,此操作很敏感,需要最近的身份验证。重试此请求之前请重新登录。,null)

在网上寻找解决方案时,我了解到,我需要通过以下方法重新验证用户: userData.reauthenticateWithCredential(credential)

但我找不到一种方法来将凭据传递给 reauthenticateWithCredential 方法。

一些代码片段(尽管我觉得它们是不必要的):

initUserData() async {
    FirebaseUser user = await FirebaseAuth.instance.currentUser();

    setState(() {
      userData = user;
    });
  }

updateEmail(String value) async {
    // value is the email user inputs in a textfield and is validated
    userData.updateEmail(value);

  }
Run Code Online (Sandbox Code Playgroud)

注意:我同时使用谷歌登录和密码电子邮件登录。

android firebase firebase-authentication flutter

7
推荐指数
2
解决办法
2万
查看次数

flutter导入android.support.annotation.NonNull

所以,我想在flutter中使用firebase_auth,但是我遇到了androidX.annotation.NonNull错误,我在android文件中做了一些更改,经过一番混乱之后我解决了这个错误,但是现在我得到了

错误

C:\Users\Dell\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.6.2+1\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:8: error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
                                 ^
C:\Users\Dell\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.6.2+1\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:538: error: cannot find symbol
    public void onComplete(@NonNull Task<AuthResult> task) {
                            ^
  symbol:   class NonNull
  location: class FirebaseAuthPlugin.SignInCompleteListener
C:\Users\Dell\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.6.2+1\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:558: error: cannot find symbol
    public void onComplete(@NonNull Task<Void> task) {
                            ^
  symbol:   class NonNull
  location: class FirebaseAuthPlugin.TaskVoidCompleteListener
C:\Users\Dell\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.6.2+1\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:576: error: cannot find symbol
    public void onComplete(@NonNull Task<ProviderQueryResult> task) {
                            ^
  symbol:   class NonNull
  location: class FirebaseAuthPlugin.ProvidersCompleteListener
C:\Users\Dell\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.6.2+1\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:175: error: cannot find symbol
                      public void onComplete(@NonNull Task<AuthResult> task) {
                                              ^
  symbol: class …
Run Code Online (Sandbox Code Playgroud)

android dart flutter androidx

6
推荐指数
1
解决办法
3134
查看次数

Flutter:与设备的连接丢失(生产应用)

在调试模式和上传到商店的应用程序中,当我第一次打开应用程序时,它崩溃了。虽然如果我再次打开它,一切正常。

I/zygote64(11974): Rejecting re-init on previously-failed class java.lang.Class<com.google.firebase.messaging.FirebaseMessagingService>: java.lang.IllegalAccessError: Class com.google.firebase.iid.zzb extended by class com.google.firebase.messaging.FirebaseMessagingService is inaccessible (declaration of 'com.google.firebase.messaging.FirebaseMessagingService' appears in /data/app/com.ved.mentor101app-AbvtNHTF_HGKeS2lffOLiw==/base.apk!classes3.dex)
Lost connection to device.

D/AndroidRuntime(11974): Shutting down VM
E/AndroidRuntime(11974): FATAL EXCEPTION: main
E/AndroidRuntime(11974): Process: com.ved.mentor101app, PID: 11974
E/AndroidRuntime(11974): java.lang.RuntimeException: Unable to instantiate service io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService: java.lang.ClassNotFoundException: Didn't find class "io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService" on path: DexPathList[[zip file "/data/app/com.ved.mentor101app-AbvtNHTF_HGKeS2lffOLiw==/base.apk"],nativeLibraryDirectories=[/data/app/com.ved.mentor101app-AbvtNHTF_HGKeS2lffOLiw==/lib/arm64, /data/app/com.ved.mentor101app-AbvtNHTF_HGKeS2lffOLiw==/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]

E/AndroidRuntime(11974):    Caused by: java.lang.IllegalAccessError: Class com.google.firebase.iid.zzb extended by class com.google.firebase.messaging.FirebaseMessagingService is inaccessible (declaration of 'com.google.firebase.messaging.FirebaseMessagingService' appears in /data/app/com.ved.mentor101app-AbvtNHTF_HGKeS2lffOLiw==/base.apk!classes3.dex)
E/AndroidRuntime(11974):        ... …
Run Code Online (Sandbox Code Playgroud)

android firebase flutter

6
推荐指数
1
解决办法
4032
查看次数

使用手势颤动可调整大小的容器

我想创建一个可调整大小的容器,用户可以使用水平拖动来调整其大小。

这个 Gif 可以解释这个要求:

在此输入图像描述

我尝试了 GestureDetector.horizo​​ntal 拖动,但结果相差甚远:

Container(
        color: primary,
        width: size.width,
        height: 40,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            GestureDetector(
              onHorizontalDragUpdate: (details) {
                final double newWidth;
                if (details.delta.dx > 0) {
                  // movement in positive direction
                  final newWidth = size.width + 1;

                  print(newWidth);
                  final updatedSize = Size(newWidth, size.height);

                  setState(() {
                    size = updatedSize;
                  });
                } else {
                  // movement in negative direction
                  final newWidth = math.max(size.width - 1, 5).toDouble();
                  print(newWidth);
                  final updatedSize = Size(newWidth, size.height);

                  setState(() {
                    size = …
Run Code Online (Sandbox Code Playgroud)

dart flutter flutter-layout flutter-animation

5
推荐指数
2
解决办法
3097
查看次数

Flutter无需手动许可即可获取用户的国家/地区

我有一个博客应用程序,我可以在其中编写全球业务内容以及一些特定国家/地区的内容。比如印度、印度尼西亚等的特别帖子。

这就是为什么我需要一种方法来查找用户来自哪个国家/地区以提供特定内容。

但是,我不想使用 GeoLocator 插件,因为它会询问用户位置。我只想要用户的国家/地区,而不是具体位置,但权限对话框没有指定,这可能会让用户担心为什么这个应用程序需要位置权限。这就是为什么我想要一种方法来获取用户的国家/地区,而无需隐式权限对话框询问其位置。

我尝试了以下方法,但没有一个给出确切的国家/地区名称。

import 'dart:io' show Platform;

String localeName = Platform.localeName;

// this returns language device is using which mostly comes us en_US so this is of no use


Locale myLocale = Localizations.localeOf(context);
// This returned the US as the country despite the App being opened and used in India.
Run Code Online (Sandbox Code Playgroud)

android geolocation flutter google-location-services flutter-dependencies

2
推荐指数
1
解决办法
4456
查看次数

Flutter 饼图 labelAccessorFn 不起作用

注意:我使用这个答案How to add label to pieChart flutter作为实现 labelAccessorFn 的参考。

我正在使用charts_flutter包在我的 flutter 应用程序中显示图表,据我所知,我们使用 labelAccessorFn 在饼图中显示标签,但在我的情况下它不起作用。

应用程序概述: 这是一款情绪检查应用程序,用户每天使用 5 种表情符号中的一种选择自己的心情,并在图表中显示表情符号与被选择的天数的数据。

图表文件(labelAccessorFn 在 addChartData 方法中定义):

import 'package:flutter/material.dart';
import 'package:charts_flutter/flutter.dart' as charts;
import '../models/mood_db.dart';
import 'dart:async';

class Mood {
  String _emoji;
  int _numOfDays; // this has to int bcz charts can't take future<int>
  charts.Color _color;

  Mood(this._emoji, this._numOfDays, this._color);
}

class MoodChart extends StatefulWidget {
  @override
  _MoodChartState createState() => _MoodChartState();
}

class _MoodChartState extends State<MoodChart> {
  DatabaseHelper _databaseHelper = DatabaseHelper(); …
Run Code Online (Sandbox Code Playgroud)

android dart flutter

0
推荐指数
1
解决办法
2539
查看次数