Getting this error while connection with firebase using flutter - android

Exception has occurred.
PlatformException (PlatformException(channel-error, Unable to establish connection on channel., null, null))
enter image description here

try this :
Run in the terminal,
flutter pub outdated
Next, update the packages which are outdated
flutter pub upgrade outdated_package
Then, run flutter clean next flutter pub get

Step 1:
In pubspec.yaml have you added firebase_core?
Step 2:
If no then please goto pub.dev and find the latest version of it
and add to pubspec.yaml
Step 4: into main.dart add this
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
}
Step 3:
If yes, then run flutter clean and flutter pub get

Related

Flutter unable to load text from assets

i have read https://flutter.dev/docs/development/ui/assets-and-images#asset-images-in-package-dependencies and Flutter - Read text file from assets and applied all there was but my code still doesn't work....
i opened a new project for this, in the main folder i created assets and a file :
pwd
/home/bboett/AndroidStudioProjects/examen_companion
bboett#hayate:~/AndroidStudioProjects/examen_companion$ ls -l assets/
insgesamt 4
-rw-r--r-- 1 bboett bboett 10 19. Mai 15:14 test.txt
bboett#hayate:~/AndroidStudioProjects/examen_companion$ cat assets/test.txt
Hello!!
then, not trusting android studio, i checked with vi, that in pubspec.yaml everything was ok:
the file ends with:
flutter:
uses-material-design: true
assets:
- assets/
i replaced the spaces, with 2 spaces before uses and assets: and 4 before - assets...
in the _MyHomePageState class i changed :
#override
Widget build(BuildContext context)
{
AssetBundle bundle = DefaultAssetBundle.of(context);
return FutureBuilder<String>(
future: bundle.loadString("assets/test.txt"),
builder: (context, AsyncSnapshot<String> snapshot)
{
if (snapshot.hasData) { return Text(snapshot.data.toString()); }
else { return CircularProgressIndicator(); }
}
);
}
doesn't work.... i never come out of the progress indicator....
so directly in the main i added :
void main() async {
print(await rootBundle.loadString("assets/test.txt"));
runApp(MyApp());
}
and that crashes with :
Launching lib/main.dart on Linux in debug mode...
Building Linux application...
Debug service listening on ws://127.0.0.1:41355/L-ev6_eNIlI=/ws
Syncing files to device Linux...
[ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Null check operator used on a null value
#0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:222:39)
#1 AssetBundle.loadString (package:flutter/src/services/asset_bundle.dart:68:33)
#2 CachingAssetBundle.loadString.<anonymous closure> (package:flutter/src/services/asset_bundle.dart:165:56)
#3 _LinkedHashMapMixin.putIfAbsent (dart:collection-patch/compact_hash.dart:311:23)
#4 CachingAssetBundle.loadString (package:flutter/src/services/asset_bundle.dart:165:27)
#5 main (package:examen_companion/main.dart:9:26)
i did after changing anything prior to the run a flutter clean.....
version is :
flutter upgrade
Flutter is already up to date on channel beta
Flutter 2.2.0-10.3.pre • channel beta • https://github.com/flutter/flutter.git
Framework • revision 06e2fd6357 (vor 11 Tagen) • 2021-05-08 11:28:22 -0700
Engine • revision a123e75c60
Tools • Dart 2.13.0 (build 2.13.0-211.14.beta)
flutter doctor run ok too, oh and i have the same error on linux or android, so its not the device....
so i am pretty clueless on how to get this work, since i have the impression to have followed documentation and previous help :(
BTW i thought that flutter was now null, safe... anyway, how do i get this to work?
thanks in advance
[edit]: even stranger.... i replaced
//future: bundle.loadString("assets/test.txt"),
future: bundle.loadString('AssetManifest.json'),
and got :
flutter: {"assets/test.txt":["assets/test.txt"],"packages/cupertino_icons/assets/CupertinoIcons.ttf":["packages/cupertino_icons/assets/CupertinoIcons.ttf"]}
so the file is there??? why can't i open/get it??
[ed2]: ok, i don't get it..... i tryed this directly in main:
print(await rootBundle.loadString('AssetManifest.json'));
and that crashed too with the null exception....
WidgetsFlutterBinding.ensureInitialized() was the key to solve my issue as well as #HannesHultergård wrote. To supplement his answer, the main should be:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
print(await rootBundle.loadString("assets/test.txt"));
runApp(MyApp());
}
I tried your code, and it works for me. Assets can be tricky. Sometimes you will need to restart the app completely after adding a new asset, or uninstall the app completely before running it again. You can also try running flutter clean.
An advice is to add if(snapshot.hasError) print(snapshot.error); before the else in the FutureBuilder just to see what the error is if it still does not work.
The reason you got an error about the null check when printing in main is because you need to add WidgetsFlutterBinding.ensureInitialized(); before using the root bundle to ensure that you have an instance of WidgetsBinding.
You have to put your test.txt inside your assets folder in your project directory.
Also, it would be better if you could add your project directory structure to your post.
Instead of this,
flutter:
uses-material-design: true
assets:
- assets/
Add this,
flutter:
uses-material-design: true
assets:
- assets/test.text
Then run flutter pub get. It should be fine. Let us know if it worked.

Flutter Dependency Error (flutter_svg: ^0.19.2+1)

When I try to add flutter_svg dependency to add SVG format picture in my project it throws me an error like that:
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_svg-0.19.2+1/lib/src/picture_provider.dart:57:59: Error: No named parameter with the name 'nullOk'.
context != null ? Localizations.localeOf(context, nullOk: true) : null,
^^^^^^
/C:/src/flutter/packages/flutter/lib/src/widgets/localizations.dart:413:17: Context: Found this candidate, but the arguments don't match.
static Locale localeOf(BuildContext context) {
I'm using flutter (Channel master, 1.26.0-18.0.pre.193). and flutter_svg: ^0.19.2+1
I've also with a lower version of this dependency, but still the same error.
add the following dependency
flutter_svg: ^0.20.0-nullsafety.3
instead of
flutter_svg: ^0.19.2+1
Then follow these steps
flutter clean
flutter pub get
flutter run
Looks like flutter_svg didn't migrate to nullsafety, try switch to stable channel and repair cache files.
1. flutter channel stable
2. flutter clean
3. flutter pub cache repair
4. flutter packages get
5. flutter run
If this does not help then try this
https://github.com/dnfield/flutter_svg/issues/479
Yeah, this was an issue for me when I was working on the master branch for a recent project. It was an issue which only came up for the flutter internalisation package.
The main issue is with the intl package:
https://pub.dev/packages/intl/install
To fix this, below the dependencies, please add another section, that will override the intl dependency, which is being pulled by the flutter_localizations package:
dependency_overrides:
intl: ^0.17.0-nullsafety.2
It should now work for the master branch. Another tip, you should avoid working on the master branch, because master changes all the time. You should stick to either stable or beta.
I am using flutter beta version as I am using beta to develop my website, this issue also came to me today, I solved it by running this command,
flutter downgrade
I solved this problem by delete nullOk: true from this line because Localizations.localeOf take context only as a parameter
locale:
context != null ? Localizations.localeOf(context) : null,
instead of
locale:
context != null ? Localizations.localeOf(context, nullOk: true) : null,
or you can change your channel from master channel to stable channel by using this command line on your terminal.
flutter channel stable
flutter clean

Url Launcher does not work with MissingPluginException Flutter

I am trying to launch a url in my flutter application. What i'm trying to do is very simple and it works in all other projects except for this one! The browser should be launched on an inkwell onTap event. I tried the exact same code in other projects and worked. I also tried to create a new flutter project and the code worked.
The app does not crash and i don't get any error but on Debug i get a missing plugin exception.
I tried flutter clean and flutter run but didn't work! I tried invalidating cache and restart but also didn't work! I tried removing and re installing the plugin but also didn't work!
Here's the code:
_launchMapsUrl() async {
final url = 'https://www.google.com';
if (await canLaunch(url)) {
await launch(url);
} else {
print('Could not launch $url');
}
}
the onTap:
onTap: () {
_launchMapsUrl();
},
The Compiled and Target SDK versions are 29 and the version of the launcher in my pubspec.yaml is url_launcher: ^5.7.10
For the record the other projects that the code worked in are of the same versions
I think it has something to do with caching issue i'm not really sure, i'm very new to flutter.
Can you please recommend a solution.

Error: Not found: 'dart:js' import 'dart:js';

I am creating a PopupMenuButton() in the AppBar section.
This is my file:
import 'dart:js';
import 'package:bfdi_app/settings.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
class ProfilePage extends StatefulWidget {
#override
_ProfilePageState createState() => _ProfilePageState();
}
class _ProfilePageState extends State<ProfilePage> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
'App_Name',
),
actions: <Widget>[
PopupMenuButton(
icon: Icon(Icons.settings),
onSelected:(value){
if(value==0){
Navigator.push(
context,
MaterialPageRoute(builder: (context)=>SettingPage())
);
}
},
itemBuilder: (context) => [
PopupMenuItem(
child: Text("Settings"),
value:0,
],
),
],
),
}
Now I am facing an error in Console Log:
Compiler message:
lib/Pages/addPost.dart:1:8: Error: Not found: 'dart:js'
import 'dart:js';
^
lib/Profile/profile.dart:1:8: Error: Not found: 'dart:js'
import 'dart:js';
^
I have already added the dependency dart:js, but still getting the same error.
Error:
Go to your flutter installed directory/.pub-cache/hosted/pub.dartlang.org/js-0.6.3-nullsafety.1/lib/js.dart
Delete or comment this line:
export 'dart:js' show allowInterop, allowInteropCaptureThis;
Then try again
I just del import 'package:js'. it works for me.
Sounds like an import issue as soon as you are trying to compile for a native application.
Try searching for and delte the incorrect dart:js import (import 'dart:js';).
Have a look at this GitHub issue #70373
EDIT: I have switched to the master channel and all working fine. Although I don't see any requirement of dart.js in your current code. so you can remove that too
ORIGINAL ANSWER:
I believe you are using stable channel so try to switch to beta channel.
Open your terminal and run,
$ flutter channel beta
Quoting pub.dev:
Depend on it
Add this to your package's pubspec.yaml file:
dependencies:
js: ^0.6.2
Install it
You can install packages from the command line:with pub:
$ pub get
with flutter:
$ flutter pub get
Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.
Import it
Now in your Dart code, you can use:
import 'package:js/js.dart';
in my case just flutter clean solved the issue
Try using the js package: https://pub.dev/packages/js#-installing-tab-
You should try to use package:js instead of dart:js
Actually mine was solved with just a system restart and a "flutter clean" command. (yes I am using beta channel) But weird thing was the files were existed already but the dependencies somehow couldn't read from the dart packages.
You may not running the app on supported platform by library. In my case I was running on Android which library just supported Web as output. No need to clear cache or comment some code.
This solution allowed me to run tests using dart:js & without modifying my local flutter installation.
check if you are not using that package in your project just remove unused packages.
Step -1
Just remove dart:js
Step -2
Run on terminal "flutter clean"
Step -3
Run on terminal "flutter pub get"
Step -4
Run your project

RNFetchBlob.mkdir got 1 arguments, expected 2

When i try to setup ongoing react-native project in that one of the plugin is react-native-fetch-blob i'll try many but can't resolve this issue.
also i remove that plugin from app and resetup all step from npm react-native-fetch-blob
after following all step getting same issue.
`RNFetchBlob.fetch('POST', 'api', {
'Content-Type': 'application/multipart/form-data'
}, [
{name: 'file', filename: filename, data: RNFetchBlob.wrap(PictureURI)}
])
.then((responseData) => {
// console.log("image uploaded",responseData);
// console.log("----------Upload Image Test---RESPONSE---------");
})
.catch(err => {
// console.log(err);
// console.log("----------Upload Image Test---RESPONSE--ERROR-------");
})`
in this plugin i'm only used the fetch method but my project gives me error mkdir method.
Resolve this issue following steps:
react-native unlink react-native-fetch-blob
npm uninstall react-native-fetch-blob --save
yarn add react-native-fetch-blob (assuming your system already
installed yarn)
RNFB_ANDROID_PERMISSIONS=true react-native link
then uninstall app from device/simulator/emulator and run command
react-native run-android
work perfect.
:)

Categories

Resources