Firebase makes Flutter App build crashes on it's own library code - flutter

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

Related

Flutter (Unable to load asset)

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:

Flutter App Localization : Arb file not readable error

I am trying to make my app support localization. I want my app to work in 2 languages: English & Hindi. So i added the following package in my pubspec.yaml:
flutter_localizations:
sdk: flutter
intl: ^0.17.0 # Add this line
Then i made a l10n.yaml file and added this:
arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
I also made the app_en.arb file like this:
{
"helloWorld": "Hello World!",
"#helloWorld": {
"description": "The conventional newborn programmer greeting"
}
}
When i am running this code, it gives me an error:
Generating synthetic localizations package failed with 1 error:
Exception: The 'template-arb-file', LocalFile: 'C:\Users\Crosslynx25\Desktop\SW_Mobile_Platform\lib/l10n\app_en.arb', is not readable.
Please ensure that the user has read permissions.
main.dart file
import 'package:ble_app_flutter/screens/home_screen.dart';
import 'package:ble_app_flutter/screens/otp_screen.dart';
import 'package:ble_app_flutter/screens/splash_screen.dart';
import 'package:ble_app_flutter/utils/colors.dart';
import 'package:ble_app_flutter/l10n/L10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:lottie/lottie.dart';
import 'country_codes.dart'
as CountryCodes;
import 'screens/driver/driver_home_screen.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
#override
State < MyApp > createState() => _MyAppState();
}
Map < int, Color > myTheme = {
50: Color.fromRGBO(9, 65, 155, .1),
100: Color.fromRGBO(9, 65, 155, .2),
};
class _MyAppState extends State < MyApp > {
// This widget is the root of your application.
MaterialColor myColor = MaterialColor(0xFF09419b, myTheme);
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'BLE App gkhglkjhkl',
debugShowCheckedModeBanner: false,
supportedLocales: L10n.all,
// localizationsDelegates: [
// AppLocalizations.delegate, // Add this line
// GlobalMaterialLocalizations.delegate,
// GlobalWidgetsLocalizations.delegate,
// GlobalCupertinoLocalizations.delegate,
// ],
theme: ThemeData(
primarySwatch: myColor,
),
home: new Login(),
);
}
}
class Login extends StatefulWidget {
#override
State < Login > createState() => _LoginState();
}
class _LoginState extends State < Login > {
// const Login({
var selectedCountry = "91";
var phoneNumber = "";
#override
Widget build(BuildContext context) {
.
. //some code
.
}
}
I got the same issue because I copied a yaml file to create the "app_en.arb" file. I think the issue happened when I renamed it and then the extension .yaml wasn't display. I was seeing "app_en.arb" but in reality it was "app_en.arb.yaml"... Hope this will help some of you.
The error is showing here
C:\Users\Crosslynx25\Desktop\SW_Mobile_Platform\lib/l10n\app_en.arb
You are on Windows so you should use \ and not / in path. So I think modifying your l10n.yaml like this
arb-dir: lib\l10n
will do the trick.
This happened with me, then I discovered that the file is actually app_en.arb (with a space before the name). This caused it not to be found.
You can test it by copying the written path in the log, and see if Windows can find the file.
An issue has been created for the misleading message in here.
I don't know why this caused after copy from pub.dev (app_en.arb ) but if you start to refactor --> rename, you can see your file has one empty space after the file format Look at the empty space
enter image description here
I deleted the file l10n.yaml then I ran the command "flutter gen-l10n" that fixed my problem.
it generated a flutter_gen folder in the .dart_tool.
then as soon as your folder is created, re-create the file l10n.yaml and execute the command flutter gen-l10n normally it fixes the problem
In my case, it happened after I implemented localization with Flutter Intl instead of raw l10n with app_en.arb file. So I had intl_en.arb instead of app_en.arb after I removed app_en.arb.
Solution is to remove l10n.yaml file from project folder if you do not need to use app_en.arb file any more. Flutter Intl is definitly more user friendly and easy to implement.
use this command flutter pub global run intl_utils:generate instead of f̶l̶u̶t̶t̶e̶r̶ ̶g̶e̶n̶-̶l̶1̶0̶n

How to fix animation glitches in Flutter Lottie

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

Flutter: How can I get list of device locales before building starts?

I want to internationalize my application. To ease translations, I want to use i18n_extension package.
I need to get the list of device locales (any device, even web) before any widget building process starts.
This is required to initially set the correct locale (which can be taken from a server) both for I18n and for Localizations (in WidgetsApp).
The only way I found to get the list of device locales is:
MaterialApp(
localeListResolutionCallback: (deviceLocales, appLocales) => myLocaleResolution(deviceLocales, appLocales),
locale: thisAppsLocale,
home: I18n(
child: MyHomePage(),
initialLocale: thisAppsLocale, ),
Method myLocaleResolution sets thisAppsLocale. Method is invoked once at startup and when the user changes the device locale. So thisAppsLocale is only available after the first build process and cannot be used to set locale and initialLocale. Using setState() within myLocaleResolution throws an exception on startup invocation.
Use window.locales:
import 'dart:ui';
import 'package:flutter/material.dart';
void main(){
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
locale: window.locale,
supportedLocales: window.locales,
home: Scaffold(),
);
}
}
The window singleton gives you access to the Window class.

My app lost connection when I try play a sound using audioplayers

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