diff --git a/.gitignore b/.gitignore index bb431f0..5c27990 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,7 @@ .pub-cache/ .pub/ build/ +pubspec.lock # Android related **/android/**/gradle-wrapper.jar diff --git a/example/pubspec.lock b/example/pubspec.lock deleted file mode 100644 index 48ee834..0000000 --- a/example/pubspec.lock +++ /dev/null @@ -1,160 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: - async: - dependency: transitive - description: - name: async - url: "https://pub.dartlang.org" - source: hosted - version: "2.5.0-nullsafety.2" - boolean_selector: - dependency: transitive - description: - name: boolean_selector - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0-nullsafety.2" - characters: - dependency: transitive - description: - name: characters - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0-nullsafety.4" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0-nullsafety.2" - clock: - dependency: transitive - description: - name: clock - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0-nullsafety.2" - collection: - dependency: transitive - description: - name: collection - url: "https://pub.dartlang.org" - source: hosted - version: "1.15.0-nullsafety.4" - fake_async: - dependency: transitive - description: - name: fake_async - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0-nullsafety.2" - flutter: - dependency: "direct main" - description: flutter - source: sdk - version: "0.0.0" - flutter_test: - dependency: "direct dev" - description: flutter - source: sdk - version: "0.0.0" - graphs: - dependency: transitive - description: - name: graphs - url: "https://pub.dartlang.org" - source: hosted - version: "0.2.0" - matcher: - dependency: transitive - description: - name: matcher - url: "https://pub.dartlang.org" - source: hosted - version: "0.12.10-nullsafety.2" - meta: - dependency: transitive - description: - name: meta - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0-nullsafety.5" - path: - dependency: transitive - description: - name: path - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.0-nullsafety.2" - rive: - dependency: "direct main" - description: - path: ".." - relative: true - source: path - version: "0.6.2" - sky_engine: - dependency: transitive - description: flutter - source: sdk - version: "0.0.99" - source_span: - dependency: transitive - description: - name: source_span - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.0-nullsafety.3" - stack_trace: - dependency: transitive - description: - name: stack_trace - url: "https://pub.dartlang.org" - source: hosted - version: "1.10.0-nullsafety.5" - stream_channel: - dependency: transitive - description: - name: stream_channel - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0-nullsafety.2" - string_scanner: - dependency: transitive - description: - name: string_scanner - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0-nullsafety.2" - term_glyph: - dependency: transitive - description: - name: term_glyph - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0-nullsafety.2" - test_api: - dependency: transitive - description: - name: test_api - url: "https://pub.dartlang.org" - source: hosted - version: "0.2.19-nullsafety.4" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0-nullsafety.4" - vector_math: - dependency: transitive - description: - name: vector_math - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0-nullsafety.4" -sdks: - dart: ">=2.11.0-0.0 <2.12.0" diff --git a/lib/src/rive_file.dart b/lib/src/rive_file.dart index 7928aa7..a2f18a8 100644 --- a/lib/src/rive_file.dart +++ b/lib/src/rive_file.dart @@ -21,11 +21,19 @@ class RiveFile { Backboard _backboard; Backboard get backboard => _backboard; - final List _artboards = []; + final _artboards = []; + + /// Returns all artboards in the file List get artboards => _artboards; + /// Returns the first (main) artboard Artboard get mainArtboard => _artboards.first; + /// Returns an artboard from the specified name, or null if no artboard with + /// that name exists in the file + Artboard artboardByName(String name) => + _artboards.firstWhere((a) => a.name == name, orElse: () => null); + bool import(ByteData bytes) { assert(_header == null, 'can only import once'); var reader = BinaryReader(bytes); diff --git a/pubspec.lock b/pubspec.lock deleted file mode 100644 index fa6cc0e..0000000 --- a/pubspec.lock +++ /dev/null @@ -1,153 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: - async: - dependency: transitive - description: - name: async - url: "https://pub.dartlang.org" - source: hosted - version: "2.5.0-nullsafety.2" - boolean_selector: - dependency: transitive - description: - name: boolean_selector - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0-nullsafety.2" - characters: - dependency: transitive - description: - name: characters - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0-nullsafety.4" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0-nullsafety.2" - clock: - dependency: transitive - description: - name: clock - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0-nullsafety.2" - collection: - dependency: transitive - description: - name: collection - url: "https://pub.dartlang.org" - source: hosted - version: "1.15.0-nullsafety.4" - fake_async: - dependency: transitive - description: - name: fake_async - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0-nullsafety.2" - flutter: - dependency: "direct main" - description: flutter - source: sdk - version: "0.0.0" - flutter_test: - dependency: "direct dev" - description: flutter - source: sdk - version: "0.0.0" - graphs: - dependency: "direct main" - description: - name: graphs - url: "https://pub.dartlang.org" - source: hosted - version: "0.2.0" - matcher: - dependency: transitive - description: - name: matcher - url: "https://pub.dartlang.org" - source: hosted - version: "0.12.10-nullsafety.2" - meta: - dependency: "direct main" - description: - name: meta - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0-nullsafety.5" - path: - dependency: transitive - description: - name: path - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.0-nullsafety.2" - sky_engine: - dependency: transitive - description: flutter - source: sdk - version: "0.0.99" - source_span: - dependency: transitive - description: - name: source_span - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.0-nullsafety.3" - stack_trace: - dependency: transitive - description: - name: stack_trace - url: "https://pub.dartlang.org" - source: hosted - version: "1.10.0-nullsafety.5" - stream_channel: - dependency: transitive - description: - name: stream_channel - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0-nullsafety.2" - string_scanner: - dependency: transitive - description: - name: string_scanner - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0-nullsafety.2" - term_glyph: - dependency: transitive - description: - name: term_glyph - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0-nullsafety.2" - test_api: - dependency: transitive - description: - name: test_api - url: "https://pub.dartlang.org" - source: hosted - version: "0.2.19-nullsafety.4" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0-nullsafety.4" - vector_math: - dependency: transitive - description: - name: vector_math - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0-nullsafety.4" -sdks: - dart: ">=2.11.0-0.0 <2.12.0" diff --git a/pubspec.yaml b/pubspec.yaml index e3820c1..5ab47b5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: rive description: Rive 2 Flutter Runtime. This package provides runtime functionality for playing back and interacting with animations built with the Rive editor available at https://rive.app. -version: 0.6.2+1 +version: 0.6.2+2 repository: https://github.com/rive-app/rive-flutter homepage: https://rive.app diff --git a/test/assets/multiple_artboards_0_6_2.riv b/test/assets/multiple_artboards_0_6_2.riv new file mode 100644 index 0000000..6db385e Binary files /dev/null and b/test/assets/multiple_artboards_0_6_2.riv differ diff --git a/test/rive_file_test.dart b/test/rive_file_test.dart new file mode 100644 index 0000000..2d81712 --- /dev/null +++ b/test/rive_file_test.dart @@ -0,0 +1,56 @@ +import 'dart:io'; +import 'dart:typed_data'; + +import 'package:flutter_test/flutter_test.dart'; +import 'package:rive/rive.dart'; + +void main() { + ByteData multipleArtboardsBytes; + + void loadTestAssets() { + multipleArtboardsBytes = ByteData.sublistView( + File('assets/multiple_artboards_0_6_2.riv').readAsBytesSync()); + } + + setUp(() { + loadTestAssets(); + }); + + test('Rive files load', () { + // Create a dummy RiveFile + final riveFile = RiveFile(); + expect(riveFile.import(multipleArtboardsBytes), true); + }); + + test('Rive files contain the correct number of artboards', () { + // Create a dummy RiveFile + final riveFile = RiveFile(); + riveFile.import(multipleArtboardsBytes); + expect(riveFile.artboards.length, 4); + }); + + test('A default artboard is available in a Rive file', () { + // Create a dummy RiveFile + final riveFile = RiveFile(); + riveFile.import(multipleArtboardsBytes); + expect(riveFile.mainArtboard, isNotNull); + expect(riveFile.mainArtboard.name, 'Artboard 1'); + }); + + test('Artboards can be retrieved by name', () { + // Create a dummy RiveFile + final riveFile = RiveFile(); + riveFile.import(multipleArtboardsBytes); + + var artboard = riveFile.artboardByName('Artboard 1'); + expect(artboard, isNotNull); + expect(artboard.name, 'Artboard 1'); + + artboard = riveFile.artboardByName('Artboard 3'); + expect(artboard, isNotNull); + expect(artboard.name, 'Artboard 3'); + + artboard = riveFile.artboardByName('Nonexistant'); + expect(artboard, isNull); + }); +}