I'm unable to load images to my app although I tried many solutions
my code is
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
backgroundColor: Colors.amber,
appBar: AppBar(
backgroundColor: Colors.amber[900],
title: const Text("hi"),
),
body: Image(image: AssetImage("images/ab.png"),
),
),
);
}
}
this is my pubspec.yaml
flutter doctor
1- I used $ flutter clean and then $ flutter pub get.
2- I updated flutter SDK.
3- I mention only the folder (images).
4- I used a smaller image.
5- I restarted my laptop.
6- I run my code in another IDE.
but nothing is working for me, so can anyone help me?
thanks in advance
I copied your main.dart code, I created a images folder with a .png file.
I think the problem could be the position of the images folder, you should place it beside the lib folder.
Without seeing the project folder structure I cannot be sure, but if you do it like that your code should work fine.
Here's the pubspec.yaml:
flutter:
assets:
- images/
Here's a screenshot of the your code running:
Related
I am trying to build an app with firebase services, and try these steps many times, including in a fresh new project just to test, but I think there's a problem with the library:
I am running
flutterfire configure
By terminal on the root folder of the project, then selecting one of the projects, selecting all the available platforms ( android, ios, macos, web), then agreeing with the update of android/build.gradle and android/app/build.gradle
After that I've got :
Firebase configuration file lib/firebase_options.dart generated successfully with the following Firebase apps:
But just importing the libraries make the build crashes
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
The error I'm getting is this
: Error: '$throw' isn't a type.
../…/method_channel/method_channel_firebase.dart:120
$throw coreNotInitialized();
^^^^^^
: Error: Expected ';' after this.
../…/method_channel/method_channel_firebase.dart:120
$throw coreNotInitialized();
^^^^^^^^^^^^^^^^^^
: Error: Expected an identifier, but got ')'.
../…/method_channel/method_channel_firebase.dart:120
Try inserting an identifier before ')'.
$throw coreNotInitialized();
^
The sample App is just this:
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(title: const Text("My App")),
body: const Center(child: Text("MyApp")),
),
);
}
}
I found this workaround, I think there's a problem with the current library version or flutterfire but the next steps work for me:
I changed the versions of the firebase libaries for previous versions I had work with, run flutter clean and deleted the Podfile.lock and it now it's working
NOT WORKING VERSIONS
firebase_core: ^2.2.0
firebase_messaging: ^14.2.1
WORKING VERSIONS
firebase_core: ^1.1.0
firebase_messaging: ^9.1.3
I have an app with lots of Lottie animations. They work fine in a Windows UWP app and AirBnB sample Android app. Also look fine in lottiefiles.com online test tool.
But they are glitchy in Flutter using Lottie for Flutter package. Not all of them, but many, maybe around a third.
Full source code below, you can try for yourself.
Glitches are either frame overlaps or blinking, as if there is a gap between frames.
Glitches are consistent, i.e. always happen in the same place, so does not seem like a performance issue.
Also, they are not happening between repeats, but in the middle of the animation, so again not an application issue but seems to be the issue with how they are rendered.
I have tried loading them as composition from memory with a controller. I have also tried a vanilla asset load to rule out issues with my implementation, and they are behaving the same. The issue appears both in the emulator and the actual phone. So it seems to me it is not caused by the way I implemented but by the Lottie package itself, or perhaps an issue with Lottie JSON that for some reason only affects Android.
Full example is below. Just paste this into main.dart and add dependency to yaml: lottie: ^1.2.1.
import 'package:flutter/material.dart';
import 'package:lottie/lottie.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(),
darkTheme: ThemeData.dark(),
themeMode: ThemeMode.dark,
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Lottie Test"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: Lottie.network(
'https://assets6.lottiefiles.com/packages/lf20_uz92k22x.json'),
),
],
),
),
);
}
}
Try adding frameRate: FrameRate.max like stated below.
Expanded(
child: Lottie.network('https://assets6.lottiefiles.com/packages/lf20_uz92k22x.json',
frameRate: FrameRate.max,
),
),
this will render the Lottie animation with the same frame rate of that of the app. In Lottie plugin it will render the json as per the frame rate mentioned in the json file. An animation encoded with a 25 FPS will only be painted 25 times per seconds even though the AnimationController will invalidate the widget 60 times per seconds. Hence this framerate was introduced from Lottie 0.6.0
I use Lottie for Flutter on my applications and it works well also on emulator or on low-performance phones. The problem can be related to bad converted animations, or you can try to use Lottie.asset(yourjson) to avoid potential network fetch issues.
According to the official package documentation
For Flutter Web, run the app with: flutter run --web-renderer canvaskit
Works fine for me in the latest version: lottie: ^1.2.1
it's all good on android but not good on iOS.
whenever i try to enter the videoPlayerScreen
error occurs
I tryed another project with same class code ,
it was fine.
but in this project doens't work.
Here's my code
...
class _VideoTestState extends State<VideoTest> {
final FijkPlayer player = FijkPlayer();
#override
void initState() {
super.initState();
player.setDataSource( // ✅ App dies in here
'http://baishan.oversketch.com/2019/11/05/d07f2f1440e51b9680f4bcfe63b0ab67.MP4',
autoPlay: true);
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
color: Colors.green,
child: Center(
child: FijkView(
player: player,
),
),
),
);
}
}
in Android studio when I enter it , it dies immediately, Log( Lost connection to device. )
but in Xcode show log like this.
I assume its package problem.
not sure about it but only difference between another project and this one is
another project has few package ( actually minimum packages to play video )
this one has alot include firebase things.
I tried ,
flutter clean ,
rm Podfile.lock
pod install.
is there any clue to solve this problem??
I am using Flutter and whenever I want to to play a sound it crashes and throw me this:
iOS => call startHeadlessService, playerId d580eb03-1cab-4a44-9b7d-5b80ac32a53c
iOS => call play, playerId d580eb03-1cab-4a44-9b7d-5b80ac32a53c
play!
Lost connection to device.
I don't know why, I followed step by step.
Here's the code I write if it's helping:
import 'package:flutter/material.dart';
import 'package:audioplayers/audio_cache.dart';
void main() => runApp(XylophoneApp());
class XylophoneApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Center(
child: FlatButton(
onPressed: () {
final player = AudioCache();
player.play('note1.wav');
},
child: Text('Play me!'),
),
),
),
),
);
}
}
And Here is my pubspec.yaml :
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
audioplayers: ^0.16.0
I've done everthing that was in that course step by step, but instead of asking me to allow microphones ( that was in course ), the app just lost connection.
I don't know why, in the course never explain what to do if you meet errors.
Can you help me understand why is this happening and how can be handled? It would help me a lot. Thank you in advance!
The emulator is iPhone 11 pro max.
Also I tried running it by calling " flutter run " in the terminal
With the help of J. Saw from the comments above, we changed the package version from 0.16 to 0.10 and it's working
I want to make 3 texts that are copyable and I want to choose SelectableText.rich.
So you can choose what you want to copy.
class HomeScreen extends StatelessWidget{
#override
Widget build(BuildContext context){
return new Scaffold(
appBar: new AppBar(title: new Text ("Better Hashtag"), backgroundColor: Colors.red),
body: Column(
children: <Widget>[
SelectableText.rich(Textspan (
)
);
],
),
);
}
}
I get an error by SelectableText.rich
What error are you getting?
Have you added the flutter_selectedtext dependency to your pubspec.yaml file?
flutter_selectext: ^0.1.1
More info: https://pub.dev/packages/flutter_selectext
You also have a syntax problem:
body: Column(
children: <Widget>[
SelectableText.rich(Textspan (
)
); // <----- remove this semi-colon, as you are still
// in the list of children of the Column widget.
],
),
SelectableText is included in Flutter 1.9 release. So if you are using Flutter 1.9 or above, you don't need to add any dependency to your pubspec.yaml file, can just use it directly.
If you are not sure about the syntax, check out this example: https://api.flutter.dev/flutter/material/SelectableText-class.html#material.SelectableText.2
If you are using an older version of Flutter and getting the error, run flutter upgrade. Once complete it should work. As of the date of this response, Flutter stable channel is on 1.9.1. So no matter which channel you are using, as soon as you upgrade Flutter, you should have SelectableText.rich ready to use without having to add any dependency to your pubspec.yaml file.