Update CupertinoNavigationBar to support large layout (#157133)

Fixes https://github.com/flutter/flutter/issues/149625

This adds a new constructor CupertinoNavigationBar.large for the large style navigation bar. CupertinoSliverNavigationBar enables dynamically changing between the smaller and larger layouts for native iOS headers in response to scrolling, this change makes it possible to configure the static navigation bar in one style or the other.
This commit is contained in:
Kate Lovett
2024-10-25 12:08:12 -07:00
committed by GitHub
parent 6337eb1a39
commit 2c20325af4
4 changed files with 423 additions and 79 deletions

View File

@@ -0,0 +1,63 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/cupertino.dart';
/// Flutter code sample for [CupertinoNavigationBar.large].
void main() => runApp(const NavBarApp());
class NavBarApp extends StatelessWidget {
const NavBarApp({super.key});
@override
Widget build(BuildContext context) {
return const CupertinoApp(
theme: CupertinoThemeData(brightness: Brightness.light),
home: NavBarExample(),
);
}
}
class NavBarExample extends StatefulWidget {
const NavBarExample({super.key});
@override
State<NavBarExample> createState() => _NavBarExampleState();
}
class _NavBarExampleState extends State<NavBarExample> {
int _count = 0;
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar.large(
largeTitle: Text('Large Sample'),
),
child: SafeArea(
child: Center(
child: Column(
children: <Widget>[
const Spacer(),
const Text('You have pushed the button this many times:'),
Text(
'$_count',
style: CupertinoTheme.of(context).textTheme.navLargeTitleTextStyle,
),
const Spacer(),
Padding(
padding: const EdgeInsets.all(15.0),
child: CupertinoButton.filled(
onPressed: () => setState(() => _count++),
child: const Text('Increment'),
),
),
],
),
),
),
);
}
}

View File

@@ -0,0 +1,25 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/cupertino.dart';
import 'package:flutter_api_samples/cupertino/nav_bar/cupertino_navigation_bar.2.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('CupertinoNavigationBar is large', (WidgetTester tester) async {
await tester.pumpWidget(
const example.NavBarApp(),
);
final Finder navBarFinder = find.byType(CupertinoNavigationBar);
expect(navBarFinder, findsOneWidget);
expect(find.text('Large Sample'), findsOneWidget);
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
await tester.tap(find.text('Increment'));
await tester.pump();
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}