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").
Related
I wish to localize a Flutter application where locales are fetched by an API call, given the requested language.
I was hoping to be able to use the Intl package or something similar, but I am not sure this is possible without the .arb files.
Any ideas on how to accomplish this without reinventing the wheel?
(Having the localizations stored locally is not an option)
Down below, you can see a class which is converted to a singleton pattern. You can use any service locator package. It will be the same thing.
Now you can call this class in your main function, default set to EN.
Now let's say, you want to support SPANISH and not want to use .arb files
Now you can call google translate and replace values with the existing one. for every variable. I hope this helps.
Use https://pub.dev/packages/localizely_sdk package, it provides what you want to achieve
Turns out easy_localization has the functionality described. Simply creating a custom HttpAssetLoader and passing it to the easy_localization initialization method works out of the box, and provides device language detection, and application rebuild on locale change as intended.
I want to access a file from material.dart library ('src/material/search.dart';) so that I can access private fields (_somethingsomething) in it to create a widget.
I read a bit about part/part of and so on, but it seems that I am not using it properly.
Is something like this possible?
Steps: Copying a file from Flutter into your own app.
Create a file search_copy.dart, and copy the content of material's search.dart.
Remove the internal imports used in the file.
Instead add the import import 'package:flutter/material.dart' to search_copy.dart
Modify the new file according to your needs, like exposing the private field.
Import the file with a prefix import 'search_copy.dart' as search; so you don't get import conflicts with material itself.
When you want to access it do so like search.showSearch(context: context, delegate: delegate)
Note: The search.dart file is part of flutter itself which is BSD-licensed. (https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/material/search.dart)
License:
https://github.com/flutter/flutter/blob/master/packages/flutter/LICENSE
The answer is NO. And probably there is a reason why these fields are private since package owners (in this case, framework maintainers) do not want the developer to use the variables directly or change them in any way.
If you would like to adjust the code for the component in the material library, you could:
a) Create an issue under flutter repository and explain why you need to access the fields, maybe even create a POC by forking the repository and implementing your changes. The Flutter team may approve this and your changes will be a part of the framework - that's the beauty of open-source! However, there is no guarantee that it will happen.
b) Copy-paste the search.dart code to your project and adjust whatever is needed. This is a faster solution to your problem, however, now you should maintain this code by yourself, you would need to keep this component in sync with any Flutter update.
Is there option to reuse result of initialize method for video_player package? It takes time for complete - it would be great to cache it (eg. memory level) and reuse it when you back to before used video - and simple use cached data instead of wait for initialize result. I need it for intensive switching between videos.
There is a package called cached_video_player which may help resolve your problem. Check it out here.
I think you are asking about having the screen/page/widget pre-render. That is not currently supported by flutter according to this issue filed on github:
https://github.com/flutter/uxr/issues/6#issuecomment-881918751
Sure, but this is not very scalable and will quickly turn into a mess. It's much simpler and more flexible to just give MyRoute someway it can cache the next route, and then show that cached route when it needs. But flutter doesn't support this as everything needs to be 'on-stage' before it can be initialized. In AIR, or Unity, I could simply construct my new page, and it would begin loading data, I could then toss it on stage whenever I want.
PS. You probably already know you can pre-cache the video data/file itself.
I have a value store in Firebase config . When my app starts I would like to read the value and have it accessible from anywhere in my app.
I cannot use provider because I may not have the context. How can I do this in Flutter
Thanks
You can either store it in one dart file or in a class with variable with static field and whenever you need it you can grab it and read or change from there.
If it needs to stay even after you restart the app, you should use https://pub.dev/packages/shared_preferences package
I'm a beginnerĀ in Flutter and sometimes I'm not sure about the proper approach to get things done. In this case I would like to save a list of favorites and history views based on an api request. The idea is that when the user reloads the app the data is still on the mobile(let's say they can see their saved bookmarks). I'm not planning to use a database as firebase as I do not need nothing complicated. Which would be the best way/approach to accomplish it? I've been reading sqflite package but not sure if it is the way to go. Please could you give me some thoughts or ideas?
I think shared-preference would perfectly match your need.
https://pub.dev/packages/shared_preferences
Here you have one article, which describes how to use it: https://medium.com/flutter-community/shared-preferences-how-to-save-flutter-application-settings-and-user-preferences-for-later-554d08671ae9
Yep as #jaop said , Shared Preferences is the best choice , but still if u want most probability of getting the data then u can use , Along with Shared Preferences , Provider or passing data from one page to another . This decreases the chance of not getting data from Shared Preferences , which happens very rarely but still.