Flutter : firebase MissingPluginException - flutter

I'm having this problem about flutter and firebase(realtime-database).
Unhandled Exception: MissingPluginException(No implementation found for method Query#observe on channel plugins.flutter.io/firebase_database)
Here is the error in terminal
error
// error message
[VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method Query#observe on channel plugins.flutter.io/firebase_database)
#0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:154:7)
<asynchronous suspension>
#1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12)
#2 Query._observe.<anonymous closure> (package:firebase_database/src/query.dart:50:38)
#3 _runGuarded (dart:async/stream_controller.dart:820:24)
#4 _BroadcastStreamController._subscribe (dart:async/broadcast_stream_controller.dart:215:7)
#5 _ControllerStream._createSubscription (dart:async/stream_controller.dart:833:19)
#6 _StreamImpl.listen (dart:async/stream_impl.dart:475:9)
#7 Stream.first (dart:async/stream.dart:1254:25)
#8 Query.once (package:firebase_database/src/query.dart:84:55)
#9 _IoTState.initState (package:flutter_try_iot/main.dart:36:13)
#10 StatefulElement._f<…>
I'm trying to get data from firebase to display in flutter app.
Here is my code main.dart
class _IoTState extends State<IoT> {
final getIot = FirebaseDatabase.instance.reference();
final getData = FirebaseDatabase.instance.reference().child('xxx-xxx');
String temperatue = "0";
String illuminance = "0";
List<String> temp = [];
List<String> light = [];
#override
void initState(){
getData.once().then((DataSnapshot snapshot){
if (snapshot.value == null) {
print("Item doesn't exist in the db");
} else {
print("Item exists in the db");
}
});
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Color(0xFF7ACADA),
title: Text(
"IoT ZigBee Simulation",
textAlign: TextAlign.center,
style: TextStyle(
color: Color(0xFF1A1244)
),
),
),
body: Column(
),
);
}
}
pubspec.yaml
firebase_core: ^0.4.5
firebase_database: ^3.1.6
flutter_icons: ^1.1.0
fl_chart: ^0.10.1
I follow instructions to add ios to firebase .ios add firebase
no issues found by flutter doctor
I follow other peoples suggestion to do flutter clean & flutter packages get, but still not able to fix this problem
https://github.com/flutter/flutter/issues/13971
terminal
Also pop up a window telling me The file “Runner.xcworkspace” has been modified by another application" everytime I execute flutter clean/ flutter packages get
I successfully connect to firebase yesterday, but after I close my simulator I start to receive error message
success picture
Please give me some solution or advice to fix this problem, thanks.
Please tell me if I need to provide additional information

Related

Unhandled Exception: Null check operator used on a null value in flutter

I hope you are well, I will give you a bit of context about my problem...
I really don't know why this error happens and I've seen many similar publications but they haven't worked for me.
I'm new to flutter and I'm working on an app, but when the user wants to log out, the app crashes and shows the following error:
E/flutter (12659): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value
E/flutter (12659): #0 StatefulElement.state
package:flutter/…/widgets/framework.dart:4999
E/flutter (12659): #1 Navigator.of
package:flutter/…/widgets/navigator.dart:2543
E/flutter (12659): #2 Navigator.pushReplacement
package:flutter/…/widgets/navigator.dart:2105
E/flutter (12659): #3 MainCoordinator.logoutNavigation
package:domicilios/…/MainCoordinator/MainCoordinator.dart:62
E/flutter (12659): #4 UserActions.signOut.<anonymous closure>.<anonymous closure>
package:domicilios/…/View/ProfileTab.dart:222
E/flutter (12659): <asynchronous suspension>
This is the code that generates this error, I hope you can help me, thank you very much for your attention.
this is the class:
extension UserActions on _ProfileTabState {
void signOut(BuildContext context) {
AlertView.showAlertDialog(
model: AlertViewModel(
context,
const AssetImage('assets/logout.png'),
'Cierre de sesión en curso',
"¿Desear salir de la sesión actual?",
'Cerrar sesión',
"Cancelar", () {
_profileTabViewModel
.signOut()
.then((value) => coordinator.logoutNavigation(context: context));
}, () {
Navigator.pop(context);
}));
}
}
That's how I call it in the code:
onTap: () => signOut(context),
This is most likely due to the widget being unmounted before navigating.
You can check if the widget is mounted before navigating.
if (mounted) {
_profileTabViewModel.signOut().then((value) {
if (mounted) {
coordinator.logoutNavigation(context: context);
}
});
}
Also,
if(mounted){
Navigator.pop(context);
}

Flutter platform player already exists just audio

So happy with the just audio flutter package from Ryan Heise for our radio app. Best package I know.
We have no problems with iOS, but on Android now some strange behavior, especially on Android 10. I'm also using the audio service and audio session packages to play the radio as background music. When the user hits play, no music is playing and error in the console:
Error:
E/flutter ( 6721): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(Platform player 6f26b522-c6c3-4226-be22-80f9d15dfc2c already exists, null, null, null)
E/flutter ( 6721): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:653:7)
E/flutter ( 6721): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:296:18)
E/flutter ( 6721):
E/flutter ( 6721): #2 MethodChannelJustAudio.init (package:just_audio_platform_interface/method_channel_just_audio.dart:13:5)
E/flutter ( 6721):
E/flutter ( 6721): #3 AudioPlayer._setPlatformActive.setPlatform (package:just_audio/just_audio.dart:1255:13)
E/flutter ( 6721):
Code in main.dart:
Future<void> main() async {
// initialise audio_service with our audio_handler
myAudioHandler = await AudioService.init(
builder: () => MyAudioHandler(),
config: const AudioServiceConfig(
androidNotificationChannelId: 'com.ryanheise.myapp.channel.audio',
androidNotificationChannelName: 'Audio playback',
androidNotificationOngoing: true,
),
);
Code in audio_handler.dart:
Future<void> _loadRadio() async {
final session = await AudioSession.instance;
await session.configure(const AudioSessionConfiguration.music());
// Try to load the radio from the source and catch any errors.
try {
await _player.setAudioSource(AudioSource.uri(
Uri.parse([stream_address])));
} catch (e) {
print("Error loading audio source: $e");
}
}
What does this error mean? And why is it only giving problems on some Android versions?
On Android 12 this is not happening all the time.
On Android 10 this is happening a lot.
We have several user complaints with the Android platform.
The error was coming from a myAudioHandler.stop command inside an internet connection checker function. When removed, everything worked again with all our Android users. This code was for testing purposes, and shouldn't be there. I hope this helps others with this error. Thanks for your help.

Update new version is not working in flutter

I have a flutter app which has an update button. This is used to update when new version is available in play store. It works fine until few days before. But now it is not working. It only shows a notification when user has installed the same version otherwise an error will be thrown.
> 2022-07-04 12:01:39.072 27969-28023/? E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Bad state: No element
#0 ListMixin.firstWhere (dart:collection/list.dart:167)
#1 NewVersion._getAndroidStoreVersion (package:new_version/new_version.dart:157)
<asynchronous suspension>
#2 _SettingsPageState._checkVersion (package:bnews/ui_components/pages/settings_page.dart:196)
<asynchronous suspension>
So now I cant update my app using this update button. I use new_version flutter package to update. This is the code
void _checkVersion() async {
final newVersion = NewVersion(
androidId: "com.abc.def",
);
final status = await newVersion.getVersionStatus();
newVersion.showUpdateDialog(
context: context,
versionStatus: status!,
dialogTitle: "UPDATE!!!",
dialogText: "Please update the app from " + "${status.localVersion}" + " to " + "${status.storeVersion}",
updateButtonText: "Lets update",
);
}
I think package not found problem is there. But it works fine until few days before. I have also updated new_version package but still same problem. Is this problem with playstore?
this is a bug check pub.dev new_version issues
for checking if there is a new version, I use upgrader package, just wrap the home of your materialApp and it will handle everything:
home: UpgradeAlert(
upgrader: Upgrader(
showReleaseNotes: false,
dialogStyle: UpgradeDialogStyle.cupertino,
shouldPopScope: () => true,
),
child: MyHomepage(),
),
Anyone who still face this issue can try a new package new_version_plus,you can use the same code by just changing name,its that simple

Flutter md link not loading md file

I am using the flutter_markdown widget to display help info in my app.
Inside an md file I am using the link to another md file. Both md files are defined in the 'assets' list in the pubspec.yml file
### [Overview](resource:asset/doc/overview.md) / Match Screen ###
Then I'm using the 'onTapLink' event handler to capture the users tap on the link to reset the markup widget to display the new md file like...
Future<String> _getData(String aFileName) async{
return rootBundle.loadString(aFileName);
}
#override
Widget build(BuildContext context) {
// get
return Scaffold(
appBar: AppBar(title: Text('Help')),
body: FutureBuilder<String>(
future: _dataFuture,
builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
if (snapshot.hasData) {
return Markdown(data: snapshot.data!, onTapLink: (text,href,title) {
setState(() {
_dataFuture = _getData(href!);
});
},);
}
return Center(
child: CircularProgressIndicator(),
);
}),
);
}
However, the onTapLnk code is causing an exception where it can't load the md file name passed in 'hef'
E/flutter ( 7261): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Unable to load asset: resource:asset/doc/overview.md
E/flutter ( 7261): #0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:237:7)
E/flutter ( 7261): <asynchronous suspension>
E/flutter ( 7261): #1 AssetBundle.loadString (package:flutter/src/services/asset_bundle.dart:72:27)
E/flutter ( 7261): <asynchronous suspension>
E/flutter ( 7261):
Any suggestions?
Through testing I can separately display both md files, so its nothing to do with faulty asset definition in the pubspec.yml file.
Solved it
The link definition in the md file should be
### [Overview](asset/doc/overview.md) / Match Screen ###
not
### [Overview](resource:asset/doc/overview.md) / Match Screen ###

Flutter: flutter_driver error message and app screen stays black while testing

I'm trying to set up some integration tests for my Flutter app, but I'm running into some troubles.
While running my app in debug mode works fine, the app stays black when I'm trying to run it with flutter_driver.
This is the code of my flutter_driver/app.dart code:
import 'package:flutter_driver/driver_extension.dart';
import 'package:[MY_APP_NAME]/main.dart' as app;
void main() {
// This line enables the extension.
enableFlutterDriverExtension();
// Call the `main()` function of the app, or call `runApp` with
// any widget you are interested in testing.
app.main();
}
This is the code of my flutter_driver/app_test.dart file:
// Imports the Flutter Driver API.
import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart';
void main() {
group('My first test group', () {
// First, define the Finders and use them to locate widgets from the
// test suite. Note: the Strings provided to the `byValueKey` method must
// be the same as the Strings we used for the Keys in step 1.
final welcomeQuestion = find.byValueKey('welcomeQuestion');
FlutterDriver driver;
// Connect to the Flutter driver before running any tests.
setUpAll(() async {
driver = await FlutterDriver.connect();
});
// Close the connection to the driver after the tests have completed.
tearDownAll(() async {
if (driver != null) {
driver.close();
}
});
test('check flutter driver health', () async {
Health health = await driver.checkHealth();
print(health.status);
});
test('Check welcomeQuestion', () async {
// Use the `driver.getText` method to verify the counter starts at 0.
expect(await driver.getText(welcomeQuestion), "Are you feeling good today?");
});
});
}
This is the error message I'm getting while running flutter drive --target=test_driver/app.dart to perform the test:
00:00 +1 -1: [APP-NAME] Check welcomeQuestion [E]
DriverError: Error in Flutter application: Uncaught extension error while executing get_text: 'package:flutter_driver/src/extension/extension.dart': Failed assertion: line 189 pos 14: 'WidgetsBinding.instance.isRootWidgetAttached || !command.require
sRootWidgetAttached': No root widget is attached; have you remembered to call runApp()?
#0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:40:39)
#1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)
#2 FlutterDriverExtension.call (package:flutter_driver/src/extension/extension.dart:189:14)
<asynchronous suspension>
#3 BindingBase.registerServiceExtension.<anonymous closure> (package:flutter/src/foundation/binding.dart:512:32)
<asynchronous suspension>
#4 _runExtension (dart:developer-patch/developer.dart:84:23)
Original error: null
Original stack trace:
null
package:flutter_driver/src/driver/driver.dart 433:7 FlutterDriver._sendCommand
===== asynchronous gap ===========================
dart:async/future_impl.dart 22:43 _Completer.completeError
dart:async-patch/async_patch.dart 40:18 _AsyncAwaitCompleter.completeError
package:flutter_driver/src/driver/driver.dart FlutterDriver._sendCommand
===== asynchronous gap ===========================
dart:async/zone.dart 1053:19 _CustomZone.registerUnaryCallback
dart:async-patch/async_patch.dart 77:23 _asyncThenWrapperHelper
package:flutter_driver/src/driver/driver.dart FlutterDriver._sendCommand
package:flutter_driver/src/driver/driver.dart 677:41 FlutterDriver.getText
===== asynchronous gap ===========================
dart:async/zone.dart 1053:19 _CustomZone.registerUnaryCallback
dart:async-patch/async_patch.dart 77:23 _asyncThenWrapperHelper
package:test_api/src/backend/declarer.dart Declarer.test.<fn>.<fn>.<fn>
package:test_api/src/backend/invoker.dart 250:15 Invoker.waitForOutstandingCallbacks.<fn>
===== asynchronous gap ===========================
dart:async/zone.dart 1045:19 _CustomZone.registerCallback
dart:async/zone.dart 962:22 _CustomZone.bindCallbackGuarded
dart:async/timer.dart 52:45 new Timer
dart:async/timer.dart 87:9 Timer.run
dart:async/future.dart 174:11 new Future
package:test_api/src/backend/invoker.dart 399:21 Invoker._onRun.<fn>.<fn>.<fn>
00:00 +1 -1: [APP-NAME] (tearDownAll)
00:00 +1 -1: Some tests failed.
Unhandled exception:
Dummy exception to set exit code.
#0 _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:1112:29)
#1 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#2 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#3 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:391:30)
#4 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:416:5)
#5 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
Stopping application instance.
Driver tests failed: 255
What's important to mention is that the app screen stays black, so it seems like the driver can't attach to the original app and run it correctly. Does anybody have an idea how to fix that?
Update
running flutter --version:
Flutter 1.7.8+hotfix.4 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 20e59316b8 (8 weeks ago) • 2019-07-18 20:04:33 -0700
Engine • revision fee001c93f
Tools • Dart 2.4.0
And here's the blackened version of my main.dart:
import 'dart:convert';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_statusbarcolor/flutter_statusbarcolor.dart';
[... + many additional imports from other private packages]
void main() async {
//load the json config globally
await Config().loadConfig();
await SharedPrefsService().init();
await RealmService().init();
SessionHistoryService().init();
final Router router = Router();
[... a lot of router.define() functions....]
//set statusbar color
FlutterStatusbarcolor.setStatusBarWhiteForeground(true);
SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]).then((_) {
runApp(new MaterialApp(
localizationsDelegates: [
const AppLocalizationsDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate
],
supportedLocales: [
const Locale('en', 'US'), // English
const Locale('de', 'DE'), // German
// ... other locales the app supports
],
localeResolutionCallback:
(Locale locale, Iterable<Locale> supportedLocales) {
for (Locale supportedLocale in supportedLocales) {
if (supportedLocale.languageCode == locale.languageCode ||
supportedLocale.countryCode == locale.countryCode) {
//For Localization Testing:
// return const Locale('de', 'DE');
return supportedLocale;
}
}
return supportedLocales.first;
},
title: 'MY APP NAME',
home: SharedPrefsService().isFirstLaunch()
? FirstLaunchScreen(true)
: MainMenuPage(),
onGenerateRoute: router.generator));
});
}
In my case, this was enough:
// connects with the current running application
driver = await FlutterDriver.connect();
// Wait for the first frame to be rasterized during the app launch.
await driver.waitUntilFirstFrameRasterized();
Well, not sure why it was downvoted, here is the gh issue about that: https://github.com/flutter/flutter/issues/41029
Update:
It seems that we have a new library that will replace FlutterDriver, and you won't need to care about these issues anymore: https://medium.com/flutter/updates-on-flutter-testing-f54aa9f74c7e
:)
I had same issue and it seems that test starts executing before .init() methods from main() in main.dart are finished. Try setting pause at the beginning of your test and see if it works, in my case did. We are looking for a solution how to wait until whole main() is executed and than start the test execution, without using hard coded pause. Hope it helps
test('Check welcomeQuestion', () async {
await sleep(Duration(seconds: 5));
// Use the `driver.getText` method to verify the counter starts at 0.
expect(await driver.getText(welcomeQuestion), "Are you feeling good today?");
});
Assuming you only have the text Are you feeling good today? on your screen,
I recreated your case and didn't see any issue or black screen while running flutter driver test. I saw successful test execution:
my main.dart is as below:
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Text('Are you feeling good today?', key: Key('welcomeQuestion'),)
)
app.dart:
void main() {
// This line enables the extension
enableFlutterDriverExtension();
// Call the `main()` function of your app or call `runApp` with any widget you
// are interested in testing.
app.main();
}
app_test.dart:
group('My first test group', () {
// First, define the Finders and use them to locate widgets from the
// test suite. Note: the Strings provided to the `byValueKey` method must
// be the same as the Strings we used for the Keys in step 1.
final welcomeQuestion = find.byValueKey('welcomeQuestion');
FlutterDriver driver;
// Connect to the Flutter driver before running any tests.
setUpAll(() async {
driver = await FlutterDriver.connect();
});
// Close the connection to the driver after the tests have completed.
tearDownAll(() async {
if (driver != null) {
driver.close();
}
});
test('check flutter driver health', () async {
Health health = await driver.checkHealth();
print(health.status);
});
test('Check welcomeQuestion', () async {
// Use the `driver.getText` method to verify the counter starts at 0.
expect(await driver.getText(welcomeQuestion), "Are you feeling good today?");
});
});