Exception ,trying to run a picture on the app - flutter

When I try to let my flutter app show a picture(it's asset image),it throws the exception :
"Exception: Gradle task assembly debug failed with exit code 1".
What should I do in such a case ?
import 'package:flutter/material.dart';
void main()
{
runApp(Center(
child: Image(
image:AssetImage('images/mont.jpg'),
)
));
}
the pubspec.yaml file is :
flutter:
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- images/mont.jpg
- images/a_dot_ham.jpg

Related

Flutter: Debug error when import rive package

I am new. I am building my first app but there is a difficult error.
I created an animation and want to use it like a button. Tap on it and the animation starts.
I try to use rive but can not run the app when importing rive.dart
this is my code:
import 'dart:ffi';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:rive/rive.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({Key? key}) : super(key: key);
#override
State createState() => _Home();
}
class _Home extends State {
String bamboo_tube_animation = 'assets/animations/OngQue.svg';
#override
Widget build(BuildContext context) {
double device_width = MediaQuery.of(context).size.width;
double device_height = MediaQuery.of(context).size.height;
double bamboo_button_size = device_width * 0.9;
double icon_size = 60;
return Container(
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
children: [
RiveAnimation.asset(bamboo_tube_animation);
Container(
height: 20,
),
],
),
);
}
}
I add rive to pubspec.yaml
dependencies:
flutter:
sdk: flutter
flutter_svg: ^1.1.6
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
flare_flutter: ^3.0.2
rive: ^0.10.1
And this is debug console:
Launching lib/main.dart on iPhone 13 Pro Max in debug mode...
Xcode build done. 6.7s
Failed to build iOS app
Error output from Xcode build:
↳
2023-01-26 21:51:46.183 xcodebuild[26922:202491] Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionSentinelHostApplications for extension Xcode.DebuggerFoundation.AppExtensionHosts.watchOS of plug-in com.apple.dt.IDEWatchSupportCore
2023-01-26 21:51:46.184 xcodebuild[26922:202491] Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionPointIdentifierToBundleIdentifier for extension Xcode.DebuggerFoundation.AppExtensionToBundleIdentifierMap.watchOS of plug-in com.apple.dt.IDEWatchSupportCore
BUILD FAILED
Xcode's output:
↳
Writing result bundle at path:
/var/folders/3w/nscscyx1109ckdn_r__40g7m0000gn/T/flutter_tools.XO1RoC/flutter_ios_build_temp_dirvZKZ6S/temporary_xcresult_bundle
: Error: Type 'Uint8List' not found.
Future<void> decode(Uint8List bytes) {
^^^^^^^^^
: Error: 'Uint8List' isn't a type.
Future<void> decode(Uint8List bytes) {
^^^^^^^^^
Failed to package /Users/manh.do/Documents/flutter_example/angicungduoc/angicungduoc.
Command PhaseScriptExecution failed with a nonzero exit code
note: Using new build system
note: Planning
note: Build preparation complete
note: Building targets in dependency order
Result bundle written to path:
/var/folders/3w/nscscyx1109ckdn_r__40g7m0000gn/T/flutter_tools.XO1RoC/flutter_ios_build_temp_dirvZKZ6S/temporary_xcresult_bundle
Could not build the application for the simulator.
Error launching application on iPhone 13 Pro Max.
Exited
Any idea?
I just start my app, but it's hard to resolve this error

Flutter audioplayers: ^2.0.0 error Unhandled Exception: Unable to load asset: assets//data/user/0/com.xxxx.xxxx/cache/flip.mp3

I'm trying to use audioplayers: ^2.0.0,but i got this error, how to solve it?please!
pubspec.yaml
flutter:
uses-material-design: true
assets:
- assets/audio/
Code
Future setAudio() async {
AudioPlayer audioPlayer = AudioPlayer();
audioPlayer.setReleaseMode(ReleaseMode.loop);
AudioCache audioCache = AudioCache(prefix: 'assets/audio/');
final url = await audioCache.load('flip.mp3');
audioPlayer.setSourceAsset(url.path);
}
You shouldn't use the full path in setSourceAsset, and since you've already set a prefix for the cache you kust have to write the filename:
audioPlayer.setSourceAsset('flip.mp3');

how to fix error DevFS synchronization failed when installing flutter SVG package?

I got this flutter_SVG package
updated pubspec.yaml as below
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.3
flutter_svg: ^0.17.4
clicked the pub get button and done properly
I confirmed that my SVG file is properly put in under assets in the pubspec.yaml
then in Home.dart where I want, I imported the package normally, and below is the code where the svg should work as per package readme instructions
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
class HomeState extends State<Home> {
TextEditingController _foo = new TextEditingController();
Widget build(BuildContext context) {
const pyramidsYellowIcon = 'my_assets/icons/pyramids_yellow.svg';
const followIconOffIcon = 'my_assets/icons/follow_icon_off.svg';
return Stack(
children: <Widget>[
Container(
child: SvgPicture.asset(followIconOffIcon, semanticsLabel: 'follow',),
),
],
),
}
}
then a hot reload error shows DevFS synchronization failed
and below logcat shows
2020-07-02 12:43:21.375 3019-3019/? E/GmsClientSupervisor: Timeout waiting for ServiceConnection callback com.google.android.gms.clearcut.service.START
java.lang.Exception
at tlk.handleMessage(PG:6)
at android.os.Handler.dispatchMessage(Handler.java:98)
at tzg.a(PG:5)
at tzg.dispatchMessage(PG:4)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
any, of course, the emulator refuses to reload, when I delete all changes mentioned above, everything is fixed and normal
After you add a package or an asset the hot reload doesn't work. You have to restart the app.
In my case I got error message "Hot Restart Error DevFS synchronization failed".
I had to stop an application in Android Studio (Run > Stop) and then run again (Run > Run...). Also there was an error in code that I fixed.

FlutterError (Unable to load asset: assets/chat1 .txt)

I know I placed my text file at the location assets\chat1.txt, and my code also works with other txts but somehow I always get the following error:
Exception has occurred.
FlutterError (Unable to load asset: assets/chat1.txt)
my Code:
Future<String> getFileData(String path) async {
return await rootBundle.loadString(path);
}
pubspec.yaml
flutter:
assets:
- assets/
Add the full path in pubspec.yaml file and you should consider the indentation for assets:
flutter:
assets:
- assets/chat1.txt

Flutter 1.0 - Unable to load text asset

I'm having some trouble loading text assets in flutter (1.0).
This is the current code attempting to read the asset.
Future<String> get _localPath async {
final directory = await getApplicationDocumentsDirectory();
return directory.path;
}
Future<String> getFileData(String path) async {
return await rootBundle.loadString(path);
}
Future<File> get _localFile async {
final path = await _localPath;
final file = File('$path/toon_test_3.json');
bool exists = file.existsSync();
if(exists){
return file;
} else {
// Load the default file
final newfile = await getFileData('toonRepo/data.json');
return file.writeAsString(newfile);
}
}
loadString will failing popping up the following:
Could not load source 'dart:core/runtime/libobject_patch.dart': <source not available>.
If execution continues the following exception is raised:
Exception has occurred.
FlutterError (Unable to load asset: toonRepo/data.json)
I've tried a lot of solutions here that revolve around the asset section in pubspec.yaml
name: hello_world
description: A new Flutter project.
version: 1.0.0+1
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
dependencies:
path_provider: ^0.4.1
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
english_words: ^3.1.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
assets:
- toonRepo/
uses-material-design: true
Am I going wrong somewhere very silly?
Cheers for any pointers you have.
Project Structure
Here is a temporary copy of the code if you want to take a peek.
Github
And here's a stack trace
[VERBOSE-2:shell.cc(184)] Dart Error: Unhandled exception:
Unable to load asset: toonRepo/data.json
#0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
<asynchronous suspension>
#1 AssetBundle.loadString (package:flutter/src/services/asset_bundle.dart:67:33)
<asynchronous suspension>
#2 CachingAssetBundle.loadString.<anonymous closure> (package:flutter/src/services/asset_bundle.dart:162:56)
#3 __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin.putIfAbsent (dart:collection/runtime/libcompact_hash.dart:284:23)
The asset access works fine with the pubspec.yaml in your question.
new Text("Name: " + toon.info.name)),
fails because toon is null because it never got a value assigned.
You could use new Text("Name: " + (toon?.info?.name ?? 'foo')), to work around the exception.
If you add
widget.storage.getFileData('toonRepo/data.json').then((f) => print(f));
to _FlutterDemoState.initState(), you'll see that reading the asset works just fine.