Files
rive-flutter/example/lib/examples/hit_test_behaviour.dart
HayesGordon 16b484c81c chore(flutter): release with rive_native bump and update examples (#10190) eec2f66855
* chore(flutter): bump rive_native

* chore(flutter): add examples

* docs: update changelog

fix: recursively check whether an artboard is its ancestor before usi… (#10184) 53fb2577bc
* fix: recursively check whether an artboard is its ancestor before using it as the source of a nested artboard

fix(wagyu): proper init of Wagyu Render Pass Inputs (#10175) ff8fc66bc4
* proper init of Wagyu Render Pass Inputs

* fixed build issues

* clang-format

* proper black clear color

chore: update thumbnailer for new rive building set-up 9fd4961e9b

Co-authored-by: Gordon <pggordonhayes@gmail.com>
2025-07-16 17:53:55 +00:00

182 lines
5.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:rive/rive.dart';
import 'package:rive_example/main.dart';
class ExampleHitTestBehaviour extends StatefulWidget {
const ExampleHitTestBehaviour({super.key});
@override
State<ExampleHitTestBehaviour> createState() =>
_ExampleHitTestBehaviourState();
}
class _ExampleHitTestBehaviourState extends State<ExampleHitTestBehaviour> {
FileLoader fileLoader = FileLoader.fromAsset(
'assets/button.riv',
riveFactory: RiveExampleApp.getCurrentFactory,
);
int count = 0;
RiveHitTestBehavior hitTestBehavior = RiveHitTestBehavior.opaque;
MouseCursor cursor = MouseCursor.defer;
@override
void dispose() {
fileLoader.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Stack(
children: [
Center(
child: MouseRegion(
cursor: SystemMouseCursors.copy,
child: GestureDetector(
onTap: () {
setState(() {
count++;
});
},
child: Container(
width: 300,
height: 300,
color: Colors.red,
),
),
),
),
Center(
child: MouseRegion(
opaque: true,
cursor: SystemMouseCursors.click,
hitTestBehavior: HitTestBehavior.deferToChild,
child: RiveWidgetBuilder(
fileLoader: fileLoader,
builder: (context, state) => switch (state) {
RiveLoading() => const Center(
child: Center(child: CircularProgressIndicator()),
),
RiveFailed() => ErrorWidget.withDetails(
message: state.error.toString(),
error: FlutterError(state.error.toString()),
),
RiveLoaded() => RiveWidget(
controller: state.controller,
hitTestBehavior: hitTestBehavior,
cursor: cursor,
)
},
),
),
),
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text('Underlying Flutter container tapped: $count'),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text('Current hit test behaviour: $hitTestBehavior'),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Wrap(
spacing: 8,
runSpacing: 8,
crossAxisAlignment: WrapCrossAlignment.start,
children: [
ElevatedButton(
onPressed: () {
setState(() {
hitTestBehavior = RiveHitTestBehavior.none;
});
},
child: const Text('none'),
),
ElevatedButton(
onPressed: () {
setState(() {
hitTestBehavior = RiveHitTestBehavior.opaque;
});
},
child: const Text('opaque'),
),
ElevatedButton(
onPressed: () {
setState(() {
hitTestBehavior = RiveHitTestBehavior.translucent;
});
},
child: const Text('translucent'),
),
ElevatedButton(
onPressed: () {
setState(() {
hitTestBehavior = RiveHitTestBehavior.transparent;
});
},
child: const Text('transparent'),
)
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text('Current mouse cursor: $cursor'),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Wrap(
spacing: 8,
runSpacing: 8,
alignment: WrapAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () {
setState(() {
cursor = MouseCursor.defer;
});
},
child: const Text('defer'),
),
ElevatedButton(
onPressed: () {
setState(() {
cursor = MouseCursor.uncontrolled;
});
},
child: const Text('unconrolled'),
),
ElevatedButton(
onPressed: () {
setState(() {
cursor = SystemMouseCursors.contextMenu;
});
},
child: const Text('context menu'),
),
ElevatedButton(
onPressed: () {
setState(() {
cursor = SystemMouseCursors.text;
});
},
child: const Text('text'),
),
],
),
),
)
],
);
}
}