How to reset a Hive Database in Flutter - flutter

I am playing around with the Hive Database for Flutter, and when I am trying to save an object, the documentations says about Adapters clearly:
As you can see, each field has a unique number (unique per class). These field numbers are used to identify the fields in the Hive binary format, and should not be changed once your class is in use.
So, after some refactoring, I need to change the classes and some attributes, including his numeration. After doing that obviously the database gives me error (was working perfectly before), and given that all the data from the database is dum data for testing purposes, I would like to Reser and restart a new Database form 0. I did try several things, like box.clear() or Hive.deleteFromDisk() after opening the boxes, but I am still getting an error about the Adapter attribute type does not match with another in the normal class (referencing the one before refactoring and changing the index).
How can I successfully remove all information and clean the database to start from Zero as a new install??
Thanks a lot!

Okkey, I found the answer:
The way to start the app as a new installation in the emulator is to desvnstall the app from the emulator and install it again.
Of course, if new changes to the index number in the Adapter, I would need to recreate these steps:
-Delete the adapters created
-Run flutter clean
-Delete the app from the emulator
-Create the new adapters with flutter packages pub run build_runner build
-Run the app again
Hope is useful for someone in the future :)

Ok, I see I had the same problem and I solved it in the following way:
First of all, delete the .hive and .lock files generated by hive when you first launch your application in the parent directory of your project.
Come back to modify it is what you want in your model and launch the following command:
flutter packages pub run build_runner build

Related

How to generate flutter code before every build

I'd like to have the output of some git describe call available inside my flutter app. It's important that this is run automatically before builds triggered by i.e. flutter run or flutter build apk. If I have to remember running a command manually before rebuilding the app in my IDE I won't get an accurate version number in the app.
I looked at https://pub.dev/packages/build_runner but that seems to require to always invoke it manually.
I also looked at --dart-define but through this I can just pass values into dart code but I also need a way to automatically update that value.
I did get this to work through gradle... but that is only invoked for android builds. Adding it additionally to the cmake layer would work... that still leaves web and iOS builds without a solution.
Anyone got an idea what I might be missing?
(flutter can already generate code for translations dynamically via the generate: true flag but this doesn't seem to be exposed through any way to add custom generation commands there?)

Why `Flutter Doctor` and `New Application Project` fails in my VSCode setup?

Following these directions, like:
Install the Flutter and Dart plugins
Start VS Code.
Invoke View > Command Palette….
Type “install”, and select Extensions: Install Extensions.
Type “flutter” in the extensions search field, select Flutter in the list, and click Install. This also installs the required Dart plugin.
Validate your setup with the Flutter Doctor
Invoke View > Command Palette….
Type “doctor”, and select the Flutter: Run Flutter Doctor.
Review the output in the OUTPUT pane for any issues. Make sure to select Flutter from the dropdown in the different Output Options.
Step 3 of validate instructions results with OUTPUT:
I did install flutter, and flutter doctor in a new command shell gives result:
What am I missing here? I also try VSCode extension palette command Flutter: New Application Project and that also fails with:
Make sure that you have installed Git and that you can access it from the command line. Check your PATH. Flutter SDK directory should be present there.
If that does not work, you should try to reinstall the dart and flutter extension.
Next Step should be to reinstall flutter.
It occurred to me that my attempt to support multiple flutter versions might be going outside of the conventions supported by the Flutter extension for VSCode.
Here's what's up!... If you think you're smart like me and installed different versions of flutter in folders like c:\src\flutter\1.20.2 and c:\src\flutter\1.22.6, then you can forget it because the extension is smarter than us, and will ignore this regardless of our PATH assignment.
Copying contents of my flutter install from c:\src\flutter\1.22.6 to the parent folder c:\src\flutter resolved my issue. I need to review how to easily support different versions of flutter. Hmmm..
BTW... what I realized in retrospect is that the complaint about git is raised by the extension not finding the .git folder under the flutter folder (i.e. c:\src\flutter) that it presumed as the path to my flutter install. Well duh!! That's because I want flutter to be sourced at the versioned sub-folder (i.e. c:\src\flutter\1.22.6). Oh well.
Some scenarios I am left pondering:
How to correctly support multiple flutter installations while also benefiting from the extension (is there a way to configure this extension or my environment as a whole)?
Are my expectations to support multiple flutter installations unreasonable?
If my expectations are reasonable, and there are no known or documented way to support multiple flutter installations while also using this extension, then perhaps the extension has a bug?

Flutter web throws error on same project but different laptop

So I just won a new laptop in a competition and now I am having some trouble migrating my flutter projects. I have set up the editor and migrated the important files in the code, i.e the lib, image, font, pubspec.yaml and web. But this app is now throwing the following error
Launching lib\main.dart on Chrome in debug mode...
Waiting for connection from debug service on Chrome...
ERROR - 2020-12-29 13:08:07.845202
GET /main_module.bootstrap.js
Error thrown by handler.
AbsoluteImportUriError: 'file:///C:/FlutterProjects/xspectre/lib/help/Auth.dart'
package:dwds/src/debugging/metadata/provider.dart 154:9 MetadataProvider._addMetadata
package:dwds/src/debugging/metadata/provider.dart 133:15 MetadataProvider._initialize.<fn>
I thought it may be a problem with my flutter but it runs the default flutter app without problem.
I also tried deleting the file but the problem just shifts to another file. I can safely say that this a is a problem with the help folder which provides me essential tools such as the auth service. What should I do? I will provide any code neccesary. You can find the entire code here
The Error:
The error is happening because when importing your new project, some imports in your .dart files are now using absolute paths instead of relative paths. In your case, this is happening at least in one .dart file that is calling your Auth.dart.
Sloution:
Step 1: Look at the top of all your .dart files, more precisely at every single import. You will have to change everything starting with:
import 'file:///C:/...
by
import 'package:... and add the name of your app
Step 2: Rerun your project and everything should work now
If still issues, then make sure you looked at all your files to ensure you did not miss other wrong import... also, you can run flutter clean then run a Pub Get
(thanks to melwinlobo18)
Please mark the answer if this was useful ;0)

How do I edit running configuration in Flutter/Android Studio?

I created an app in Flutter and it was running fine, but I adjusted something and when I tried to debug it on the emulator, a new window popped up which I think was called "Configuration Editor" or something. I'd no idea what to do with it, but the app wouldn't run without it, so I entered some random data in one of the fields to see what would happen.
Now Android Studio seems to be trying to run the app with this data, and it won't run. I'm getting the error:
Target file "4,6,8" not found.
where "4,6,8" is the data I entered. I assume I need to blank out those fields again, but I don't know how to open the configuration file or whatever it was where I entered the data!
I assume you messed up the running configuration for the project, setting a file that doesn't exist "4,6,8".
Anyway, if this is the problem, you can configure it again in Android Studio:
Then set the entry file 'main.dart' of your project. The 'additional arguments' and 'flavor' are optional.
In my case it occur due to the reason that pubspec.yaml is missing that is why main.dart is not running as it did not found flutter sdk and other dependencies present pubspec.yaml file.

Cocoa application with SwiftPM

My general goal is to create an app, that grabs all data from the postgreSQL database. Firstly, I connected C API libpq to connect my database. Then, I found a nice wrapper around libpq to make my life easier, thanks to Perfect. To install this wrapper, I need to create Package.swift, add a dependency and regenerate my xcodeproj with swift package generate-xcodeproj.
But when I do that, the whole structure of my project is being rebuilt and, as a result, when I run the project, a simulator doesn't start and I lose understanding on what's happening and build usually fails.
New project structure
It would've been nice if somebody explained to me, what happens when I generate a project after adding Package.swift file and how to keep everything working with new packages being added.
... when I run the project, a simulator doesn't start and I lose understanding on what's happening and build usually fails.l
I suppose you already have the libpq added and working. If this is an iOS project, try just adding the PostgresSQL.swift instead of using the package.