diff --git a/packages/animations/CHANGELOG.md b/packages/animations/CHANGELOG.md index 1630957ffa5..1cb8e8afe76 100644 --- a/packages/animations/CHANGELOG.md +++ b/packages/animations/CHANGELOG.md @@ -1,6 +1,7 @@ -## NEXT +## 2.1.0 * Updates minimum supported SDK version to Flutter 3.29/Dart 3.7. +* Make `OpenContainerState` public. ## 2.0.11 diff --git a/packages/animations/lib/src/open_container.dart b/packages/animations/lib/src/open_container.dart index 59d33e350e2..129a5be3443 100644 --- a/packages/animations/lib/src/open_container.dart +++ b/packages/animations/lib/src/open_container.dart @@ -260,10 +260,17 @@ class OpenContainer extends StatefulWidget { final Clip clipBehavior; @override - State> createState() => _OpenContainerState(); + State> createState() => OpenContainerState(); } -class _OpenContainerState extends State> { +/// State for a [OpenContainer]. +/// +/// The [OpenContainerState.openContainer] can be triggered either by: +/// 1. Explicitly calling from [OpenContainerState] via a [GlobalKey]. +/// 2. By tapping the [OpenContainer] widget itself, +/// if [OpenContainer.tappable] is true. +@optionalTypeArgs +class OpenContainerState extends State> { // Key used in [_OpenContainerRoute] to hide the widget returned by // [OpenContainer.openBuilder] in the source route while the container is // opening/open. A copy of that widget is included in the @@ -276,6 +283,8 @@ class _OpenContainerState extends State> { // same widget included in the [_OpenContainerRoute] where it fades out. final GlobalKey _closedBuilderKey = GlobalKey(); + /// Open the container using the given middle color and specific route, + /// then call `onClosed` with the returned data after popped. Future openContainer() async { final Color middleColor = widget.middleColor ?? Theme.of(context).canvasColor; diff --git a/packages/animations/pubspec.yaml b/packages/animations/pubspec.yaml index 96a682100af..74fe71ac736 100644 --- a/packages/animations/pubspec.yaml +++ b/packages/animations/pubspec.yaml @@ -2,7 +2,7 @@ name: animations description: Fancy pre-built animations that can easily be integrated into any Flutter application. repository: https://github.com/flutter/packages/tree/main/packages/animations issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+animations%22 -version: 2.0.11 +version: 2.1.0 environment: sdk: ^3.7.0 diff --git a/packages/animations/test/open_container_test.dart b/packages/animations/test/open_container_test.dart index f397daf7cda..aa57c8a1edb 100644 --- a/packages/animations/test/open_container_test.dart +++ b/packages/animations/test/open_container_test.dart @@ -7,6 +7,36 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { + testWidgets('Can be opened via GlobalKey', (WidgetTester tester) async { + final GlobalKey openContainerKey = + GlobalKey(); + + await tester.pumpWidget( + _boilerplate( + child: Center( + child: OpenContainer( + key: openContainerKey, + closedBuilder: (BuildContext context, VoidCallback _) { + return const Text('Closed'); + }, + openBuilder: (BuildContext context, VoidCallback _) { + return const Text('Open'); + }, + ), + ), + ), + ); + + expect(find.text('Closed'), findsOneWidget); + expect(find.text('Open'), findsNothing); + + openContainerKey.currentState!.openContainer(); + await tester.pumpAndSettle(); + + expect(find.text('Closed'), findsNothing); + expect(find.text('Open'), findsOneWidget); + }); + testWidgets('Container opens - Fade (by default)', ( WidgetTester tester, ) async { @@ -1861,6 +1891,7 @@ class _SizableContainerState extends State<_SizableContainer> { double get size => _size; late double _size; + set size(double value) { if (value == _size) { return;