Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter does not work anymore after upgrading

Tags:

flutter

dart

My project was working perfectly and Just today i have upgrade my Flutter then everything start going run.

At the bottom is the error they give me. Please help me.

file:///Users/macbook/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/animated_background-1.0.4/lib/image_helper.dart:17:30: Error: The argument type 'dynamic Function(ImageInfo, bool)' can't be assigned to the parameter type 'ImageStreamListener'.
 - 'ImageInfo' is from 'package:flutter/src/painting/image_stream.dart' ('file:///Users/macbook/Documents/flutter/packages/flutter/lib/src/painting/image_stream.dart').
 - 'ImageStreamListener' is from 'package:flutter/src/painting/image_stream.dart' ('file:///Users/macbook/Documents/flutter/packages/flutter/lib/src/painting/image_stream.dart').
Try changing the type of the parameter, or casting the argument to 'ImageStreamListener'.
    newStream.removeListener(listener);
                             ^
file:///Users/macbook/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/animated_background-1.0.4/lib/image_helper.dart:20:25: Error: The argument type 'dynamic Function(ImageInfo, bool)' can't be assigned to the parameter type 'ImageStreamListener'.
 - 'ImageInfo' is from 'package:flutter/src/painting/image_stream.dart' ('file:///Users/macbook/Documents/flutter/packages/flutter/lib/src/painting/image_stream.dart').
 - 'ImageStreamListener' is from 'package:flutter/src/painting/image_stream.dart' ('file:///Users/macbook/Documents/flutter/packages/flutter/lib/src/painting/image_stream.dart').
Try changing the type of the parameter, or casting the argument to 'ImageStreamListener'.
  newStream.addListener(listener);
                        ^
file:///Users/macbook/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/animated_background-1.0.4/lib/image_helper.dart:21:41: Error: The argument type 'dynamic Function(ImageInfo, bool)' can't be assigned to the parameter type 'ImageStreamListener'.
 - 'ImageInfo' is from 'package:flutter/src/painting/image_stream.dart' ('file:///Users/macbook/Documents/flutter/packages/flutter/lib/src/painting/image_stream.dart').
 - 'ImageStreamListener' is from 'package:flutter/src/painting/image_stream.dart' ('file:///Users/macbook/Documents/flutter/packages/flutter/lib/src/painting/image_stream.dart').
Try changing the type of the parameter, or casting the argument to 'ImageStreamListener'.
  return () => newStream.removeListener(listener);
                                        ^
Compiler failed on /Users/macbook/AndroidStudioProjects/alimmentation/lib/main.dart
Finished with error: Gradle task assembleDebug failed with exit code 1
like image 221
BriscoPeas Aristide Avatar asked Mar 04 '23 22:03

BriscoPeas Aristide


2 Answers

Solved a similar issue by replacing

/*...*/.addListener((ImageInfo image, bool synchronousCall) { /*...*/ });

with

import 'package:flutter/painting.dart';

/*...*/.addListener(new ImageStreamListener((ImageInfo image, bool synchronousCall) { /*...*/ }) as ImageStreamListener);
like image 51
lastant Avatar answered Mar 11 '23 06:03

lastant


I had the same problem, here is some code only as an example

Code that broke:

var sunImage = new NetworkImage(incident.mobileSignature[0].uriFile,
          headers: AuthenticationService.getAuthHeaders());
sunImage.obtainKey(new ImageConfiguration()).then((val) {
    var load = sunImage.load(val);
    load.addListener((listener, err) async {
        ByteData data = await listener.image.toByteData(format:ui.ImageByteFormat.png);
        setState(() => this.signatureImage = data);
    });
  });
}

The code broke on line load.addListener((listener, err) async { ....

I solved creating an ImageListener function that does the same as my previous function with the listener variable. And then create an ImageStreamListener that receives this ImageListener as parameter. Note also that you can send as parameters onError and onChunk to the ImageStreamListener.

var sunImage = new NetworkImage(incident.mobileSignature[0].uriFile,
          headers: AuthenticationService.getAuthHeaders());
sunImage.obtainKey(new ImageConfiguration()).then((val) {
    var load = sunImage.load(val);
    ImageListener imageListener = (ImageInfo imageInfo, syncCall) async {
        ByteData data =
              await imageInfo.image.toByteData(format: ui.ImageByteFormat.png);
          setState(() => this.signatureImage = data);
    };
    ImageStreamListener listenerStream = new ImageStreamListener(imageListener);
    load.addListener(listenerStream, onError: ...., onChunk: ......); // These last parameters are optional
});
like image 42
Mauricio Pastorini Avatar answered Mar 11 '23 05:03

Mauricio Pastorini