Error Compiling Flutter Flame Game in VSCode After Flame Version Upgrade - flutter

After upgrading from Flame 1.0.0 to 1.3.0, my project stopped building with errors like so:
Error: Type 'HasHitboxes' not found.
package:project/…/sprite_components/player_component.dart:14
with HasGameRef, HasHitboxes, Collidable
The errors are related only to HitBoxes and Collidables, in that they are not found, I'm suspecting something needs importing in Flame 1.3.0.
These are my imports:
import 'package:flame/components.dart';
import 'package:flame/geometry.dart';
import 'package:flame/input.dart';
import 'package:flame/sprite.dart';
I tried:
flutter pub cache clean
flutter pub get
But no luck, is there anything else that needs doing?
P.S. If I downgrade back to 1.0.0, everything works fine.

HasHitboxes and Collidable aren't used anymore.
Hitboxes are now a first class component in Flame, so you just have to add the hitboxes directly to the component with component.add. If you want to listen for collisions with those hitboxes you have to add the CollisionCallbacks mixin to the component and the HasCollisionDetection to the game.
https://docs.flame-engine.org/1.3.0/flame/collision_detection.html

Related

By updating Flutter 3.8.0 Error in flutter_date_time_picker

By updating Flutter 3.8.0
I am getting the following error in flutter_date_time_picker.
I would like to know if anyone knows a solution to this problem.
../../../../.pub-cache/git/flutter_datetime_picker-eb66486c47d50bf550950c196486121ffcea8885/lib/flutter_datetime_picker.dart:7:1: Error:
'DatePickerTheme' is imported from both 'package:flutter/src/material/date_picker_theme.dart' and'package:flutter_datetime_picker/src/datetime_picker_theme.dart'.
pubspeck.yaml
flutter_datetime_picker:
git:
url: https://github.com/Realank/flutter_datetime_picker.git
If anyone knows of a solution, I would love to hear about it.
I believe this is probably due to the flutter update, as I was able to build normally until yesterday!
If anyone knows of a solution, I would love to hear about it.
You can try the following steps:
Remove the flutter_datetime_picker package from your pubspec.yaml file.
Run flutter clean in your terminal to remove any cached files.
Re-install the flutter_datetime_picker package.
first try to flutter clean and then pub get and reinstall the package you want. if again you had this error try this:
To resolve it; in the class where you have both imports, assign an alias to one of the packages using the as keyword.
import 'package:flutter/src/material/date_picker_theme.dart' as dp
dp.EveryMethodYouWant(); //call the class using the alias
if you had any question i'm here.
happy coding.
By mistakenly,you have imported the wrong package because as per the package documentation, there is no such line mentioned.
Import the package mentioned below and try pub get.
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
everything vill works fine.

Flutter assests_audio_player import doesn't work

My flutter has suddenly started giving me this error on assets_audio_player : "Undefined class 'AssetsAudioPlayer'.". The import for the player: import 'package:assets_audio_player/assets_audio_player.dart'; is also greyed out. I've tried upgrading the flutter & restarting the device but the issue is still there. Any clue what might've gone wrong? Thank you!
Before importing the package in your code, did you properly add its dependency in your "pubspec.yaml" file and then run the flutter pub get command?
I am guessing you're using this package.
Be sure to add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get).
dependencies:
assets_audio_player: ^3.0.4+1

The method 'registerMessageHandler' isn't defined for the type 'Registrar'

import 'package:cloud_firestore_web/cloud_firestore_web.dart';
import 'package:firebase_analytics_web/firebase_analytics_web.dart';
import 'package:firebase_auth_web/firebase_auth_web.dart';
import 'package:firebase_core_web/firebase_core_web.dart';
import 'package:fluttertoast/fluttertoast_web.dart';
import 'package:google_sign_in_web/google_sign_in_web.dart';
import 'package:pak_farmer/models/Register.dart';
import 'package:shared_preferences_web/shared_preferences_web.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
// ignore: public_member_api_docs
void registerPlugins(Registrar registrar) {
FirebaseFirestoreWeb.registerWith (registrar);
FirebaseAnalyticsWeb.registerWith(registrar);
FirebaseAuthWeb.registerWith(registrar);
FirebaseCoreWeb.registerWith(registrar);
FluttertoastWebPlugin.registerWith(registrar);
GoogleSignInPlugin.registerWith(registrar);
SharedPreferencesPlugin.registerWith(registrar);
registrar**.registerMessageHandler();**
}
I've written this code but it is giving me an error on the last line:
The method 'registerMessageHandler' isn't defined for the type 'Registrar'.
my error gone with flutter clean once and it will work fine for me
flutter clean didn't work for me. My problem was that I made the project in the Flutter beta channel and then opened in the stable channel. When I switched back to beta it was OK. Once web support enters stable this shouldn't be a problem anymore.
I faced the same issue when I downgraded Flutter from 2.0.0+ to 1.22.6. Developed the web panel in 2.0.0+ but after downgrading it for another app, saw this.
The error is likely if you created the project in stable version and for some reason you downgraded to a lower Flutter version.
FIX: Upgrade to the higher / updated version OR check the channel it was built on and shift to that channel.
You can see which channel you are currently on with flutter channel in your cmd.
Delete that autoGenerated file and run the application.

How do you integrate a flutter plugin into an existing flutter project?

I want to install a simple audio recorder which will record a user’s voice. I know I can find plugins on PubDev, however I have difficulty in integrating them into my Flutter project. I have installed ‘audio_recorder 1.0.2. in a new dart file as part of ‘lib’. I don’t know how to integrate this file into the flutter project. I have tried to a button in another dart file which when pressed would take the user to that file, without succes. ‘This class is not a widget’ is the message I get. The ‘GitHub’ version has the errors ‘undefined class’, ‘LocalFileSystem isn’t defined for the type ‘AudioRecorder’. The example version (why this difference?) has quite a few errors after installation. Dependencies and imports are ok. When I install audio_recorder 1.0.2 inside the project via ‘Dart packages’ I get a lot of errors. I have successfully installed an audio recorder in another android app. I would like some help in how to integrate plugins in a flutter project.
The plugins have instructions on how to install it. Got to your pubspec.yaml-file and put it under dependencies.
Make sure that you add your dependency to pubspec.yaml like this:
dependencies:
audio_recorder: ^1.0.2
After that make sure to type "flutter pub get" in console.
Go on a specified file in which you want to use Your dependency and import it like this:
import 'package:audio_recorder/audio_recorder.dart';

cannot import path_provider package

I'm building new flutter app, I've downloaded the last version of path_provider package, but when I try to import it using the import statement form the docs
import 'package:path_provider/path_provider.dart';
It didn't work, it says this package doesn't exist, instead I can import things like
import 'package:path_provider_linux/path_provider_linux.dart';
which doens't have the functionality I want.
Can you build the application?
Are you deploying to mobile or MacOS?
Try to run a fresh release configuration, and if it works, then reboot your IDE.
Then run the command that Confidence Yobo suggested, to redownload the packages via yaml.
Also make sure that your yaml file is formatted correctly. Once a pubspec GET command has finished running and the lock is released, normally if there is an error it will show up on your output window.
Also make sure to get the latest package: path_provider: ^1.6.18