Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/animations/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
11 changes: 9 additions & 2 deletions packages/animations/lib/src/open_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,15 @@ class OpenContainer<T extends Object?> extends StatefulWidget {
final Clip clipBehavior;

@override
State<OpenContainer<T?>> createState() => _OpenContainerState<T>();
State<OpenContainer<T?>> createState() => OpenContainerState<T>();
}

class _OpenContainerState<T> extends State<OpenContainer<T?>> {
/// State for a [OpenContainer].
///
/// Can [openContainer] explicitly or via a tap when

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/// The [openContainer] can be triggered either by:
/// 1. Explicitly calling [openContainer] from [OpenContainerState]
/// 2. By tapping the [OpenContainer] widget itself, if [OpenContainer.tappable] is true.

/// [OpenContainer.tappable] is true.
@optionalTypeArgs
class OpenContainerState<T> extends State<OpenContainer<T?>> {
// 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
Expand All @@ -276,6 +281,8 @@ class _OpenContainerState<T> extends State<OpenContainer<T?>> {
// 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<void> openContainer() async {
final Color middleColor =
widget.middleColor ?? Theme.of(context).canvasColor;
Expand Down
2 changes: 1 addition & 1 deletion packages/animations/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions packages/animations/test/open_container_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<OpenContainerState> openContainerKey =
GlobalKey<OpenContainerState>();

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 {
Expand Down Expand Up @@ -1861,6 +1891,7 @@ class _SizableContainerState extends State<_SizableContainer> {

double get size => _size;
late double _size;

set size(double value) {
if (value == _size) {
return;
Expand Down