小编Tom*_*652的帖子

如何防止缓存图片受到网络抖动的影响?

我已尝试以下所有方法Widget从网络加载图像:

  • Image.network()
  • CachedNetworkImage()

还有他们的ImageProvider

  • NetworkImage
  • CachedNetworkImageProvider

无法bool选择不缓存图像。我发现的唯一方法是加载ImageProvider类似的内容initState(),然后evict()立即调用。

我真的不知道这是否真的有效,或者这是否是最好的方法......

有什么方法可以阻止“本地”网络缓存吗?

dart flutter flutter-image

9
推荐指数
2
解决办法
7177
查看次数

从Map<dynamic,dynamic>获取Map<String,dynamic> flutter

我有下面的代码:

 Map<dynamic, dynamic> result = snapshot.value;
 Map<String, dynamic> data = Map<String, dynamic>();
 for (dynamic type in result.keys) {
    data[type.toString()] = result[type];
 }
 print(data);
 print(data.runtimeType);

Run Code Online (Sandbox Code Playgroud)

但数据类型是_InternalLinkedHashMap<String, dynamic>,我无法读取它的值,尽管我在上面做了丑陋的黑客攻击。

直接转换也不起作用:snapshot.value as Map<String, dynamic>抛出错误:'_InternalLinkedHashMap<Object?, Object?>' is not a subtype of type 'Map<String, dynamic>'

我需要有一个 Map<String,dynamic> 类型才能创建我的自定义类对象。

snapshot.value有一种动态类型,但它是一个返回实时数据库查询结果的 json 对象,并且没有关于如何将值检索到 Flutter 对象中的文档。

我已经尝试过这个答案,但我无法使用它,因为它jsonDecode()需要一个字符串作为参数。

dart firebase firebase-realtime-database flutter

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

处理图像/视频和导航器抖动的内存使用情况

抱歉提前发了这么大的帖子……

我的应用程序是一个与 Instagram 非常相似的社交网络。

图案

  1. 用户个人资料(包含缩略图列表,未播放视频)
  2. Navigator.push()选择照片(打开包含照片/播放视频的页面
  3. 选择另一个用户个人资料(例如在视频的评论中)
  4. 再次查看缩略图列表,然后发布照片 - 播放视频,等等......

这就像一个无限的“轮廓 - 进给”循环。按照这样的逻辑,在遇到错误之前,我使用 Navigator.push() 到达了大约 30 页OutOfMemory

Flutter 工具只是说lost connection to device,但我使用的越多Navigator,应用程序变得越迟缓,最终崩溃,所以我 99% 确定这是由于内存使用造成的。
这种情况 100% 发生,由于帖子列表中的滚动,或多或少会出现 1 页差异。

如果我不在图片/视频列表中滚动太多,则每个页面的内存使用量或多或少会增加 20MB。
我已经计划缩小我的图像,但这充其量只是推迟了问题的解决。

问题

  • OutOfMemory这种“无限页面”是否可能永远不会遇到异常?
  • 我知道有一个deactivate()方法StateFul Widgets可以在Navigator.push被调用后使用(dispose()没有被调用,因为我们没有从树中删除任何东西),也许应该在那里做一些工作?
  • 我应该做些什么来处理自己的Navigator堆栈吗?我不想打开pop()旧页面,因为我需要返回到第一个页面打开

在这种情况和这种逻辑下,这意味着如果我可能浏览 Instagram 中的 100 个页面,这也会以 100% 的速度崩溃。

我不确定是否有人会走那么远,也许这就是他们所指望的...如果没有办法阻止OutOfMemory,唯一的解决方案可能是延迟它,直到用户看到至少 100 个页面...

我在理论上找到了解决方法,但不确定这在代码中是否可能:

到目前为止我想到的唯一解决方案是允许用户访问push()一定数量的页面,并在Navigator堆栈中最多保留 20 …

dart flutter flutter-navigation

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

Android EditText 和 SearchView:主要区别是什么(设计除外)?

我需要在我的 Android 应用程序中实现一个搜索界面,该界面可以RecyclerView过滤ViewPager.

我已经实现了EditTextSearchView小部件并尝试查看差异。

我感兴趣的听众是:

   myEditText.addTextChangedListener(new TextWatcher() {

            public void afterTextChanged(Editable s) {}

            public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

            public void onTextChanged(CharSequence s, int start, int before, int count) {}
        });
Run Code Online (Sandbox Code Playgroud)

和 :

mySearchView.OnQueryTextListener() {
    @Override
    public boolean onQueryTextChange(String newText) {

        textView.setText(newText);
        return true;
    }

    @Override
    public boolean onQueryTextSubmit(String query) {
        textView.setText(query);
        return true;
    }
Run Code Online (Sandbox Code Playgroud)
  1. SearchView我是否缺少一些允许和不允许的重要功能EditText

  2. 有了这两个小部件,我可以使用单个“搜索视图”RecyclerView在内部进行搜索吗?ViewPager

我不想要一个ACTION_SEARCH或任何添加的搜索对话框视图。

提前致谢 …

android android-edittext android-viewpager searchview android-recyclerview

5
推荐指数
1
解决办法
5389
查看次数

Flutter RenderObject 断言失败

我遇到以下错误:

======== Exception caught by scheduler library =====================================================
The following assertion was thrown during a scheduler callback:
Updated layout information required for RenderIndexedSemantics#f51aa NEEDS-LAYOUT to calculate semantics.
'package:flutter/src/rendering/object.dart':
Failed assertion: line 2658 pos 12: '!_needsLayout'


Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.md

When …
Run Code Online (Sandbox Code Playgroud)

dart flutter flutter-sliver sliver-grid

5
推荐指数
1
解决办法
2233
查看次数

Flutter 推送通知应用程序背景:firebase_messaging

我想当我的应用程序在后台运行时显示推送通知。
我正在使用flutter_local_notifications包和firebase_messaging包。

当我的应用程序是后台时,推送通知与 firebase_messaging 配合得很好。
然而,下面的方法:

 // The following handler is called, when App is in the background.
 FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);
Run Code Online (Sandbox Code Playgroud)

RemoteNotification如果对象通过以下方式传递,则不会被调用RemoteMessage

Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  print('message from background handler');
  print("Handling a background message: ${message.messageId}");
  
  // If this is null, then this handler method is called
  RemoteNotification remoteNotification = message.notification; 

  showNotificationFromData(message.data);
}
Run Code Online (Sandbox Code Playgroud)

因此,我必须传递message.dataa 对象Map<String, dynamic>

firebaseMessagingBackgroundHandler我的问题是,当调用此处理程序方法时,我不再收到推送通知。

所以我一直在尝试使用该flutter_local_notification包来显示推送通知,但正如所说,它是“本地”的,因此它在前台工作正常,但显然不在后台(相同的代码,具有相同的数据没有显示在背景作为推送通知)。

问题 :

我需要调用firebaseMessagingBackgroundHandler处理程序来处理我的应用程序中的事件。那么当我的应用程序在后台时我可以做些什么仍然有推送通知吗?

谢谢

dart flutter firebase-cloud-messaging flutter-notification

5
推荐指数
1
解决办法
2596
查看次数

请求不包含本地化祖先的上下文的区域设置

我试图Locale在应用程序启动时获取用户手机的信息。

Widget我的方法中有这棵树runApp()

@override
  Widget build(BuildContext context) {
    return MaterialApp(
            locale: Locale(Localizations.localeOf(context).languageCode), // This crashes
            localizationsDelegates: [
              const LocalizationDelegate(), // My custom delegate to get translations
              CountryLocalizations.delegate,
              GlobalMaterialLocalizations.delegate,
              GlobalWidgetsLocalizations.delegate,
            ],
            supportedLocales: [
              Locale("en"),
              Locale("fr"),
            ],
            debugShowCheckedModeBanner: false,
            home: Scaffold(
              resizeToAvoidBottomInset: false,
              body: HomePage(),
            )
        );
}
Run Code Online (Sandbox Code Playgroud)

该线路locale: Locale(Localizations.localeOf(context).languageCode)导致崩溃:

Requested the Locale of a context that does not include a Localizations ancestor.
Run Code Online (Sandbox Code Playgroud)

我只是想将此区域设置绑定到我的区域设置,Delegate而无需在应用程序中进一步进行操作。
到目前为止,我locale: Locale("en")en.json我的LocalizationDelegate.

dart flutter

5
推荐指数
1
解决办法
2984
查看次数

如何使用云函数正确连接MongoDB?

我只想为每个运行 Cloud Functions 的实例连接一次 Atlas 集群。

这是我的实例代码:

const MongoClient = require("mongodb").MongoClient;

const client = new MongoClient("myUrl", {
  useNewUrlParser: true,
  useUnifiedTopology: true,
});

exports.myHttpMethod = functions.region("europe-west1").runWith({
  memory: "128MB",
  timeoutSeconds: 20,
}).https.onCall((data, context) => {
  console.log("Data is: ", data);
  client.connect(() => {
    const testCollection = client.db("myDB").collection("test");
    testCollection.insertOne(data);
  });
});
Run Code Online (Sandbox Code Playgroud)

我想避免client.connect()在每个函数调用中看起来确实太多了。

我想做这样的事情:

const MongoClient = require("mongodb").MongoClient;

const client = await MongoClient.connect("myUrl", {
  useNewUrlParser: true,
  useUnifiedTopology: true,
});

const db = client.db("myDB");

exports.myHttpMethod = functions.region("europe-west1").runWith({
  memory: "128MB",
  timeoutSeconds: 20,
}).https.onCall((data, context) => …
Run Code Online (Sandbox Code Playgroud)

mongodb node.js firebase google-cloud-platform google-cloud-functions

5
推荐指数
1
解决办法
2701
查看次数

应用程序终止时不会调用 Firebase 消息传递后台处理程序 (Flutter)

当应用程序终止时收到推送通知时,我试图更新我的扑动应用程序的应用程序徽章计数。

如果应用程序位于后台,Firebase 消息传递后台处理程序可以正常工作,但当应用程序终止时,Firebase 消息传递后台处理程序将无法工作。

我已阅读文档

在 iOS 上,如果用户从应用程序切换器中滑开应用程序,则必须再次手动重新打开应用程序,后台消息才能再次开始工作。

这是否意味着在 iOS 上无法使用 firebase 后台处理程序更新徽章计数(当然,通过您在处理程序中实现的逻辑,只需要调用处理程序)?

今天任何应用程序都会这样做,所以我想知道为什么 Firebase Messaging 无法实现这一点。

firebase flutter firebase-cloud-messaging

5
推荐指数
1
解决办法
2250
查看次数

Authenticate a GET request to Google Play Purchase API with service account python

I need to verify purchases of my android App from my AWS lambda in python.

I have seen many posts of how to do so and the documentation and here is the code I have written :

url = f"{google_verify_purchase_endpoint}/{product_id}/tokens/{token}"
response = requests.get(url=url)
data = response.json()
logging.info(f"Response from Google Play API : {data}")
Run Code Online (Sandbox Code Playgroud)

When I do so, it throws a 401 status code not allowed. Alright, I have created a service account to allow the request with OAuth, but how …

python android in-app-purchase google-api-python-client google-play-developer-api

5
推荐指数
1
解决办法
1027
查看次数