rive-flutter
rive-flutter copied to clipboard
Cannot access certain types in the public library
Description
There are a number of types that we can access by using the public API that are not exposed in lib/rive.dart
. In order to access them, we need to import from src/**
, which is discouraged. There is also a lint to prevent doing this:
https://dart-lang.github.io/linter/lints/implementation_imports.html
In the following, I am going to list a number of cases where we need to use implementation imports. I am not sure if the best fix is adding them to lib/rive.dart
. It might also be beneficial to have a lib/core.dart
file we could import.
import 'package:rive/src/rive_core/animation/linear_animation.dart';
import 'package:rive/src/rive_core/animation/state_machine_input.dart';
Use case: accessing information like the type of animation and name of the animation, passing the animation object around.
import 'package:rive/src/rive_core/runtime/exceptions/rive_format_error_exception.dart';
import 'package:rive/src/rive_core/runtime/exceptions/rive_unsupported_version_exception.dart';
Use case: catching version or format exceptions while dynamically loading Rive files, e.g. from network or the user's local files (in a CMS):
try {
await loadRiveFile();
} on RiveUnsupportedVersionException catch (e) {
// handle unsupported version.
} on RiveFormatErrorException catch (e) {
// handle format error.
}
import 'package:rive/src/animation_list.dart';
import 'package:rive/src/rive_core/animation/animation.dart';
Use case: querying animations.
import 'package:rive/src/rive_core/animation/linear_animation.dart';
import 'package:rive/src/rive_core/animation/state_machine_bool.dart';
import 'package:rive/src/rive_core/animation/state_machine_input.dart';
import 'package:rive/src/rive_core/animation/state_machine_number.dart';
Use case: querying animations and state machine inputs and working with them, e.g. allowing to select them (by name) in a CMS.
import 'package:rive/src/rive_core/runtime/runtime_header.dart';
Use case: checking the runtime version to check if Rive files are supported.
I might have forgotten some, but this should convey the general idea.
Package structure
@luigi-rosso I think that the current package structure is probably not ideal because idiomatically all implementation files are inside of a src/
directory and you only have Dart files that export '';
files from that directly in lib/
.
This is a good point, thanks! I'd prefer to not just export everything with rive.dart, but we recently started exposing some specific functionality via other imports. For example, see components.dart and math.dart
Sounds like we should do something similar for other groups of imports. Perhaps add two new imports like:
import 'package:rive/errors.dart';
import 'package:rive/animation.dart';
Let me know your thoughts or suggestions. Unfortunately the current package structure is somewhat constrained by the editor packages it generates from..
@luigi-rosso Thanks, that is what I was thinking as well!
I just meant that there are some more files that should move to lib
, likely.