Missing plugin exception - flutter

I got an error for unhandled plugin exception for google_fonts and shared_preferences:
Unhandled Exception: MissingPluginException(No implementation found
for method getAll on channel plugins.flutter.io/shared_preferences)
Unhandled Exception: MissingPluginException(No implementation found
for method getApplicationSupportDirectory on channel
plugins.flutter.io/path_provider) MethodChannel.invokeMethod
(package:flutter/src/services/platform_channel.dart:332:12)
_localPath (package:google_fonts/src/file_io_desktop_and_mobile.dart:28:27)
googleFontsTextStyle
(package:google_fonts/src/google_fonts_base.dart:107:3)

import androidx.annotation.NonNull
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(#NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}
By adding above code solved the problem it was suggested on GitHub
link

I'm solved with change code from mainactivity.kt or mainactivity.java.
import androidx.annotation.NonNull
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity: FlutterFragmentActivity() {
override fun configureFlutterEngine(#NonNull flutterEngine:
FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine)
}
}
after that, flutter clean and run

Related

Exception! need both FlutterFragmentActivity vs FlutterActivity

I have a situation where I need to use local_auth which expects FlutterFragmentActivity as main activity, but on the other hand I also wanna use video_player package which expects FlutterActivity as main activity.
Main Activity for local_auth:
package //your package name for eg.com.example.filename
import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity: FlutterFragmentActivity() {
override fun configureFlutterEngine(#NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}
Main Activity for video_player:
package //your package name for eg.com.example.filename
import android.content.Context
import android.os.Bundle
import androidx.annotation.NonNull
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.videoplayer.*
class MainActivity : FlutterActivity() {
override fun configureFlutterEngine(#NonNull flutterEngine:
FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
flutterEngine.getPlugins().add(VideoPlayerPlugin())
}
}
Is there a way to combine both activities so that both packages get their own required FlutterActivity and FlutterFragmentActivity for functioning?
If I use main activity as FlutterFragmentActivity app crashes while compiling and video_player package works smoothly, and if I use FlutterActivity app compiles successfully, but local_auth didn't worked because it requires FlutterFragmentActivity for auth apis to function.

FlutterError (Unable to load asset: assets/audio/assets/Sound3.mp3)

I want to play an audio as the app background music(without button click/autoplay). The code seen like no problem, but cant display.Did I do anything wrong with the code?
import 'package:flutter/material.dart';
import 'package:flame/game.dart';
import 'package:flame/input.dart';
import 'package:flame_audio/flame_audio.dart';
import 'package:flutter/widgets.dart';
void main() {
runApp(GameWidget(game: Audio()));
}
class Audio extends FlameGame with TapDetector {
#override
Future<void> onLoad() async {
super.onLoad();
}
#override
void onTapUp(TapUpInfo) {
FlameAudio.bgm.play('assets/Sound3.mp3');
}
}
pubspec.yaml
assets:
- assets/Sound3.mp3
[The Error Show in C:\flutter_windows_2.10.4-stable\flutter\packages\flutter\lib\src\services\asset_bundle.dart][1]
[1]: https://i.stack.imgur.com/p383i.png
const AssetImage('icons/heart.png', package: 'my_icons');
Assets used by the package (or plugin) itself should also be fetched using the package argument.
line: https://docs.flutter.dev/development/ui/assets-and-images

How to handle cache since the cache package is not available for flutter version 2 in pub.dev

The Code above shows a section from bloclibrary.dev Complete Code example on BlocLibrary.dev on how to build the UI for login screen using bloc and Firebase. Since there is no available version of cache in pub.dev, I do not know how to replace the CacheClient variable properly.
import 'dart:async';
import 'package:authentication_repository/authentication_repository.dart';
import 'package:cache/cache.dart';
import 'package:firebase_auth/firebase_auth.dart' as firebase_auth;
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:google_sign_in/google_sign_in.dart';
import 'package:meta/meta.dart';
/// Thrown if during the sign up process if a failure occurs.
class SignUpFailure implements Exception {}
/// Thrown during the login process if a failure occurs.
class LogInWithEmailAndPasswordFailure implements Exception {}
/// Thrown during the sign in with google process if a failure occurs.
class LogInWithGoogleFailure implements Exception {}
/// Thrown during the logout process if a failure occurs.
class LogOutFailure implements Exception {}
/// {#template authentication_repository}
/// Repository which manages user authentication.
/// {#endtemplate}
class AuthenticationRepository {
/// {#macro authentication_repository}
AuthenticationRepository({
CacheClient? cache,
firebase_auth.FirebaseAuth? firebaseAuth,
GoogleSignIn? googleSignIn,
}) : _cache = cache ?? CacheClient(),
_firebaseAuth = firebaseAuth ?? firebase_auth.FirebaseAuth.instance,
_googleSignIn = googleSignIn ?? GoogleSignIn.standard();
final CacheClient _cache;
final firebase_auth.FirebaseAuth _firebaseAuth;
final GoogleSignIn _googleSignIn;
You can find the CacheClient implementation here:
https://github.com/felangel/bloc/blob/master/examples/flutter_firebase_login/packages/cache/lib/cache.dart

Error while handling Appcheck with flutter

I want to upload files in the firebase storage, but i have an error of appcheck after many researches, i saw that i have to activate Appcheck on firebase, but also to activate it on my application
in a google video on youtube, i have seen that i have to call this function while building my app:
initFirebase(){
FirebaseApp.initializeApp(/*context*/ this);
FirebaseAppCheck firebaseAppCheck = FirebaseAppCheck.getInstance();
firebaseAppCheck.installAppCheckProviderFactory(
SafetyNetAppCheckProviderFactory.getInstance());
}
But i have errors, that the methods "initializeApp";"getInstance" and "installAppCheckProviderFactory" are not defined,
Your MainActivity.kt shoul look like this:
package com.example.app //your package name
import androidx.annotation.NonNull
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import com.google.firebase.FirebaseApp
import com.google.firebase.appcheck.FirebaseAppCheck
import com.google.firebase.appcheck.debug.DebugAppCheckProviderFactory
class MainActivity: FlutterActivity() {
private val CHANNEL = "samples.flutter.dev/battery"
override fun configureFlutterEngine(#NonNull flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler {
call, result ->
FirebaseApp.initializeApp(/*context=*/this)
val firebaseAppCheck = FirebaseAppCheck.getInstance()
firebaseAppCheck.installAppCheckProviderFactory(
DebugAppCheckProviderFactory.getInstance()
)
}
}
}
And your main.dart like this:
import 'package:firebase_app_check/firebase_app_check.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
await FirebaseAppCheck.instance.activate();
}

Flutter Bloc Test : Null check operator used on a null value (null-safety)

I am using flutter_bloc, bloc_test, and bloc_testing to implement testing. But even after I initialize Bloc in Setup the errors say Null check operator used on a null value.
import 'package:bloc_test/bloc_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:orotask/logic/bloc/map_bloc/map_bloc.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:orotask/logic/repository/addr_map_repository.dart';
class MockAddrRepository extends Mock implements MapAddrRepository {}
void main()async {
late MapAddrRepository mapAddrRepository ;
late MapBloc mapBloc;
await Firebase.initializeApp();
setUp(() {
mapAddrRepository = MapAddrRepository();
mapBloc = MapBloc();
});
tearDown(() {
mapBloc.close();
});
blocTest<MapBloc, MapState>('Map Bloc Initial State Tests',
build: () => mapBloc,
expect: () => MapNotLoaded());
}
Error in flutter test --no-sound-null-safety
(I have some dependencies which don't support null-safety)
00:20 +0 -1: loading C:\Users\Dell\Desktop\OroTask\orotask\test\src\bloc\visit_bloc\visit_bloc_test.dart [E]
Failed to load "C:\Users\Dell\Desktop\OroTask\orotask\test\src\bloc\visit_bloc\visit_bloc_test.dart": Null check operator used on a null value
package:flutter/src/services/platform_channel.dart 142:86 MethodChannel.binaryMessenger
package:flutter/src/services/platform_channel.dart 148:36 MethodChannel._invokeMethod
package:flutter/src/services/platform_channel.dart 331:12 MethodChannel.invokeMethod
package:flutter/src/services/platform_channel.dart 344:41 MethodChannel.invokeListMethod
package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart 30:37 MethodChannelFirebase._initializeCore
package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart 77:13 MethodChannelFirebase.initializeApp
package:firebase_core/src/firebase.dart 41:47 Firebase.initializeApp
test\src\bloc\visit_bloc\visit_bloc_test.dart
14:18
the firbase app is not intalised as its future you need to wrap it in async
void main() async {
await Firebase.initializeApp();}