Skip to content

Commit 379420c

Browse files
[flutter_adaptive_scaffold] Changed type of appBar parameter from AppBar? to PreferredSizeWidget? (#2617)
1 parent 9b42b5f commit 379420c

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

packages/flutter_adaptive_scaffold/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.0.6
2+
3+
* Change type of `appBar` parameter from `AppBar?` to `PreferredSizeWidget?`
4+
15
## 0.0.5
26

37
* Calls onDestinationChanged callback in bottom nav bar.

packages/flutter_adaptive_scaffold/lib/src/adaptive_scaffold.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class AdaptiveScaffold extends StatefulWidget {
217217

218218
/// Option to override the default [AppBar] when using drawer in desktop
219219
/// small.
220-
final AppBar? appBar;
220+
final PreferredSizeWidget? appBar;
221221

222222
/// Callback function for when the index of a [NavigationRail] changes.
223223
final Function(int)? onSelectedIndexChange;

packages/flutter_adaptive_scaffold/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_adaptive_scaffold
22
description: Widgets to easily build adaptive layouts, including navigation elements.
3-
version: 0.0.5
3+
version: 0.0.6
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+flutter_adaptive_scaffold%22
55
repository: https://github.com/flutter/packages/tree/main/packages/flutter_adaptive_scaffold
66

packages/flutter_adaptive_scaffold/test/adaptive_scaffold_test.dart

+40
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,46 @@ void main() {
168168
expect(selectedIndex, state.index);
169169
});
170170
});
171+
172+
// Regression test for https://github.com/flutter/flutter/issues/111008
173+
testWidgets(
174+
'appBar parameter should have the type PreferredSizeWidget',
175+
(WidgetTester tester) async {
176+
await tester.pumpWidget(MaterialApp(
177+
home: MediaQuery(
178+
data: const MediaQueryData(size: Size(500, 800)),
179+
child: AdaptiveScaffold(
180+
drawerBreakpoint: TestBreakpoint0(),
181+
internalAnimations: false,
182+
destinations: const <NavigationDestination>[
183+
NavigationDestination(icon: Icon(Icons.inbox), label: 'Inbox'),
184+
NavigationDestination(
185+
icon: Icon(Icons.video_call), label: 'Video'),
186+
],
187+
appBar: const PreferredSizeWidgetImpl(),
188+
),
189+
),
190+
));
191+
192+
expect(find.byType(PreferredSizeWidgetImpl), findsOneWidget);
193+
},
194+
);
195+
}
196+
197+
/// An empty widget that implements [PreferredSizeWidget] to ensure that
198+
/// [PreferredSizeWidget] is used as [AdaptiveScaffold.appBar] parameter instead
199+
/// of [AppBar].
200+
class PreferredSizeWidgetImpl extends StatelessWidget
201+
implements PreferredSizeWidget {
202+
const PreferredSizeWidgetImpl({super.key});
203+
204+
@override
205+
Widget build(BuildContext context) {
206+
return Container();
207+
}
208+
209+
@override
210+
Size get preferredSize => const Size(200, 200);
171211
}
172212

173213
class TestBreakpoint0 extends Breakpoint {

0 commit comments

Comments
 (0)