How can I save my firestore database data locally? [closed] - flutter

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 days ago.
Improve this question
Where can I store my loaded data from firestore database and access it anywhere I want? Is there any storage available or package that stores data locally? Secondly, Can I store the data in the cache for the next time when user uses the application second time?
Please view the image below: It is my firestore database. Right now it has limited data but in future it will be increased upto 1000 or maybe more than that. Database
Please suggest me with a code example or reference because I am new in this.
I appreciate your effort and inputs into this matter thankyou.

for the storing locally there is package called Hive
so here are the steps:
step 1:
run flutter pub add Hive &
flutter pub add hive_flutter
step 2:
and them to dev dependencies in pubscpec.yaml
step 3:
import them &
at main():
make it async and write
await Hive.initFlutter();
ok so flutter works with boxes you store data in a box
so at the start you define the box and open it
step 4:
add var box = Hive.openBox("boxname");
but when you already initialized the box you can use:
var box = Hive.box("box name");
How to use the box:
Add:
box.add("key",item); // key is dynamic key is like the name of an container in a box container can contain many things
delete:
box.delete(key) // this deletes the whole container
Update:
box.put("key",value);
Read:
box.get("key");

Related

Exclude material fonts from flutter web release

I'm currently developing a flutter web application.
I notice that the application takes a lot of time to load (an average of 20 seconds).
The fetch of the 'FontManifest.json' and the fonts 'MaterialIcons-Regular.otf' and 'CupertinoIcons.tff' takes an average of 10 seconds.
I'm not using any of these fonts, as I installed google fonts. It's just wasting time and data.
My question is: how can I get rid of these two fonts in flutter web or how can I reduce the time of waiting tffb + content downloading?
I tried to edit the 'FontManifest.json' and remove the '.otf' and '.tff' but as the files are auto generated, flutter rewrite them during each build.
I don't want to set use-material-design to false because i need some other features.
I already tried to edit the 'fonts' field of the 'pubspec.yaml' file, it doesn't work.
I have already read a few posts, but the questions mostly concerns display problems.
Thanks in advance for your help!
There is a way instead to possibly optimize the build time of the other packages by using the command
cp -r ./build/app/intermediates/flutter/release/flutter_assets/ ./build/web/assets
and the treeshake function available by flutter
--tree-shake-icons
you can read more here

Create a global variable for text size in Flutter

I'm developing a Flutter App, and one of the steps I need to take is to implement a way for user to increase/decrease the size of the text. For that, I'm thinking about making a slider in the settings page, which is quite straight-forward, but I don't know how to create a global value, change it (so it can't be a constant) and use it everywhere.
Any help is much is much appreciated !
You can store persistent data using shared_preferences or get_storage.
You can use the Hive framework to store the data locally on the device - https://docs.hivedb.dev/#/
First install Hive as a dependency and import it. Initialize Hive using Hive.initFlutter() (in the hive_flutter package).
Open a box using Hive.openBox("boxName"). Store the box as a variable - var box = Hive.box("boxName").
Add data into the box using box.put("key", "value").
Then you can access the data from anywhere you want by calling Hive.get("key").

How do I detect user screenshots, without screenshot_callback [no duplicate]

I asked this question before but I got closed. Because it is a duplicate, but it isn't. I don't want to disable screenshots I only want to detect screenshots. So this question is not a duplicate of  Flutter: disable screenshot capture for app
I currently run into a problem I tried to detect if a user is taking a screenshot. So I found this package screenshot_callback, but it didn't work, I used the example file of the package and nothing happened when taking a screenshot. I tried it on my android emulator and on my phone, it didn't work on both of them So I wrote an issue report on git but no one answered.
So I was wondering is there any way to detect a user screenshot without using this package, I couldn't find any way to do so, but maybe someone else knows the answer.
I use Flutter/Dart.
try this package
import 'package:screen_capture_event/screen_capture_event.dart';
listenScreenShot() {
screenListener.addScreenShotListener((filePath) {
print("fresh screenshot!");
});
screenListener.watch();
}

How to import custom css and js in Ionic 4 [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am using a custom theme for my app in ionic. But it has some css and javascript dependencies except bootstrap.
Could you help me how can I import these libraries to my app?
Regards
It sounds like you are probably missing some Angular usage theory if you are trying to import Bootstrap into your project.
It uses a specific set of classes and they aren't out-of-the-box compatible with Angular / Ionic.
Ionic will give you a cross-device baseline set of styles so you should really work with Ionic to build upon their styles rather trying to fight it with another system.
However, to answer your questions:
Importing CSS
You can edit app.scss and reference files in your imported packages like this:
#import '~#swimlane/ngx-datatable/release/assets/icons';
Notice the ~ at the start and then the package name, then the path to the file. You don't need to put the .css or .scss on the end but you can if you want to.
Importing JS
I'm not sure the best way to do this, but you can include scripts in the <head> tag by editing the index.html.
It's not something that's really done though and sounds like you are misunderstanding the way Angular / Ionic works.
It's based around building web components and you let Angular manage the actual live html. Your code that you write is TypeScript and its to interact with various API's that set the data model and then you let Angular generate the actual script.
There is library for loading asynchronous JavaScript files. https://www.npmjs.com/package/scriptjs
Install the package:
npm i scriptjs
Then use it anywhere like below:
import { get } from 'scriptjs';
ngOnInit() {
get("assets/js/searchEmp.js", () => {
getSerchInspContext = this;
loadSearchEmp();
});}`
OR
You can simply use the jquery method to append or remove the script tag in your header.
To add .js file, call below line under ngOnInit():
$('head').append('<script async src="assets/js/search.js"></script>');
Remove .js file:
document.querySelector('script[src="assets/js/search.js"]').remove();

How to add notes functionality in myApp in iphone?

I want to add notes functionality in myApp in iphone so that whenever i would open that notes in future,I would get that along with the date and time of writing that note.
Edit-1:
I want to make notes in my application. I also want to add edit functionality in that notes so that whenever i will open that in future I would be able to edit that and store that for the future with time and date of editing that notes.So i want to make list of the notes which i would make for myself in my application.Please help me regarding this.Thanks in advance and ask whatever u want to give the answer of this question.
What you're trying to do seems very simple. There are SEVERAL ways to go about doing something like that. A couple options off the top of my head:
Create a "Note" object with properties like:
NSString note;
NSDate lastEdited;
And just store it in a file. So whenever the user modifies your data just go:
lastEdited = [NSDate date]; To set the date to the current time.
Personally the way I would handle this is to persist(store) the data in Core Data. That way instead of having to write your data to file each time it's modified you can save the data in one line of code:
[myNote.managedObjectContext save:&error].
I hope this helps. If not there's a similar question that has already been answered here:
Save object in CoreData