Skip to content

Latest commit

 

History

History
 
 

tizen_bundle

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

tizen_bundle

pub package

Tizen Data Bundle APIs.

Usage

To use this package, add tizen_bundle as a dependency in your pubspec.yaml file.

depenedencies:
  tizen_bundle: ^0.1.1

Adding content to a bundle

The bundle content is in the form of key-value pairs. The key is always a String. The value must be either a String, a List<String>, or a Uint8List.

Bundles can be treated like a Map. You can use the [] operator or Bundle.addAll() to add data to a bundle.

import 'package:tizen_bundle/tizen_bundle.dart';

var bundle = Bundle();
bundle['string'] = 'value';
bundle['strings'] = <String>['value1', 'value2', 'value3'];
bundle['bytes'] = Uint8List.fromList(<int>[0x01, 0x02, 0x03]);

Accessing the bundle content

To get data from a bundle or update their values, use the [] operator.

var stringValue = bundle['string'];
if (stringValue is String) {
  print('string: $stringValue');
}

var stringsValue = bundle['strings'];
if (stringsValue is List<String>) {
  print('strings: $stringsValue');
}

var bytesValue = bundle['bytes'];
if (bytesValue is Uint8List) {
  print('bytes: $bytesValue');
}

You can also use other methods and properties supported by a Map, such as containsKey and remove.

if (bundle.containsKey('string')) {
  bundle.remove('string');
}

Encoding and decoding a bundle

To save bundle data to a file or send over network, you can encode them to a raw string using Bundle.encode(). To restore the bundle from the encoded string, use Bundle.decode().

var bundle = Bundle();
bundle['key'] = 'value';

var encoded = bundle.encode();
var newBundle = Bundle.decode(encoded);

print(newBundle['key']);