English 中文(简体)
FadeInImage检测
原标题:Flutter FadeInImage Test
  • 时间:2024-04-21 11:13:58
  •  标签:
  • flutter
  • dart
The bounty expires in 7 days. Answers to this question are eligible for a +50 reputation bounty. anasqadrei wants to draw more attention to this question.

我曾试图为<代码>FadeInImage进行简单测试,但无uck。 我只想测试一下:<条码>k 透明度<>/条码>是否作为持有人出现。 之后,经过一段等待时间(约700米),《URL》的形象出现和k 透明 图像消失。

首先,我们需要使用<代码>HttpClient,以便显示网络形象。 我使用<代码>nock,但感到自己可以自由使用。

import  package:flutter/material.dart ;
import  package:flutter_test/flutter_test.dart ;
import  package:transparent_image/transparent_image.dart ;

void main() {
  testWidgets( Test FadeInImage , (tester) async {
    await tester.pumpWidget(FadeInImage.memoryNetwork(
      placeholder: kTransparentImage,
      image:  https://picsum.photos/id/28/200 ,
    ));

    // First: Solve for "provide your own HttpClient implementation" error

    // Second: Test for placeholder image (kTransparentImage)

    // Third: Wait until network image to appear

    // Forth: Test for network image (https://picsum.photos/id/28/200)
  });
}
问题回答

你们需要处理几个要点: 提供自己的<代码>HttpClient执行, 持照人形象测试(ktransulImage) 在网络形象出现之前,对网络形象进行测试。

通过这样做,你可以测试<代码>。 FadeInImage widget;

import  package:flutter/material.dart ;
import  package:flutter_test/flutter_test.dart ;
import  package:transparent_image/transparent_image.dart ;
import  package:http/http.dart  as http;

class MockHttpClient extends http.BaseClient {
  @override
  Future<http.StreamedResponse> send(http.BaseRequest request) async {
    return http.StreamedResponse(null, 200);
  }
}

void main() {
  testWidgets( Test FadeInImage , (tester) async {
    // Provide your own HttpClient implementation
    http.Client client = MockHttpClient();

    await tester.pumpWidget(MaterialApp(
      home: FadeInImage.memoryNetwork(
        placeholder: kTransparentImage,
        image:  https://picsum.photos/id/28/200 ,
        client: client,
      ),
    ));

    // Test for placeholder image (kTransparentImage)
    expect(find.byWidgetPredicate((widget) => widget is FadeInImage && widget.placeholder == kTransparentImage), findsOneWidget);

    // Wait for 700ms
    await Future.delayed(Duration(milliseconds: 700));

    // Test for network image (https://picsum.photos/id/28/200)
    expect(find.byWidgetPredicate((widget) => widget is FadeInImage && widget.image ==  https://picsum.photos/id/28/200 ), findsOneWidget);
  });
}




相关问题
Flutter App cannot be installed on Android TV

I m building a Flutter app that should support Android TV and Mobile devices. Despite Google Play shows that it is supported, I cannot install app on my MiBox device. While trying to install it, both ...

Moving the icon button to the right causes rendering issues

I am trying to align the icon button to the right of the Text field, I tried the row which made the icon button not centered vertically and now I am trying out the Stack widget. Here is my code - ...

热门标签