mirror of
https://github.com/rive-app/rive-flutter.git
synced 2025-07-06 16:29:11 +08:00

Bascially add tracking of fileAssetReferencers from file assets, so that when file assets update, they can tell things that reference them to update also. its worth looking at the rive-flutter & runtime implementations in cpp it looks like we can hook into the delete hooks nicely to clean up after ourselves (so that when artboards get collected we are not holding references to them from file assets) in dart this is more of a problem, however using weakReferences we do end up seeing artboards go out of scope but weakReferences requires us to bump to a min dart of 2.17 (we are 2.14 in flutter & 2.12 in our editor atm) the update here also uses the referencers to mark fonts dirty when fonts are set, which causes them to be updated on the next draw cycle (video showing font updates working properly now in dart) https://github.com/rive-app/rive/assets/1216025/d65ea2cf-95d6-4412-b8f5-368cda609d0b (video showing how referencers get collected and trashed in dart, it looks like we hold onto about 10 of them at a time.. but they do drop off over time. also we start with 2 references, the main artboard and the artboard instance) https://github.com/rive-app/rive/assets/1216025/b11b7b46-aa9d-4dcc-bc11-f745d8449575 Diffs= 7bc216b03 add ability to attach callbacks when resolving file asset listeners (#6068) Co-authored-by: Maxwell Talbot <talbot.maxwell@gmail.com>
130 lines
4.4 KiB
Dart
130 lines
4.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:rive_example/basic_text_customized.dart';
|
|
|
|
import 'package:rive_example/custom_asset_loading.dart';
|
|
import 'package:rive_example/custom_cached_asset_loading.dart';
|
|
import 'package:rive_example/carousel.dart';
|
|
import 'package:rive_example/custom_controller.dart';
|
|
import 'package:rive_example/event_open_url_button.dart';
|
|
import 'package:rive_example/event_sounds.dart';
|
|
import 'package:rive_example/event_star_rating.dart';
|
|
import 'package:rive_example/example_state_machine.dart';
|
|
import 'package:rive_example/liquid_download.dart';
|
|
import 'package:rive_example/little_machine.dart';
|
|
import 'package:rive_example/play_one_shot_animation.dart';
|
|
import 'package:rive_example/play_pause_animation.dart';
|
|
import 'package:rive_example/simple_animation.dart';
|
|
import 'package:rive_example/simple_animation_network.dart';
|
|
import 'package:rive_example/simple_machine_listener.dart';
|
|
import 'package:rive_example/simple_state_machine.dart';
|
|
import 'package:rive_example/skinning_demo.dart';
|
|
import 'package:rive_example/state_machine_skills.dart';
|
|
import 'package:rive_example/basic_text.dart';
|
|
|
|
void main() => runApp(
|
|
MaterialApp(
|
|
title: 'Rive Example',
|
|
home: const RiveExampleApp(),
|
|
darkTheme: ThemeData.dark().copyWith(
|
|
scaffoldBackgroundColor: _backgroundColor,
|
|
appBarTheme: const AppBarTheme(backgroundColor: _appBarColor),
|
|
colorScheme:
|
|
ColorScheme.fromSwatch().copyWith(primary: _primaryColor),
|
|
),
|
|
themeMode: ThemeMode.dark,
|
|
),
|
|
);
|
|
|
|
/// An example application demoing Rive.
|
|
class RiveExampleApp extends StatefulWidget {
|
|
const RiveExampleApp({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<RiveExampleApp> createState() => _RiveExampleAppState();
|
|
}
|
|
|
|
class _RiveExampleAppState extends State<RiveExampleApp> {
|
|
// Example animations
|
|
final _pages = [
|
|
const _Page('Basic Text Customized', BasicTextCustomized()),
|
|
const _Page('Simple Animation - Asset', SimpleAssetAnimation()),
|
|
const _Page('Simple Animation - Network', SimpleNetworkAnimation()),
|
|
const _Page('Play/Pause Animation', PlayPauseAnimation()),
|
|
const _Page('Play One-Shot Animation', PlayOneShotAnimation()),
|
|
const _Page('Button State Machine', ExampleStateMachine()),
|
|
const _Page('Skills Machine', StateMachineSkills()),
|
|
const _Page('Little Machine', LittleMachine()),
|
|
const _Page('Liquid Download', LiquidDownload()),
|
|
const _Page('Custom Controller - Speed', SpeedyAnimation()),
|
|
const _Page('Simple State Machine', SimpleStateMachine()),
|
|
const _Page('State Machine with Listener', StateMachineListener()),
|
|
const _Page('Skinning Demo', SkinningDemo()),
|
|
const _Page('Animation Carousel', AnimationCarousel()),
|
|
const _Page('Basic Text', BasicText()),
|
|
const _Page('Custom Asset Loading', CustomAssetLoading()),
|
|
const _Page('Custom Cached Asset Loading', CustomCachedAssetLoading()),
|
|
const _Page('Event Open URL Button', EventOpenUrlButton()),
|
|
const _Page('Event Sounds', EventSounds()),
|
|
const _Page('Event Star Rating', EventStarRating()),
|
|
];
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('Rive Examples')),
|
|
body: Center(
|
|
child: ListView.separated(
|
|
shrinkWrap: true,
|
|
itemBuilder: (context, index) => _NavButton(page: _pages[index]),
|
|
separatorBuilder: (context, index) => const SizedBox(height: 16),
|
|
itemCount: _pages.length,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Class used to organize demo pages.
|
|
class _Page {
|
|
final String name;
|
|
final Widget page;
|
|
|
|
const _Page(this.name, this.page);
|
|
}
|
|
|
|
/// Button to navigate to demo pages.
|
|
class _NavButton extends StatelessWidget {
|
|
const _NavButton({required this.page});
|
|
|
|
final _Page page;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Center(
|
|
child: ElevatedButton(
|
|
child: SizedBox(
|
|
width: 250,
|
|
child: Center(
|
|
child: Text(
|
|
page.name,
|
|
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
),
|
|
onPressed: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute<void>(
|
|
builder: (context) => page.page,
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
const _appBarColor = Color(0xFF323232);
|
|
const _backgroundColor = Color(0xFF1D1D1D);
|
|
const _primaryColor = Color(0xFF57A5E0);
|