I've tried everything from every modification of the pubspec.yaml file, flutter clean, updating flutter and my IDE (Android Studio). Nothing seems to be working.
Building a money tracker app in the case that no transactions are on the page the image displays.
Path of image file:
lib/assets/images/waiting.png
Code:
return Container(
height: 300,
child: transactions.isEmpty
? Column(
children: <Widget>[
Text(
'No Transactions yet',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20.0,
),
),
Container(
height: 200,
child: Image.asset(
'assets/images/waiting.png',
fit: BoxFit.cover,
),
),
],
)
: ListView.builder(
itemBuilder: (context, index) {
return Container(
margin: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
padding: EdgeInsets.all(3.0),
decoration: BoxDecoration(
gradient: LinearGradient(colors: _txColors),
border: Border.all(color: Colors.grey, width: 2.0),
borderRadius: BorderRadius.all(
Radius.circular(15.0),
),
color: Colors.greenAccent,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Container(
child: Text(
'\$${transactions[index].amount.toStringAsFixed(2)}',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20.0,
color: Colors.white,
// Color(0xffC5CED4),
),
),
),
Pubspec.yaml:
flutter:
uses-material-design: true
assets:
- assets/images/
Error:
I/flutter ( 5679): ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
I/flutter ( 5679): The following assertion was thrown resolving an image codec:
I/flutter ( 5679): Unable to load asset: assets/images/waiting.png
I/flutter ( 5679):
I/flutter ( 5679): When the exception was thrown, this was the stack:
I/flutter ( 5679): #0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
I/flutter ( 5679): <asynchronous suspension>
I/flutter ( 5679): #1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:664:31)
I/flutter ( 5679): #2 AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:648:14)
I/flutter ( 5679): #3 ImageProvider.resolveStreamForKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:501:13)
I/flutter ( 5679): #4 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:359:22)
I/flutter ( 5679): #5 ImageProvider.resolveStreamForKey (package:flutter/src/painting/image_provider.dart:499:80)
I/flutter ( 5679): #6 ScrollAwareImageProvider.resolveStreamForKey (package:flutter/src/widgets/scroll_aware_image_provider.dart:106:19)
I/flutter ( 5679): #7 ImageProvider.resolve.<anonymous closure> (package:flutter/src/painting/image_provider.dart:330:9)
I/flutter ( 5679): #8 ImageProvider._createErrorHandlerAndKey.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:460:26)
I/flutter ( 5679): (elided 13 frames from dart:async)
I/flutter ( 5679):
I/flutter ( 5679): Image provider: AssetImage(bundle: null, name: "assets/images/waiting.png")
I/flutter ( 5679): Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#288b8(), name:
I/flutter ( 5679): "assets/images/waiting.png", scale: 1.0)
I/flutter ( 5679): ════════════════════════════════════════════════════════════════════════════════════════════════════
As Omi Shah said, move asset folder to same level of lib folder.
or
please try chaging pubspec.yaml and asset url'
Image.asset(
'lib/assets/images/waiting.png',
fit: BoxFit.cover,
),
flutter:
uses-material-design: true
assets:
- lib/assets/images/
I did have to move the asset folder to the same level of the lib folder. BUT I also had to fix indentation issues for the pubspec.yaml file.
flutter:
uses-material-design: true
assets:
- assets/
--------------------------------
flutter:
[space][space]uses-material-design: true
[space][space]assets:
[space][space][space]- assets/
Spent a few good minutes on this and all looked good, identation, path etc.
What did the trick was to run flutter clean from terminal and rebuild.
Related
How to make modify Sliverappbar so I can see the background image with FlexibleSpaceBar when I scroll up?
SliverAppBar(
expandedHeight: 200.0,
floating: false,
pinned: true,
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
title: Text("Collapsing Toolbar",
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
)),
background: Image.network(
"https://images.pexels.com/photos/396547/pexels-photo-396547.jpeg?auto=compress&cs=tinysrgb&h=350",
fit: BoxFit.cover,
)),
),
I'm afraid this is the standard behavior of the FlexibleSpaceBar. You can change the color but not make it transparent.
A workaround I found is to use a Stack instead of the FlexibleSpaceBar:
SliverAppBar(
expandedHeight: 200.0,
floating: true,
pinned: true,
snap: true,
flexibleSpace: Stack(
children: <Widget>[
Positioned.fill(
child: Image.network(
"https://images.pexels.com/photos/396547/pexels-photo-396547.jpeg?auto=compress&cs=tinysrgb&h=350",
fit: BoxFit.cover,
),
),
Positioned.fill(
child: Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: Text(
"Collapsing Toolbar",
style: TextStyle(
color: Colors.white,
fontSize: 24.0,
),
textAlign: TextAlign.center,
),
),
),
),
],
),
),
I am working on a drawing app. I can get a screenshot of a widget using RepaintBoundary but I need to update it with a button which is outside. In my case, I can clear the list of points with a FlatButton but my Container is not clearing because of RepaintBoundary I need to get a screenshot of my Container without RepaintBoundary or I should update my Container from outside they both works for me. Thanks.
return
SingleChildScrollView(//physics: NeverScrollableScrollPhysics(),
child: Column(
children: <Widget>[
RepaintBoundary(
key: _signKey,
child: new Container(
width: 100.0 * MediaQuery.of(context).devicePixelRatio ,
height: 150.0 * MediaQuery.of(context).devicePixelRatio,
color: Colors.black12,
child: GestureDetector(
onPanUpdate: (DragUpdateDetails details) {
setState(() {
RenderBox object = context.findRenderObject();
Offset _localPosition =
object.globalToLocal(details.globalPosition);
points = new List.from(points)
..add(_localPosition);
});
},
onPanEnd: (DragEndDetails details) => points.add(null),
child: new CustomPaint(
painter: new DrawingPainter(points: points),
size: Size.infinite,
),
),
),
),
Row(
children: <Widget>[
FlatButton( //Button to clear container
padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8)),
color: Colors.redAccent,
textColor: Colors.black,
onPressed: (){
setState(() {
points.clear();
});
},
child: Text('Sil'),
),
],
),
],
),
);
I have been trying to develop an app which works with firebase and I am not a professional of coding.
Actually, my app is working well on the emulator but after 3-5 seconds I get an error message as you can see below:
W/DynamiteModule(11855): Local module descriptor class for providerinstaller not found.
I/DynamiteModule(11855): Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller(11855): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
W/DynamiteModule(11855): Local module descriptor class for providerinstaller not found.
I/DynamiteModule(11855): Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller(11855): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
And you can see my dependencies below:
dependencies:
flutter:
sdk: flutter
cloud_firestore: ^0.14.0+2
image: ^2.0.7
animator: 0.1.4
image_picker: ^0.6.7+7
google_sign_in: ^4.5.3
timeago: 2.0.17
cached_network_image:
firebase_auth: ^0.18.0+1
geolocator: 5.0.1
uuid: ^2.0.0
cupertino_icons: ^0.1.2
path_provider: ^1.6.16
firebase_messaging: ^7.0.0
firebase_storage: ^4.0.0
firebase_core: ^0.5.0
flutter_svg: ^0.19.0
In addition to providerinstaller issue above when I try to upload an image with camera, I get additional error below:
E/flutter (11855): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: NoSuchMethodError: The getter 'path' was called on null.
E/flutter (11855): Receiver: null
E/flutter (11855): Tried calling: path
E/flutter (11855): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
E/flutter (11855): #1 _UploadPageState.pickImageFromGallery (package:buddiesgram/pages/UploadPage.dart:37:38)
E/flutter (11855): <asynchronous suspension>
E/flutter (11855): #2 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:992:19)
E/flutter (11855): #3 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:1098:38)
E/flutter (11855): #4 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:184:24)
E/flutter (11855): #5 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:524:11)
E/flutter (11855): #6 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:284:5)
E/flutter (11855): #7 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:219:7)
E/flutter (11855): #8 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:477:9)
E/flutter (11855): #9 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:78:12)
E/flutter (11855): #10 PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:124:9)
E/flutter (11855): #11 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:377:8)
E/flutter (11855): #12 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:122:18)
E/flutter (11855): #13 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:108:7)
E/flutter (11855): #14 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:220:19)
E/flutter (11855): #15 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:200:22)
E/flutter (11855): #16 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:158:7)
E/flutter (11855): #17 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:104:7)
E/flutter (11855): #18 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:88:7)
E/flutter (11855): #19 _rootRunUnary (dart:async/zone.dart:1206:13)
E/flutter (11855): #20 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (11855): #21 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter (11855): #22 _invoke1 (dart:ui/hooks.dart:267:10)
E/flutter (11855): #23 _dispatchPointerDataPacket (dart:ui/hooks.dart:176:5)
E/flutter (11855):
You can see my code of my upload page below:
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
class UploadPage extends StatefulWidget {
#override
_UploadPageState createState() => _UploadPageState();
}
class _UploadPageState extends State<UploadPage> {
PickedFile file;
captureImageWithCamera() async {
Navigator.pop(context);
final picker = ImagePicker();
PickedFile imageFile = await picker.getImage(
source: ImageSource.camera,
maxHeight: 680,
maxWidth: 970,
);
imageFile = PickedFile(imageFile.path);
setState(() {
this.file = imageFile;
});
}
pickImageFromGallery() async {
Navigator.pop(context);
final picker = ImagePicker();
PickedFile imageFile = await picker.getImage(
source: ImageSource.gallery,
maxHeight: 680,
maxWidth: 970,
);
imageFile = PickedFile(imageFile.path);
setState(() {
this.file = imageFile;
});
}
takeImage(mContext){
return showDialog(
context: mContext,
builder: (context){
return SimpleDialog(
title: Text("New Post", style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),),
children: [
SimpleDialogOption(
child: Text("Capture image with camera", style: TextStyle(color: Colors.white),),
onPressed: captureImageWithCamera,
),
SimpleDialogOption(
child: Text("Select image from gallery", style: TextStyle(color: Colors.white),),
onPressed: pickImageFromGallery,
),
SimpleDialogOption(
child: Text("Cancel", style: TextStyle(color: Colors.white),),
onPressed: () => Navigator.pop(context),
),
],
);
}
);
}
displayUploadScreen(){
return Container(
color: Theme.of(context).accentColor.withOpacity(0.5),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.add_a_photo, color: Colors.grey,size: 200.0,),
Padding(
padding: EdgeInsets.only(top: 20.0),
child: RaisedButton(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(9.0),),
child: Text("Upload Image", style: TextStyle(color: Colors.white, fontSize: 20.0),),
color: Colors.green,
onPressed: () => takeImage(context),
),
),
],
),
);
}
#override
Widget build(BuildContext context) {
return displayUploadScreen();
}
}
If you would like to see my code or other files I would like to share with you. Can you please guide me?
Thank you in advance.
Regards,
Ekin.
Updated July 2021:
There are no defined answers to why these warnings are coming but can follow some steps.
make sure that <uses-permission android:name="android.permission.INTERNET"/> is defined in all the three AndroidManifest.xml files that i.e debug/main/profile.
for some, having <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> in main AndroidManifest file also helps.
Sometimes outdated google play services can also cause these warnings so update google play services this happens mostly in the case of an emulator.
if you are running your app on older device make user that multi-dex is enabled.
to enable multi-dex support add the following code in
app/build.gradle file
defaultConfig {
applicationId "com.example.flutter_test_firebase"
minSdkVersion 16
targetSdkVersion 30
multiDexEnabled true //<= add this line
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
and inside the same file add following dependencies
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation("com.android.support:multidex:1.0.3") // for multi-dex
}
Also make sure that you are using latest firebase plugins.
i don't know where you accessed the firestore package but in my case i was trying to update data but i was actually deleting and creating a new one which don't have the data i need to access in my code. So my only advice is gone be make sure you are not accidently deleting data or trying to access data you don't or will not have by some unknown reason go to your firestore database and make sure your data is as you want it. I have seen answers saying you need to update your google service in your emulator so maybe that might be your case but its not mine if you go to your google play service app in setting and see deactivate that means your emulator is already updated plus it will say update your google play service.
I got the same error when my app starts in emulator, also when I clicked add new data button. Actually my problem is exactly to add new data to Firebase Firestore in Flutter.
I updated the Google Play Services, and it worked for me.
To update the Google Play Services, following:
File > Settings > Appearance & Behavior > System Settings > Android SDK > SDK Tools, and select the Google Play Services and update.
Hope it works.
make sure that <uses-permission android:name="android.permission.INTERNET"/> is defined in all the three AndroidManifest.xml files that i.e debug/main/profile.
This is worked for me
I want to make header image and ListView in same scroll. But the code like below doesn't work:
SingleChildScrollView(
child: Column(
children: <Widget>[
HeaderImage(),
ListView(...)
]
)
)
I know ListView can't be below Column() directly. I know the way to use Expand() or Container with height or SizedBox, but these way can't make header image and ListView in same scroll. How to do these in same scroll? (HeaderImage widget is example.)(I must use ListView.)
I used to see this style in the world of web frequently.
You can use:
CustomScrollView(
slivers: <Widget>[
SliverAppBar(
flexibleSpace: FlexibleSpaceBar(
background: Container(
color: Colors.transparent,
child: Image(
image: NetworkImage('your image url here'),
fit: BoxFit.cover,
),
)
),
expandedHeight: 300,
backgroundColor: Colors.transparent,
actionsIconTheme: IconThemeData.fallback(),
),
SliverList(
delegate: SliverChildListDelegate(
[
Column(
children: <Widget>[
for(var index = 0;index<your_data.length;index++) // Dont put comma
your List Design here
]
)
]
)
)
]
)
I have a Container wrapped inside the Stack. Since the Stack will have a variable width, I would like to set the Container width equals to the Stack width.
I tried the below code but it does not work.
Stack(
alignment: Alignment.center,
children: <Widget>[
new Container(
child: new CachedNetworkImage(
fit: BoxFit.fitWidth,
height: 270.0,
imageUrl: _imageURL,
placeholder: (context, url) {
new CircularProgressIndicator();
},
),
new Container(
constraints: BoxConstraints.expand(height: 270.0),
decoration: new BoxDecoration(
color: Colors.black45
),
),
the console log says
I/flutter (14660): The following assertion was thrown during performLayout():
I/flutter (14660): BoxConstraints forces an infinite width.
I/flutter (14660): These invalid constraints were provided to RenderDecoratedBox's layout() function by the following
I/flutter (14660): function, which probably computed the invalid constraints in question:
I/flutter (14660): RenderConstrainedBox.performLayout (package:flutter/src/rendering/proxy_box.dart:259:13)
I/flutter (14660): The offending constraints were:
I/flutter (14660): BoxConstraints(w=Infinity, h=148.1)
The Container only shows when i give a definite width and height inside the code like this.
Stack(
alignment: Alignment.center,
children: <Widget>[
new Container(
child: new CachedNetworkImage(
fit: BoxFit.fitWidth,
height: 270.0,
imageUrl: _imageURL,
placeholder: (context, url) {
new CircularProgressIndicator();
},
),
new Container(
width: 100.0,
height: 100.0,
decoration: new BoxDecoration(
color: Colors.black45
),
),
Just set StackFit.expand to the fit property of your Stack :
SizedBox(
width : 300,
height: 300,
child: Stack(
fit: StackFit.expand,
alignment: Alignment.center,
children: <Widget>[
new Container(
decoration: new BoxDecoration(color: Colors.black45),
)
...