forked from firka/flutter
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:
@@ -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'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user