plist_parser 0.0.3 copy "plist_parser: ^0.0.3" to clipboard
plist_parser: ^0.0.3 copied to clipboard

outdated

A Flutter Plugin for Plist parser supporting XML and Binary formats.

example/plist_parser_example.dart

import 'package:plist_parser/plist_parser.dart';

import 'dart:io';

const xml = '''
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>string_type</key>
  <string>hello plist</string>
  <key>int_type</key>
  <integer>12345</integer>
  <key>double_type</key>
  <real>12.345</real>
  <key>bool_type_true</key>
  <true/>
  <key>bool_type_false</key>
  <false/>
  <key>date_type</key>
  <date>2022-02-11T18:27:45Z</date>
  <key>data_type</key>
  <data>VGVzdCBWYWx1ZQ==</data>
  <key>dict_type</key>
  <dict>
    <key>key1</key>
    <string>value1</string>
    <key>key2</key>
    <integer>2</integer>
    <key>long_key_item_name_aaaaa_bbbbb_ccccc_ddddd_eeeee</key>
    <string>long_key_item_value_11111_22222_33333_44444_55555</string>
  </dict>
  <key>array_type</key>
  <array>
    <string>array item1</string>
    <string>array item2</string>
  </array>
  <key>array_type2</key>
  <array>
    <string>array2 item1</string>
    <dict>
      <key>nest_array</key>
      <array>
        <string>nest_array_item</string>
      </array>
      <key>nest_dict</key>
      <dict>
        <key>nest_dict_item</key>
        <integer>12345</integer>
      </dict>
    </dict>
  </array>
</dict>
</plist>
''';

void main() async {
  // parse from xml string
  //
  // parse method detects plist format and use xml or binary parser
  // default is typeDetection = true
  // to disable the detection, use typeDetection = false
  var result = PlistParser().parse(xml);
  print(result);
  print("int_type: ${result["int_type"]}");
  print("array_type[1]: ${result["array_type"][1]}\n");

  // parse from plist file
  PlistParser()
      .parseFile("${Directory.current.path}/example/example.plist")
      .then((value) => print("parseFile\n$result\n"));

  // parse from plist file sync
  result = PlistParser()
      .parseFileSync("${Directory.current.path}/example/example.plist");
  print("parseFileSync\n$result\n");

  // parse from binary file
  var filePath = "${Directory.current.path}/example/example_binary.plist";
  PlistParser().parseBinaryFile(filePath).then((value) {
    print("parseBinaryFile\n$value\n");
  });

  // parse from binary file sync
  filePath = "${Directory.current.path}/example/example_binary.plist";
  print(
      "parseBinaryFileSync\n${PlistParser().parseBinaryFileSync(filePath)}\n");

  // parse from binary file sync
  filePath = "${Directory.current.path}/example/example_binary.plist";
  print(
      "parseBinaryFileSync\n${PlistParser().parseBinaryFileSync(filePath)}\n");

  // parse from binary file with type detection
  var file = File(filePath);
  var binaryText = String.fromCharCodes(file.readAsBytesSync());
  print("parse for binary data\n${PlistParser().parse(binaryText)}\n");
}
11
likes
0
pub points
84%
popularity

Publisher

unverified uploader

A Flutter Plugin for Plist parser supporting XML and Binary formats.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

meta, xml

More

Packages that depend on plist_parser