mirror of
https://github.com/rive-app/rive-flutter.git
synced 2025-06-27 18:28:18 +08:00
Exposes antialiasing option in Rive and RiveAnimation
This commit is contained in:
@ -15,6 +15,7 @@ class SimpleAnimation extends StatelessWidget {
|
|||||||
child: RiveAnimation.network(
|
child: RiveAnimation.network(
|
||||||
'https://cdn.rive.app/animations/vehicles.riv',
|
'https://cdn.rive.app/animations/vehicles.riv',
|
||||||
fit: BoxFit.cover,
|
fit: BoxFit.cover,
|
||||||
|
antialiasing: false,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -6,6 +6,7 @@ import 'package:rive/src/rive_render_box.dart';
|
|||||||
import 'package:rive/src/runtime_artboard.dart';
|
import 'package:rive/src/runtime_artboard.dart';
|
||||||
|
|
||||||
class Rive extends LeafRenderObjectWidget {
|
class Rive extends LeafRenderObjectWidget {
|
||||||
|
/// Artboard used for drawing
|
||||||
final Artboard artboard;
|
final Artboard artboard;
|
||||||
|
|
||||||
/// Determines whether to use the inherent size of the [artboard], i.e. the
|
/// Determines whether to use the inherent size of the [artboard], i.e. the
|
||||||
@ -27,12 +28,19 @@ class Rive extends LeafRenderObjectWidget {
|
|||||||
/// this to `true`.
|
/// this to `true`.
|
||||||
final bool useArtboardSize;
|
final bool useArtboardSize;
|
||||||
|
|
||||||
|
/// Fit for the rendering artboard
|
||||||
final BoxFit fit;
|
final BoxFit fit;
|
||||||
|
|
||||||
|
/// Alignment for the rendering artboard
|
||||||
final Alignment alignment;
|
final Alignment alignment;
|
||||||
|
|
||||||
|
/// Enables/disables anitalising
|
||||||
|
final bool antialiasing;
|
||||||
|
|
||||||
const Rive({
|
const Rive({
|
||||||
required this.artboard,
|
required this.artboard,
|
||||||
this.useArtboardSize = false,
|
this.useArtboardSize = false,
|
||||||
|
this.antialiasing = true,
|
||||||
BoxFit? fit,
|
BoxFit? fit,
|
||||||
Alignment? alignment,
|
Alignment? alignment,
|
||||||
}) : fit = fit ?? BoxFit.contain,
|
}) : fit = fit ?? BoxFit.contain,
|
||||||
@ -40,6 +48,8 @@ class Rive extends LeafRenderObjectWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
RenderObject createRenderObject(BuildContext context) {
|
RenderObject createRenderObject(BuildContext context) {
|
||||||
|
// Doing this here and not in constructor so it can remain const
|
||||||
|
artboard.antialiasing = antialiasing;
|
||||||
return RiveRenderObject(artboard as RuntimeArtboard)
|
return RiveRenderObject(artboard as RuntimeArtboard)
|
||||||
..fit = fit
|
..fit = fit
|
||||||
..alignment = alignment
|
..alignment = alignment
|
||||||
@ -50,6 +60,7 @@ class Rive extends LeafRenderObjectWidget {
|
|||||||
@override
|
@override
|
||||||
void updateRenderObject(
|
void updateRenderObject(
|
||||||
BuildContext context, covariant RiveRenderObject renderObject) {
|
BuildContext context, covariant RiveRenderObject renderObject) {
|
||||||
|
artboard.antialiasing = antialiasing;
|
||||||
renderObject
|
renderObject
|
||||||
..artboard = artboard
|
..artboard = artboard
|
||||||
..fit = fit
|
..fit = fit
|
||||||
|
@ -15,15 +15,31 @@ enum _Source {
|
|||||||
/// animation are not specified, the default artboard and first animation fonund
|
/// animation are not specified, the default artboard and first animation fonund
|
||||||
/// within it are used.
|
/// within it are used.
|
||||||
class RiveAnimation extends StatefulWidget {
|
class RiveAnimation extends StatefulWidget {
|
||||||
|
/// The asset name or url
|
||||||
final String name;
|
final String name;
|
||||||
|
|
||||||
|
/// The type of source used to retrieve the asset
|
||||||
final _Source src;
|
final _Source src;
|
||||||
|
|
||||||
|
/// The name of the artboard to use; default artboard if not specified
|
||||||
final String? artboard;
|
final String? artboard;
|
||||||
|
|
||||||
|
/// List of animations to play; default animation if not specified
|
||||||
final List<String> animations;
|
final List<String> animations;
|
||||||
|
|
||||||
|
/// List of state machines to play; none will play if not specified
|
||||||
final List<String> stateMachines;
|
final List<String> stateMachines;
|
||||||
|
|
||||||
|
/// Fit for the animation in the widget
|
||||||
final BoxFit? fit;
|
final BoxFit? fit;
|
||||||
|
|
||||||
|
/// Alignment for the animation in the widget
|
||||||
final Alignment? alignment;
|
final Alignment? alignment;
|
||||||
|
|
||||||
/// Widget displayed while the rive is loading.
|
/// Enable/disable antialiasing when rendering
|
||||||
|
final bool antialiasing;
|
||||||
|
|
||||||
|
/// Widget displayed while the rive is loading
|
||||||
final Widget? placeHolder;
|
final Widget? placeHolder;
|
||||||
|
|
||||||
/// Creates a new RiveAnimation from an asset bundle
|
/// Creates a new RiveAnimation from an asset bundle
|
||||||
@ -35,6 +51,7 @@ class RiveAnimation extends StatefulWidget {
|
|||||||
this.fit,
|
this.fit,
|
||||||
this.alignment,
|
this.alignment,
|
||||||
this.placeHolder,
|
this.placeHolder,
|
||||||
|
this.antialiasing = true,
|
||||||
}) : src = _Source.asset;
|
}) : src = _Source.asset;
|
||||||
|
|
||||||
const RiveAnimation.network(
|
const RiveAnimation.network(
|
||||||
@ -45,6 +62,7 @@ class RiveAnimation extends StatefulWidget {
|
|||||||
this.fit,
|
this.fit,
|
||||||
this.alignment,
|
this.alignment,
|
||||||
this.placeHolder,
|
this.placeHolder,
|
||||||
|
this.antialiasing = true,
|
||||||
}) : src = _Source.network;
|
}) : src = _Source.network;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -88,23 +106,6 @@ class _RiveAnimationState extends State<RiveAnimation> {
|
|||||||
final res = await http.get(Uri.parse(widget.name));
|
final res = await http.get(Uri.parse(widget.name));
|
||||||
final data = ByteData.view(res.bodyBytes.buffer);
|
final data = ByteData.view(res.bodyBytes.buffer);
|
||||||
_init(data);
|
_init(data);
|
||||||
// final client = HttpClient();
|
|
||||||
// final contents = <int>[];
|
|
||||||
|
|
||||||
// client
|
|
||||||
// .getUrl(Uri.parse(widget.name))
|
|
||||||
// .then(
|
|
||||||
// (req) async => req.close(),
|
|
||||||
// )
|
|
||||||
// .then(
|
|
||||||
// (res) => res.listen(
|
|
||||||
// contents.addAll,
|
|
||||||
// onDone: () {
|
|
||||||
// final data = ByteData.view(Uint8List.fromList(contents).buffer);
|
|
||||||
// _init(data);
|
|
||||||
// },
|
|
||||||
// ),
|
|
||||||
// );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Initializes the artboard, animation, and controller
|
/// Initializes the artboard, animation, and controller
|
||||||
@ -157,6 +158,7 @@ class _RiveAnimationState extends State<RiveAnimation> {
|
|||||||
artboard: _artboard!,
|
artboard: _artboard!,
|
||||||
fit: widget.fit,
|
fit: widget.fit,
|
||||||
alignment: widget.alignment,
|
alignment: widget.alignment,
|
||||||
|
antialiasing: widget.antialiasing,
|
||||||
)
|
)
|
||||||
: widget.placeHolder ?? const SizedBox();
|
: widget.placeHolder ?? const SizedBox();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user