Skip to content

Commit 8a14113

Browse files
committed
feat(lib): create 2-button layout
1 parent f792302 commit 8a14113

File tree

8 files changed

+122
-0
lines changed

8 files changed

+122
-0
lines changed

example/simple_app/test/flutter_test_config.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@ import 'package:adaptive_test/adaptive_test.dart';
44
import 'package:flutter/foundation.dart';
55
import 'package:flutter_test/flutter_test.dart';
66

7+
final pixel5TwoButton = pixel5ThreeButton.copyWith(
8+
name: 'pixel_5_two_button',
9+
systemNavBar: const SystemNavBarData.twoButton(),
10+
);
11+
712
final defaultDeviceConfigs = {
813
iPhone8,
914
iPhone16,
1015
iPadPro,
1116
desktop,
1217
pixel9,
1318
pixel5ThreeButton,
19+
pixel5TwoButton
1420
};
1521

1622
Future<void> testExecutable(FutureOr<void> Function() testMain) async {
75.7 KB
Loading
75.7 KB
Loading
75.7 KB
Loading
168 KB
Loading

lib/src/adaptive/widgets/layers/system_nav_bar_layer.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:adaptive_test/src/adaptive/widgets/layers/gesture_indicator_system_nav_bar_layer.dart';
22
import 'package:adaptive_test/src/adaptive/widgets/layers/three_button_system_nav_bar_layer.dart';
3+
import 'package:adaptive_test/src/adaptive/widgets/layers/two_button_system_nav_bar_layer.dart';
34
import 'package:adaptive_test/src/adaptive/window_config.dart';
45
import 'package:adaptive_test/src/adaptive/window_config_data/system_nav_bar_data.dart';
56
import 'package:flutter/material.dart';
@@ -31,6 +32,12 @@ class SystemNavBarLayer extends StatelessWidget {
3132
child: child,
3233
);
3334

35+
case TwoButtonSystemNavBarData():
36+
return TwoButtonSystemNavBarLayer(
37+
twoButtonNavBar: systemNavBarData,
38+
child: child,
39+
);
40+
3441
case null:
3542
return child;
3643
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import 'package:adaptive_test/src/adaptive/window_config.dart';
2+
import 'package:adaptive_test/src/adaptive/window_config_data/system_nav_bar_data.dart';
3+
import 'package:flutter/material.dart';
4+
5+
class TwoButtonSystemNavBarLayer extends StatelessWidget {
6+
const TwoButtonSystemNavBarLayer({
7+
required this.twoButtonNavBar,
8+
required this.child,
9+
super.key,
10+
});
11+
12+
final TwoButtonSystemNavBarData twoButtonNavBar;
13+
final Widget child;
14+
15+
@override
16+
Widget build(BuildContext context) {
17+
final windowConfig = WindowConfig.of(context);
18+
19+
return Directionality(
20+
textDirection: TextDirection.ltr,
21+
child: Stack(
22+
children: [
23+
child,
24+
Positioned(
25+
bottom: twoButtonNavBar.bottomPadding,
26+
width: windowConfig.size.width,
27+
child: Container(
28+
height: twoButtonNavBar.height,
29+
color: twoButtonNavBar.backgroundColor,
30+
child: Row(
31+
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
32+
children: [
33+
// Back button
34+
Padding(
35+
padding: const EdgeInsets.symmetric(horizontal: 24),
36+
child: Icon(
37+
Icons.arrow_back,
38+
color: twoButtonNavBar.iconColor,
39+
),
40+
),
41+
// Home pill (centered visually)
42+
Center(
43+
child: Container(
44+
height: twoButtonNavBar.homeHeight,
45+
width: twoButtonNavBar.homeWidth,
46+
decoration: BoxDecoration(
47+
color: twoButtonNavBar.iconColor,
48+
borderRadius:
49+
BorderRadius.circular(twoButtonNavBar.homeHeight),
50+
),
51+
),
52+
),
53+
54+
// Right side is empty (no tasks button)
55+
const SizedBox(width: 48),
56+
],
57+
),
58+
),
59+
),
60+
],
61+
),
62+
);
63+
}
64+
}

lib/src/adaptive/window_config_data/system_nav_bar_data.dart

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@ sealed class SystemNavBarData extends Equatable {
2828
double iconSize,
2929
double bottomPadding,
3030
}) = ThreeButtonSystemNavBarData;
31+
32+
/// Describe the OS two-button navigation bar.
33+
///
34+
/// [height] The height of the navigation bar, expressed in `dp`.
35+
/// [backgroundColor] The background color of the navigation bar.
36+
/// [iconColor] The color of the icons in the navigation bar.
37+
/// [homeWidth] The width of the home button, expressed in `dp`.
38+
/// [homeHeight] The height of the home button, expressed in `dp`.
39+
/// [bottomPadding] The distance from the screen bottom to the navigation bar.
40+
const factory SystemNavBarData.twoButton({
41+
double height,
42+
Color backgroundColor,
43+
Color iconColor,
44+
double homeWidth,
45+
double homeHeight,
46+
double bottomPadding,
47+
}) = TwoButtonSystemNavBarData;
3148
}
3249

3350
/// Describe the OS gesture indicator on bottom of apps, expressed in `dp`.
@@ -83,3 +100,31 @@ class ThreeButtonSystemNavBarData extends SystemNavBarData {
83100
bottomPadding,
84101
];
85102
}
103+
104+
class TwoButtonSystemNavBarData extends SystemNavBarData {
105+
const TwoButtonSystemNavBarData({
106+
this.height = 48.0,
107+
this.backgroundColor = const Color.fromRGBO(0, 0, 0, .1),
108+
this.iconColor = const Color.fromRGBO(40, 40, 40, .6),
109+
this.homeWidth = 60.0,
110+
this.homeHeight = 6.0,
111+
this.bottomPadding = 0.0,
112+
});
113+
114+
final double height; // total bar height
115+
final Color backgroundColor; // bar background
116+
final Color iconColor; // color of back arrow
117+
final double homeWidth; // pill width
118+
final double homeHeight; // pill height
119+
final double bottomPadding; // distance from bottom
120+
121+
@override
122+
List<Object?> get props => [
123+
height,
124+
backgroundColor,
125+
iconColor,
126+
homeWidth,
127+
homeHeight,
128+
bottomPadding,
129+
];
130+
}

0 commit comments

Comments
 (0)