Skip to content

Commit ebf6156

Browse files
committed
refactor: extract ThreeButtonNavBarLayer widget
1 parent b0d61f9 commit ebf6156

File tree

3 files changed

+81
-81
lines changed

3 files changed

+81
-81
lines changed

lib/src/adaptive/widgets/adaptive_wrapper.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:adaptive_test/src/adaptive/widgets/layers/hardware_layer.dart';
22
import 'package:adaptive_test/src/adaptive/widgets/layers/keyboard_layer.dart';
33
import 'package:adaptive_test/src/adaptive/widgets/layers/system_layer.dart';
4+
import 'package:adaptive_test/src/adaptive/widgets/layers/three_button_nav_bar_layer.dart';
45
import 'package:adaptive_test/src/adaptive/window_size.dart';
56
import 'package:flutter/material.dart';
67
import 'package:flutter_test/flutter_test.dart';
@@ -10,6 +11,7 @@ import 'package:flutter_test/flutter_test.dart';
1011
/// See also:
1112
/// * [HardwareLayer]
1213
/// * [SystemLayer]
14+
/// * [ThreeButtonNavBarLayer]
1315
/// * [KeyboardLayer]
1416
class AdaptiveWrapper extends StatelessWidget {
1517
const AdaptiveWrapper({
@@ -28,9 +30,11 @@ class AdaptiveWrapper extends StatelessWidget {
2830
windowConfig: windowConfig,
2931
child: HardwareLayer(
3032
child: SystemLayer(
31-
child: KeyboardLayer(
32-
tester: tester,
33-
child: child,
33+
child: ThreeButtonNavBarLayer(
34+
child: KeyboardLayer(
35+
tester: tester,
36+
child: child,
37+
),
3438
),
3539
),
3640
),

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

Lines changed: 22 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -12,88 +12,32 @@ class SystemLayer extends StatelessWidget {
1212
@override
1313
Widget build(BuildContext context) {
1414
final windowConfig = WindowConfig.of(context);
15-
1615
final homeIndicator = windowConfig.homeIndicator;
17-
final threeButtonNavBar = windowConfig.threeButtonNavBar;
18-
19-
// Case 1: Three-button nav bar
20-
if (threeButtonNavBar != null) {
21-
return _buildThreeButtonNavBar(context, windowConfig, threeButtonNavBar);
22-
}
23-
24-
// Case 2: Gesture navigation (home indicator pill)
25-
if (homeIndicator != null) {
26-
return _buildHomeIndicator(context, windowConfig, homeIndicator);
27-
}
28-
29-
// Case 3: No system layer
30-
return child;
31-
}
3216

33-
Widget _buildThreeButtonNavBar(
34-
BuildContext context,
35-
WindowConfigData windowConfig,
36-
ThreeButtonNavBarData threeButtonNavBar,
37-
) =>
38-
Directionality(
39-
textDirection: TextDirection.ltr,
40-
child: Stack(
41-
children: [
42-
child,
43-
Positioned(
44-
bottom: threeButtonNavBar.bottomPadding,
45-
width: windowConfig.size.width,
17+
if (homeIndicator == null) return child;
18+
19+
return Directionality(
20+
textDirection: TextDirection.ltr,
21+
child: Stack(
22+
children: [
23+
child,
24+
Positioned(
25+
bottom: homeIndicator.bottom,
26+
width: windowConfig.size.width,
27+
child: Center(
4628
child: Container(
47-
height: threeButtonNavBar.height,
48-
color: threeButtonNavBar.backgroundColor,
49-
child: Row(
50-
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
51-
children: const [
52-
Icons.arrow_back_ios_rounded,
53-
Icons.circle,
54-
Icons.square_rounded
55-
]
56-
.map(
57-
(iconData) => Icon(
58-
iconData,
59-
color: threeButtonNavBar.iconColor,
60-
size: threeButtonNavBar.iconSize,
61-
),
62-
)
63-
.toList(),
29+
height: homeIndicator.size.height,
30+
width: homeIndicator.size.width,
31+
decoration: BoxDecoration(
32+
borderRadius:
33+
BorderRadius.circular(homeIndicator.size.height),
34+
color: Colors.black,
6435
),
6536
),
6637
),
67-
],
68-
),
69-
);
70-
71-
Widget _buildHomeIndicator(
72-
BuildContext context,
73-
WindowConfigData windowConfig,
74-
HomeIndicatorData homeIndicator,
75-
) =>
76-
Directionality(
77-
textDirection: TextDirection.ltr,
78-
child: Stack(
79-
children: [
80-
child,
81-
Positioned(
82-
bottom: homeIndicator.bottom,
83-
width: windowConfig.size.width,
84-
child: Center(
85-
child: Container(
86-
height: homeIndicator.size.height,
87-
width: homeIndicator.size.width,
88-
decoration: BoxDecoration(
89-
borderRadius:
90-
BorderRadius.circular(homeIndicator.size.height),
91-
color: Colors.black,
92-
),
93-
),
94-
),
95-
),
96-
],
97-
),
98-
);
38+
),
39+
],
40+
),
41+
);
42+
}
9943
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import 'package:adaptive_test/src/adaptive/window_size.dart';
2+
import 'package:flutter/material.dart';
3+
4+
class ThreeButtonNavBarLayer extends StatelessWidget {
5+
const ThreeButtonNavBarLayer({
6+
required this.child,
7+
super.key,
8+
});
9+
10+
final Widget child;
11+
12+
@override
13+
Widget build(BuildContext context) {
14+
final windowConfig = WindowConfig.of(context);
15+
final threeButtonNavBar = windowConfig.threeButtonNavBar;
16+
17+
if (threeButtonNavBar == null) return child;
18+
19+
return Directionality(
20+
textDirection: TextDirection.ltr,
21+
child: Stack(
22+
children: [
23+
child,
24+
Positioned(
25+
bottom: threeButtonNavBar.bottomPadding,
26+
width: windowConfig.size.width,
27+
child: Container(
28+
height: threeButtonNavBar.height,
29+
color: threeButtonNavBar.backgroundColor,
30+
child: Row(
31+
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
32+
children: const [
33+
Icons.arrow_back_ios_rounded,
34+
Icons.circle,
35+
Icons.square_rounded
36+
]
37+
.map(
38+
(iconData) => Icon(
39+
iconData,
40+
color: threeButtonNavBar.iconColor,
41+
size: threeButtonNavBar.iconSize,
42+
),
43+
)
44+
.toList(),
45+
),
46+
),
47+
),
48+
],
49+
),
50+
);
51+
}
52+
}

0 commit comments

Comments
 (0)