type 'Null' is not a subtype of type 'List<int>' in type cast in flutter - flutter

I am having a strange problem. I don't think that there is any problem with the url of image. Problem happens when I restart the simulator
Update
It seems the the image is expired
How can I catch this exception?
I am just calling a network image
return CircleAvatar(
radius: 40.0,
backgroundImage: NetworkImage(
sessionControl.currentUser.value.picture),
backgroundColor: Colors.transparent,
);
Error log
Launching lib/main.dart on iPhone 13 in debug mode...
Xcode build done. 13.5s
Connecting to VM Service at ws://127.0.0.1:57758/38wgT4iPnbk=/ws
flutter: Check 1 : Is Amplify SetState set to true ? false
[GETX] Instance "GetMaterialController" has been created
[GETX] Instance "GetMaterialController" has been initialized
flutter: Check 1 : Is Amplify SetState set to true ? true
flutter: Session Sign In Status = true
flutter: Check 1 : Is Amplify SetState set to true ? true
[GETX] Instance "HomeController" has been created
[GETX] Instance "HomeController" has been initialized
flutter: Requested for pulling current user info
[GETX] Instance "SessionController" has been created
[GETX] Instance "SessionController" has been initialized
flutter: Printing session control picture :
flutter: Printing session control picture :
flutter: Printing session control picture : https://dontak4d751b4dd50548f1b4819e95919c2d17220339-oxlnewenv.s3.ap-southeast-2.amazonaws.com/public/Aaronimage_picker_29FADB72-2761-4BB9-89B0-9EFA849305BA-33481-0000009746CE94EE.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=%2F20210930%2Fap-southeast-2%2Fs3%2Faws4_request&X-Amz-Date=20210930T195105Z&X-Amz-Expires=17999&X-Amz-SignedHeaders=host&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEHQaDmFwLXNvdXRoZWFzdC0yIkYwRAIgJGnlBRuLiHfiSRjwIH8XnKYWqrmIPMfdOcchb8P878sCIBmI362NDDXenQUm%B8i30UG9uy0kucILDuxd3RreSTpb5HBJyUtJrvViYzy45XuHWjJ1WKEDxeAZdiDHEZPubnkkcGkcj0jdcaXtBP2OpR1cPT5MTWyv1dJ7mobezeRWvteSVzygA4Ot%2Fe5Yrf2ARLA3JDiIenmaxX7%2FAhvOUb0ppL9BocsAv0wojTSsdPvvQooRLqr%2FSjzEpDrVkHf7QOI50im9eBlk%2F8dKKERfwjIP41dyv1Wo5hyIc%2BfUmsXml0nRnluB<…>
flutter: Note: calling the network image
════════ Exception caught by image resource service ════════════════════════════
The following _CastError was thrown resolving an image codec:
type 'Null' is not a subtype of type 'List<int>' in type cast
When the exception was thrown, this was the stack
#1 NetworkImage._loadAsync
<asynchronous suspension>
(elided one frame from dart:async)
Image provider: NetworkImage("https://dontak4d751b4dd50548f1b4819e95919c2d17220339-oxlnewenv.s3.ap-southeast-2.amazonaws.com/public/Aaronimage_picker_29FADB72-2761-4BB9-89B0-9EFA849305BA-33481-0000009746CE94EE.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=%2F20210930%2Fap-southeast-2%2Fs3%2Faws4_request&X-Amz-Date=20210930T195105Z&X-Amz-Expires=17999&X-Amz-SignedHeaders=host&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEHQaDmFwLXNvdXRoZWFzdC0yIkYwRAIgJGnlBRuLiHfiSRjwIH8XnKYWqrmIPMfdOcchb8P878sCIBmItfJeejulE3fb0a7FgzSkedEkb8CrRxq%2BgeT47%2BJlaWUzJm6rC4r1%2F8Bc7T9aDqtYmNy1xlfVKr2D776gLFlWc3uMbwWeK3QQIRgb%2F0dMv4%2Bam4Z763as4v65nrs26%2B9S9U0XuII3V4M7pXDIspQwj%2B9Mq6sTsFwbYx0DMeCjVI96WAJdxuACAKJIgHR9DVaIHWI77IogWieRJPIH12quhZ%2F4GZr%2BfWvh8OL8Ak8feHTtcy%2FEQndGukUianBFEv2Erl7fc7VLdkLUZK1D40wa8Qlk1uH6Kt%2B36H%2FQNEIYRd%2FpzoyvSMuuhtDJ%2FfkQyvRv7TvJbCDzwibKom34sZyjK5yVc%3D&X-Amz-Signature=9537750a0fe8d32358f5461f305539147cbba13a1d337ee34b44f263d926da43", scale: 1.0)
Image key: NetworkImage("https://dontak4d751b4dd50548f1b4819e95919c2d17220339-oxlnewenv.s3.ap-southeast-2.amazonaws.com/public/Aaronimage_picker_29FADB72-2761-4BB9-89B0-9EFA849305BA-33481-0000009746CE94EE.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=%2F20210930%2Fap-southeast-2%2Fs3%2Faws4_request&X-Amz-Date=20210930T195105Z&X-Amz-Expires=17999&X-Amz-SignedHeaders=host&X-Amz-Security-Token=IQoJb3JpZ2luX2VjHBhOUPrHu25bSB2fUAlzezITPYaksWbJyrZD%2BTiUzRvD5T2CWSDifjtYYLJ9HVj06XupHwhNyNrAC3wiIG%2Fsy1c4%2FYIGKUQ%2BR8PO7le%2FyNNMVQdFGFJvzW9BBhgcwR6JQwAUpHYpFiWZ1ZeVmk0fTR%2FFU721Tc9M%2BsVdxhcDnZVOR4CtIMR5jbNKSRp3ambx75lgZJEXwQiKol0aSTDx6iGlKkKBPCucT4JlCu9m5wlAZSU8ejJbWbgWxxK6sP1rLVQTC2Erl7fc7VLdkLUZK1D40wa8Qlk1uH6Kt%2B36H%2FQNEIYRd%2FpzoyvSMuuhtDJ%2FfkQyvRv7TvJbCDzwibKom34sZyjK5yVc%3D&X-Amz-Signature=9537750a0fe8d32358f5461f305539147cbba13a1d337ee34b44f263d926da43", scale: 1.0)
════════════════════════════════════════════════════════════════════════════════
If I update the profile pic then it loads but after sometime it doesn't with above error. Can't understand why pls help.

You can use onBackgroundImageError to catch error
CircleAvatar(
radius: 40.0,
backgroundImage: NetworkImage(
sessionControl.currentUser.value.picture,
),
onBackgroundImageError: (exception,context) {
print('${sessionControl.currentUser.value.picture} Cannot be loaded');
print('Error msg : ${exception.toString()}');
},
backgroundColor: Colors.transparent,
),
and you can check if the provided URL working or not :
CircleAvatar(
radius: 40.0,
backgroundImage: NetworkImage(
'https://via.placeholder.com/120',
),
onBackgroundImageError: (exception,context) {
print('${sessionControl.currentUser.value.picture} Cannot be loaded');
},
backgroundColor: Colors.transparent,
),

Related

Loading image in Flutter | Path from content root doesn't work, but absolute path works

Very simple app, the image is in project/images folder.
When I try to load it from the relative path:
'images/diamond.png'
the image doesn't load.
When I do it from the absolute path: '/Users/MacBookAir/StudioProjects/secondtry_iamrich/images/diamond.png'
it does.
Why is this? Can anyone please help?
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
home: Scaffold(
backgroundColor: Colors.blueGrey,
appBar: AppBar(
title: const Text('I am Rich'),
backgroundColor: Colors.blueGrey[900],
),
body: const Center(
child: Image(
image: AssetImage('images/diamond.png'),
),
),
),
),
);
}
This is the error it is providing:
======= Exception caught by image resource service ================================================
The following assertion was thrown resolving an image codec:
Unable to load asset: images/diamond.png
When the exception was thrown, this was the stack:
#0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:237:7)
<asynchronous suspension>
#1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:658:14)
<asynchronous suspension>
Image provider: AssetImage(bundle: null, name: "images/diamond.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#99cb5(), name: "images/diamond.png", scale: 1.0)
====================================================================================================
Do not forgot to add image folder path to your pubspec.ymal folder like
assets:
- assets/images/
- assets/images/icons/
- assets/loader.json
Use this plugin in your android studio it will auto generate your all assets no need to write path.
Use it like this
Image.asset(Assets.imagesNoDataFound, scale: 3.5)
Uncomment and change the asset section in your pubspect.yaml file can fix it.
assets:
- images/

Why showcaseview throws error on first try?

Hey I am using ShowCaseView in my Flutterapp. When I first open my app, after registration there is no showcase, not even the icon which should be 'showcased' is shown. But when I am closing the app and opening it again it works just fine.
Thats the code referring to showcase:
class _HomeSearchPageState extends State<HomeSearchPage> {
final keyOne = GlobalKey();
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback(
(_) => ShowCaseWidget.of(context).startShowCase([
keyOne,
]),
);
}
And now the scaffold:
return Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(getTopBarSize()),
child: AppBar(
automaticallyImplyLeading: false,
title: Text(
'username',
style: TextStyle(fontSize: 14),
),
actions: <Widget>[
Showcase(
key: keyOne,
description: 'test',
child: IconButton(
icon: Icon(Icons.search),
onPressed: () {
showSearch(context: context, delegate: DataSearch())
.whenComplete(() => setName());
}),
),
],
),
),)
I did exactly the same as in the Github example but still it throws this error the first time:
════════ Exception caught by widgets library ═══════════════════════════════════
The following NoSuchMethodError was thrown building IconTheme(color: Color(0xffffffff)):
The getter 'activeWidgetIds' was called on null.
Receiver: null
Tried calling: activeWidgetIds
The relevant error-causing widget was
AppBar
lib\Views\HomeSearchPage.dart:182
When the exception was thrown, this was the stack
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1 ShowCaseWidget.activeTargetWidget
package:showcaseview/showcase_widget.dart:51
#2 _ShowcaseState.showOverlay
package:showcaseview/showcase.dart:171
#3 _ShowcaseState.didChangeDependencies
package:showcaseview/showcase.dart:164
#4 StatefulElement._firstBuild
package:flutter/…/widgets/framework.dart:4786
════════ Exception caught by rendering library ═════════════════════════════════
Each child must be laid out exactly once.
The relevant error-causing widget was
AppBar
lib\Views\HomeSearchPage.dart:182
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by scheduler library ═════════════════════════════════
Exception: Please provide ShowCaseView context
════════ Exception caught by widgets library ═══════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 6224 pos 12: '_children.contains(child)': is not true.
The relevant error-causing widget was
AppBar
lib\Views\HomeSearchPage.dart:182
════════════════════════════════════════════════════════════════════════════════
These errors are kind a looped, so the debug console shows them all the time.
The only difference between the first app opening and the second one is: In the first one the user enters a registrationpage and after this he enters the page with the showcaseview. In the second the user enters directly the page with the showcaseview. How can this affect the showcase and more accurate why does this throw the errors?
Not sure if we share a similar issue but maybe my answer will help you somehow :). The issue occurs when I navigate to the page where I have Showcase widget, but it does not occur when I navigate "back" to the page from the other page.
Maybe you can check this page "This error is thrown if you haven't wrapped your widget with ShowCaseWidget. This is not the problem with the package itself."
Thus, I tried raising the level of the ShowCaseWidget in the main.dart and the issue was solved.
void main() {
// runApp(MyApp());
runApp(
ShowCaseWidget(
autoPlay: false,
autoPlayDelay: Duration(seconds: 8),
autoPlayLockEnable: false,
builder: Builder(
builder: (context) => MyApp(),
),
onStart: (index, key) {
print('onStart: $index, $key');
},
onComplete: (index, key) {
print('onComplete: $index, $key');
},
),
);
}
So far the app still works well. I will report again here in case any issues occur.

Flutter and Google Sing in: Invalid image data

I have implemented Google Authentication with FlutterFire. I use the official package to sing in users.
However, if I navigate to a page where the user profile picture is seen and try to render the GoogleUserCircleAvatarar, although the page seems to be working just fine, I get an error in the console:
════════ Exception caught by image resource service ════════════════════════════════════════════════
Exception: Invalid image data
════════════════════════════════════════════════════════════════════════════════════════════════════
On the screen, it takes a few milliseconds, to load up the picture. Before it's loaded, I can see the placeholder image (First letter of the users initials on a filled background) next to the user's name and email address (so the currentUser is loaded) which transitions to the user profile picture. As I am using the recommended Widget, I am confused how should I prevent the error from happening.
Code:
if (widget.userService.currentUser != null) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
ListTile(
leading: GoogleUserCircleAvatar(
identity: widget.userService.currentUser,
),
title: Text(widget.userService.currentUser.displayName ?? ''),
subtitle: Text(widget.userService.currentUser.email ?? ''),
),
const Text("Signed in successfully."),
RaisedButton(
child: const Text('SIGN OUT'),
onPressed: _handleSignOut,
),
],
);
} else {
...
currentUser object is created with the official API:
currentUser = await GoogleSignIn().signIn();
and my pubspec.yml:
dependencies:
flutter:
sdk: flutter
cloud_firestore: ^0.14.0+1
provider: ^4.3.2+2
google_sign_in: "^4.5.1"
firebase_core: "^0.5.0+1"
firebase_auth: "^0.18.1+2"
This issue should've resolved on the latest version of the google_sign_in plugin. More details of the fix for the issue is discussed on this pull request.

Flutter/Dart copyCrop Function Exception: Could not instantiate image codec

I want to display a cropped Image in Flutter. I use the Image.memory Widget. When I use the orginal image there is no Problem.
var tempStore = await ImagePicker.pickImage(source: ImageSource.camera);
List<int> byteListe = await tempStore.readAsBytes();
image = dartimage.Image.fromBytes(400, 400, byteList);
But after I used the copyCrop() Function I get an Exception..
https://pub.dev/documentation/image/latest/image/copyCrop.html
cropImage = dartimage.copyCrop(image, 4, 0, 100, 100);
Expanded(
child: Container(
child: cropImage != null ? Image.memory(cropImage.getBytes()): Text('No Image'),
),
),
This is the Exception!
════════ Exception caught by image resource service ════════════════════════════════════════════════
The following _Exception was thrown while resolving an image:
Exception: Could not instantiate image codec.
When the exception was thrown, this was the stack:
#0 _futurize (dart:ui/painting.dart:4304:5)
#1 instantiateImageCodec (dart:ui/painting.dart:1682:10)
#2 PaintingBinding.instantiateImageCodec (package:flutter/src/painting/binding.dart:88:12)
#3 MemoryImage._loadAsync (package:flutter/src/painting/image_provider.dart:714:18)
#4 MemoryImage.load (package:flutter/src/painting/image_provider.dart:706:14)
...
Image provider: MemoryImage(_Uint8ArrayView#a573e, scale: 1.0)
Image configuration: ImageConfiguration(bundle: PlatformAssetBundle#c13af(), devicePixelRatio: 4.0, locale: de_DE, textDirection: TextDirection.ltr, platform: android)
Image key: MemoryImage(_Uint8ArrayView#a573e, scale: 1.0)
════════════════════════════════════════════════════════════════════════════════════════════════════

Exception caught by image resource service, The following assertion was thrown resolving an image codec:

I am trying to load an image into a scroll, but every time it does not load the image due to error:
Exception caught by image resource service The following assertion was thrown resolving an image codec:
Unable to load asset: assets/images/jorge.png
When the exception was thrown, this was the stack:
0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:464:44)
2 AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:449:14)
...
Image provider: AssetImage(bundle: null, name: "assets/images/jorge.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#dd41f(), name: "assets/images/jorge.png", scale: 1.0)
(2) Exception caught by image resource service
Unable to load asset: assets/images/heitor.png
(3) Exception caught by image resource service
Unable to load asset: assets/images/john.png
I/chatty ( 8763): uid=10206(com.festapp.flutter_app_fest) identical 5 lines
E/AccessibilityBridge( 8763): VirtualView node must not be the root node.
flutter clean was used, besides exchanging images
final User currentUser = User(
id: 0,
name: 'Current User',
imageUrl: 'assets/images/greg.png'
);
//usuários
final User Jorge = User(
id: 1,
name: 'Jorge',
imageUrl: 'assets/images/jorge.png'
);
final User John= User(
id: 2,
name: 'John',
imageUrl: 'assets/images/john.png'
);
final User Heitor = User(
id: 3,
name: 'Heitor',
imageUrl: 'assets/images/heitor.png'
);
final User Gui = User(
id: 4,
name: 'Gui',
imageUrl: 'assets/images/heitor.png'
);
and images use in:
return Padding(
padding: EdgeInsets.all(10.0),
child: Column(
children: <Widget>[
CircleAvatar(
radius: 35.0,
backgroundImage: AssetImage(favorites[index].imageUrl),
),
SizedBox(
height: 6.0,
),
Text(favorites[index].name, style: TextStyle(
color: Colors.blueGrey,
fontSize: 16.0,
fontWeight: FontWeight.w600,
),
),
],
),
);
Exception caught by image resource service
The following assertion was thrown resolving an image codec:
Unable to load asset: assets/images/jorge.png
When the exception was thrown, this was the stack:
0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:464:44)
2 AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:449:14)
...
Image provider: AssetImage(bundle: null, name: "assets/images/jorge.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#dd41f(), name: "assets/images/jorge.png", scale: 1.0)
(2) Exception caught by image resource service
Unable to load asset: assets/images/heitor.png
(3) Exception caught by image resource service
Unable to load asset: assets/images/john.png
It seems that these image files aren't in your project:
assets/images/jorge.png
assets/images/john.png
assets/images/heitor.png
Make sure you are doing these things:
Add the images in the folder assets/images/
Specify the images in pubspec.yaml
Execute flutter packages get / tap Packages get from
pubspec.yaml / tap Get dependencies from any dart file.
Use Image.asset() or AssetImage() to show them.
i also faced the same issue,
the solution is to stop the main.dart -by clicking the red button given in taskbar
and then restart it.
sometime its not able to load the images when you add it as fresh
To solve this error, you should check your pubspec.yaml file, either the asset folder is indexed like below or not:
flutter:
[2 whitespaces or 1 tab]assets:
[4 whitespaces or 2 tabs]- assets/images/ #index all files inside images folder
[4 whitespaces or 2 tabs]- assets/images/elephant.jpg #index only elephant.jpg