Giter VIP home page Giter VIP logo

dahkenangnon / json_bridge.dart Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 1.0 424 KB

Powerful. Flexible. Easy-to-use. Manage JSON files effortlessly in your Dart and Flutter apps.

Home Page: https://pub.dev/packages/json_bridge

License: BSD 3-Clause "New" or "Revised" License

Kotlin 0.21% Swift 1.95% Objective-C 0.06% Dart 27.95% CMake 28.59% C++ 31.99% C 2.18% HTML 2.78% Ruby 4.29%
configuration dart firstrun flutter json preferences jsonbridge

json_bridge.dart's Introduction

JSON Bridge for Dart and Flutter

Powerful. Flexible. Easy-to-use. Manage JSON files effortlessly in your Dart and Flutter apps.


Improvement in Progress

Currently, I'm working on the following improvements. Keep in mind that there are not yet available in the current version of the package.

  • Fix typo in doc comments (✅)
  • Add default value to the fileName (json_bridge_data.json) passed to the init method (✅)
  • You can leave the .json file extension or not, it will be added automatically if not present (✅)
  • Add ability to choose predefined path to save the json file in: (✅)
    • applicationDocumentsDirectory,
    • applicationSupportDirectory,
    • externalStorageDirectory,
    • libraryDirectory,
    • temporaryDirectory,
    • customDirectory (you can pass a custom path to the init method)
  • Provide example app for each supported platform in progress (⌛️)

Compatibility and Platform Support

Compatible with:

  • Dart SDK: >=2.14.0 <3.0.0
  • Flutter: >=2.10.0

Platform support:

Platform Support
Android ✔️
iOS ✔️
Linux ✔️
macOS ✔️
Windows ✔️

Why Choose JSON Bridge?

🚀 Supercharge your Dart and Flutter apps with JSON Bridge – the ultimate solution for managing JSON files with ease.

✨ Store and retrieve data effortlessly from a JSON file.

📂 Seamlessly manage JSON files in the application document directory or a custom directory.

🔎 Manipulate nested keys using the dot notation with JSONBridge.

⚙️ Use JSONBridge to store user preferences, settings, data, and more.

🔥 Build powerful NoSQL databases for Dart and Flutter apps with JSONBridge.

💾 Store any data in a JSON file within your application.

👋 Engage users by customizing the app experience based on their preferences stored with JSONBridge.

⏳ Track user activity and restore the last seen screen when the app restarts.

💡 The possibilities are endless – let your imagination run wild!


Getting Started

1. Add the JSON Bridge dependency to your pubspec.yaml file:

dependencies:
  # Replace [latest_version] with the latest version of JSON Bridge.
  json_bridge: ^latest_version

2. Import the package in your Dart or Flutter code:

import 'package:json_bridge/json_bridge.dart';

3. Initialize the package:

// Omit `dir` to use the default Flutter application document directory (no permission required).
// If you specify a `dir`, make sure to set the necessary permissions as you will be accessing an external directory.
// For more information, see: https://developer.android.com/training/data-storage/app-specific#external
JSONBridge jsonBridge = JSONBridge()..init(fileName: 'config', dir: 'test');

4. Start using JSON Bridge:

4.1. Write data to the JSON file:

Note that using the write method will overwrite the entire file. If you want to add a key/value pair or a new JSON object, consider using the set method.

jsonBridge.write({
  'name': 'John Doe',
  'age': 25,
  'address': {
    'street': 'Main Street',
    'city':

 'New York',
    'country': 'USA'
  }
});

4.2. Clear the JSON file and delete it:

jsonBridge.clear();

4.3. Read the entire content of the JSON file:

Map<String, dynamic> dataFromJsonBridge = jsonBridge.read();

Your dataFromJsonBridge variable will contain the entire content of the JSON file as a Map<String, dynamic>.

4.4. Add a new JSON object:

jsonBridge.set('preferences', {
  'dark': true,
  'receive_notification': false,
  'show_update_notification': true,
});

4.5. Update a nested key/value pair:

Let's say we want to update the dark mode preference to false:

jsonBridge.set('preferences.dark', false);

4.6. Get a value:

Use dot notation to access nested keys. If a key is not found, the method will return null. If a key contains invalid characters, an error will be thrown.

String name = jsonBridge.get('name'); // 'John Doe'

int age = jsonBridge.get('age'); // 25

String street = jsonBridge.get('address.street'); // 'Main Street'

String city = jsonBridge.get('address.city'); // 'New York'

String country = jsonBridge.get('address.country'); // 'USA'

bool dark = jsonBridge.get('preferences.dark'); // false

bool receiveNotification = jsonBridge.get('preferences.receive_notification'); // false

bool showUpdateNotification = jsonBridge.get('preferences.show_update_notification'); // true

4.7. Delete a key:

jsonBridge.delete('preferences.show_update_notification');

4.8. Check if a key exists:

bool exists = jsonBridge.exists('preferences.dark'); // true

bool exists = jsonBridge.exists('iKnowThisKeyDoesNotExist'); // false

API Reference

The following table lists all the available methods in JSONBridge. Use dot notation for accessing nested keys.

Method Description
void init({required String fileName, String? dir}) Initialize the bridge by creating the JSON file. This method should be called before any other methods.
Map<String, dynamic> read() Read the JSON file and return its contents as a Map.
void write(Map<String, dynamic> data) Write a Map into the JSON file, overwriting the existing content.
void clear() Delete the JSON file and its contents.
void set(String key, dynamic value) Add or update a key in the JSON file.
void delete(String key) Delete a key from the JSON file.
dynamic get(String key) Get the value associated with a key from the JSON file.
bool has(String key) Check if a key exists in the JSON file.

Support and Contributions

Have questions or need support? Email us at [email protected]. We're here to help!

Contributions are welcome and greatly appreciated. Help us make JSON Bridge even better by following our contribution guidelines and code of conduct.

Join the JSON Bridge community now and experience the power of easy JSON file management in your Dart and Flutter projects!

License

This project is licensed under the BSD-3-Clause License. See the

LICENSE file for details.

GitHub Repo Stars

json_bridge.dart's People

Contributors

dahkenangnon avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

sjarosz

json_bridge.dart's Issues

Can't create dir file

I just do an example as below:

void initState() {
super.initState();
JSONBridge jsonBridge = JSONBridge()..init(fileName: 'multilingual');
jsonBridge.write({
'name': 'John Doe',
'age': 25,
'address': {
'street': 'Main Street',
'city': 'New York',
'country': 'USA'
}
});
}
But when build with iOS version, I get the error that can't create dir file as the screenshot below

Screen Shot 2023-08-16 at 3 22 29 PM

Do you have any idea about it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.