From 19a6d199b8a9e184d24e2195839c0043d16d7222 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Fri, 29 Aug 2025 08:36:47 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E2=9C=A8=20Make=20`OpenContainerState`=20p?= =?UTF-8?q?ublic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/animations/lib/src/open_container.dart | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/animations/lib/src/open_container.dart b/packages/animations/lib/src/open_container.dart index 59d33e350e27..4aca9d0dba8b 100644 --- a/packages/animations/lib/src/open_container.dart +++ b/packages/animations/lib/src/open_container.dart @@ -260,10 +260,14 @@ class OpenContainer extends StatefulWidget { final Clip clipBehavior; @override - State> createState() => _OpenContainerState(); + State> createState() => OpenContainerState(); } -class _OpenContainerState extends State> { +/// State for a [OpenContainer]. +/// +/// Can [openContainer] explicitly or via a tap when +/// [OpenContainer.tappable] is true. +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 +280,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; From d5c88f6353a578e41ee65f1b6ba3c67965ea9ffa Mon Sep 17 00:00:00 2001 From: Alex Li Date: Sat, 27 Sep 2025 11:34:33 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Make=20`OpenContainerS?= =?UTF-8?q?tate`=20annotated=20with=20`optionalTypeArgs`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/animations/lib/src/open_container.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/animations/lib/src/open_container.dart b/packages/animations/lib/src/open_container.dart index 4aca9d0dba8b..c892941425ee 100644 --- a/packages/animations/lib/src/open_container.dart +++ b/packages/animations/lib/src/open_container.dart @@ -267,6 +267,7 @@ class OpenContainer extends StatefulWidget { /// /// Can [openContainer] explicitly or via a tap when /// [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 From 851945838e731c3cbbb9487389f311bb85afd449 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Sat, 27 Sep 2025 11:34:46 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E2=9C=85=20Add=20a=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../animations/test/open_container_test.dart | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/packages/animations/test/open_container_test.dart b/packages/animations/test/open_container_test.dart index f397daf7cdad..aa57c8a1edba 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; From 7286ec3c1a456aeb9e4db89b46164c1434ce2f9d Mon Sep 17 00:00:00 2001 From: Alex Li Date: Sat, 27 Sep 2025 11:35:52 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=F0=9F=93=9D=20CHANGELOG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/animations/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/animations/CHANGELOG.md b/packages/animations/CHANGELOG.md index 1630957ffa57..c418093d584d 100644 --- a/packages/animations/CHANGELOG.md +++ b/packages/animations/CHANGELOG.md @@ -1,6 +1,7 @@ ## NEXT * Updates minimum supported SDK version to Flutter 3.29/Dart 3.7. +* Make `OpenContainerState` public. ## 2.0.11 From e4816b8ec4aacadd447deb51a73630ed579d5ff3 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Sat, 27 Sep 2025 11:52:43 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=F0=9F=94=96=202.1.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/animations/CHANGELOG.md | 2 +- packages/animations/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/animations/CHANGELOG.md b/packages/animations/CHANGELOG.md index c418093d584d..1cb8e8afe766 100644 --- a/packages/animations/CHANGELOG.md +++ b/packages/animations/CHANGELOG.md @@ -1,4 +1,4 @@ -## NEXT +## 2.1.0 * Updates minimum supported SDK version to Flutter 3.29/Dart 3.7. * Make `OpenContainerState` public. diff --git a/packages/animations/pubspec.yaml b/packages/animations/pubspec.yaml index 96a682100af4..74fe71ac736a 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 From 8d2ec07e5e07d6b27481bbcfdabea6b5f4cda211 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Thu, 9 Oct 2025 11:32:45 +0800 Subject: [PATCH 6/6] Update OpenContainerState documentation Clarified documentation for triggering the openContainer method. --- packages/animations/lib/src/open_container.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/animations/lib/src/open_container.dart b/packages/animations/lib/src/open_container.dart index c892941425ee..129a5be34430 100644 --- a/packages/animations/lib/src/open_container.dart +++ b/packages/animations/lib/src/open_container.dart @@ -265,8 +265,10 @@ class OpenContainer extends StatefulWidget { /// State for a [OpenContainer]. /// -/// Can [openContainer] explicitly or via a tap when -/// [OpenContainer.tappable] is true. +/// 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