-
Notifications
You must be signed in to change notification settings - Fork 448
Expand file tree
/
Copy pathpersistent-tab-view.widget.dart
More file actions
758 lines (689 loc) · 29.5 KB
/
persistent-tab-view.widget.dart
File metadata and controls
758 lines (689 loc) · 29.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
// Author: Bilal Shahid
// For queries, contact me at bilalscheema@gmail.com
part of persistent_bottom_nav_bar;
///A highly customizable persistent navigation bar for flutter.
///
///To learn more, check out the [Readme](https://github.com/BilalShahid13/PersistentBottomNavBar).
class PersistentTabView extends PersistentTabViewBase {
///Screens that will be displayed on tapping of persistent bottom navigation bar items.
final List<Widget> screens;
///Controller for persistent bottom navigation bar. Will be declared if left empty.
final PersistentTabController? controller;
///Background color of bottom navigation bar. `white` by default.
final Color backgroundColor;
///A custom widget which is displayed at the bottom right of the display at all times.
final Widget? floatingActionButton;
///Specifies the navBarHeight
///
///Defaults to `kBottomNavigationBarHeight` which is `56.0`.
//final double navBarHeight;
///The margin around the navigation bar.
final EdgeInsets margin;
///Will confine the NavBar's items in the safe area defined by the device.
final bool confineInSafeArea;
///Handles android back button actions. Defaults to `true`.
///
///Action based on scenarios:
///1. If the you are on the first tab with all screens popped of the given tab, the app will close.
///2. If you are on another tab with all screens popped of that given tab, you will be switched to first tab.
///3. If there are screens pushed on the selected tab, a screen will pop on a respective back button press.
final bool handleAndroidBackButtonPress;
///Bottom margin of the screen.
final double? bottomScreenMargin;
final bool resizeToAvoidBottomInset;
///Preserves the state of each tab's screen. `true` by default.
final bool stateManagement;
///If you want to perform a custom action on Android when exiting the app, you can write your logic here. Returns context of the selected screen.
final Future<bool> Function(BuildContext?)? onWillPop;
///Returns the context of the selected tab.
final Function(BuildContext?)? selectedTabScreenContext;
///Screen transition animation properties when switching tabs.
final ScreenTransitionAnimation screenTransitionAnimation;
final bool hideNavigationBarWhenKeyboardShows;
///Hides the navigation bar with an transition animation. Use it in conjuction with [Provider](https://pub.dev/packages/provider) for better results.
final bool? hideNavigationBar;
final BuildContext context;
PersistentTabView(this.context,
{Key? key,
List<PersistentBottomNavBarItem>? items,
required this.screens,
this.controller,
double navBarHeight = kBottomNavigationBarHeight,
this.margin = EdgeInsets.zero,
this.backgroundColor = CupertinoColors.white,
ValueChanged<int>? onItemSelected,
NeumorphicProperties? neumorphicProperties,
this.floatingActionButton,
NavBarPadding padding = const NavBarPadding.all(null),
NavBarDecoration decoration = const NavBarDecoration(),
this.resizeToAvoidBottomInset = false,
this.bottomScreenMargin,
this.selectedTabScreenContext,
this.hideNavigationBarWhenKeyboardShows = true,
bool popAllScreensOnTapOfSelectedTab = true,
PopActionScreensType popActionScreens = PopActionScreensType.all,
this.confineInSafeArea = true,
this.onWillPop,
this.stateManagement = true,
this.handleAndroidBackButtonPress = true,
ItemAnimationProperties? itemAnimationProperties,
this.hideNavigationBar,
this.screenTransitionAnimation = const ScreenTransitionAnimation(),
NavBarStyle navBarStyle = NavBarStyle.style1})
: super(
key: key,
context: context,
screens: screens,
controller: controller,
margin: margin,
items: items,
padding: padding,
decoration: decoration,
hideNavigationBarWhenKeyboardShows:
hideNavigationBarWhenKeyboardShows,
itemAnimationProperties: itemAnimationProperties,
navBarStyle: navBarStyle,
popActionScreens: popActionScreens,
popAllScreensOnTapOfSelectedTab: popAllScreensOnTapOfSelectedTab,
navBarHeight: navBarHeight,
backgroundColor: backgroundColor,
onItemSelected: onItemSelected,
neumorphicProperties: neumorphicProperties,
floatingActionButton: floatingActionButton,
resizeToAvoidBottomInset: resizeToAvoidBottomInset,
bottomScreenMargin: bottomScreenMargin,
onWillPop: onWillPop,
isCustomWidget: false,
confineInSafeArea: confineInSafeArea,
stateManagement: stateManagement,
handleAndroidBackButtonPress: handleAndroidBackButtonPress,
hideNavigationBar: hideNavigationBar,
screenTransitionAnimation: screenTransitionAnimation,
) {
assert(items != null,
"Items can only be null in case of custom navigation bar style. Please add the items!");
assert(assertMidButtonStyles(navBarStyle, items!.length),
"NavBar styles 15-18 only accept 3 or 5 PersistentBottomNavBarItem items.");
assert(items!.length == screens.length,
"screens and items length should be same. If you are using the onPressed callback function of 'PersistentBottomNavBarItem', enter a dummy screen like Container() in its place in the screens");
assert(items!.length >= 2 && items.length <= 6,
"NavBar should have at least 2 or maximum 6 items (Except for styles 15-18)");
}
PersistentTabView.custom(
this.context, {
Key? key,
required this.screens,
this.controller,
this.margin = EdgeInsets.zero,
this.floatingActionButton,
required Widget customWidget,
required int itemCount,
this.resizeToAvoidBottomInset = false,
this.bottomScreenMargin,
this.selectedTabScreenContext,
this.hideNavigationBarWhenKeyboardShows = true,
this.backgroundColor = CupertinoColors.white,
CutsomWidgetRouteAndNavigatorSettings routeAndNavigatorSettings =
const CutsomWidgetRouteAndNavigatorSettings(),
this.confineInSafeArea = true,
this.onWillPop,
this.stateManagement = true,
this.handleAndroidBackButtonPress = true,
this.hideNavigationBar,
this.screenTransitionAnimation = const ScreenTransitionAnimation(),
}) : super(
key: key,
context: context,
screens: screens,
controller: controller,
margin: margin,
routeAndNavigatorSettings: routeAndNavigatorSettings,
backgroundColor: backgroundColor,
floatingActionButton: floatingActionButton,
customWidget: customWidget,
itemCount: itemCount,
resizeToAvoidBottomInset: resizeToAvoidBottomInset,
bottomScreenMargin: bottomScreenMargin,
onWillPop: onWillPop,
confineInSafeArea: confineInSafeArea,
stateManagement: stateManagement,
handleAndroidBackButtonPress: handleAndroidBackButtonPress,
hideNavigationBar: hideNavigationBar,
screenTransitionAnimation: screenTransitionAnimation,
isCustomWidget: true,
decoration: NavBarDecoration(),
) {
assert(itemCount == screens.length,
"screens and items length should be same. If you are using the onPressed callback function of 'PersistentBottomNavBarItem', enter a dummy screen like Container() in its place in the screens");
assert(
routeAndNavigatorSettings.navigatorKeys == null ||
routeAndNavigatorSettings.navigatorKeys != null &&
routeAndNavigatorSettings.navigatorKeys!.length !=
items!.length,
"Number of 'Navigator Keys' must be equal to the number of bottom navigation tabs.");
}
}
class PersistentTabViewBase extends StatefulWidget {
///List of persistent bottom navigation bar items to be displayed in the navigation bar.
final List<PersistentBottomNavBarItem>? items;
///Screens that will be displayed on tapping of persistent bottom navigation bar items.
final List<Widget>? screens;
///Controller for persistent bottom navigation bar. Will be declared if left empty.
final PersistentTabController? controller;
///Background color of bottom navigation bar. `white` by default.
final Color? backgroundColor;
///Callback when page or tab change is detected.
final ValueChanged<int>? onItemSelected;
///Specifies the curve properties of the NavBar.
final NavBarDecoration? decoration;
///`padding` for the persistent navigation bar content. Accepts `NavBarPadding` instead of `EdgeInsets`.
///
///`USE WITH CAUTION, MAY CAUSE LAYOUT ISSUES`.
final NavBarPadding? padding;
///Style for persistent bottom navigation bar. Accepts `NavBarStyle` to determine the theme.
final NavBarStyle? navBarStyle;
///Style the `neumorphic` navigation bar item.
///
///Works only with style `neumorphic`.
final NeumorphicProperties? neumorphicProperties;
///A custom widget which is displayed at the bottom right of the display at all times.
final Widget? floatingActionButton;
///Specifies the navBarHeight
///
///Defaults to `kBottomNavigationBarHeight` which is `56.0`.
final double? navBarHeight;
///The margin around the navigation bar.
final EdgeInsets? margin;
///Custom navigation bar widget. To be only used when `navBarStyle` is set to `NavBarStyle.custom`.
final Widget? customWidget;
///If using `custom` navBarStyle, define this instead of the `items` property
final int? itemCount;
///Will confine the NavBar's items in the safe area defined by the device.
final bool? confineInSafeArea;
///Handles android back button actions. Defaults to `true`.
///
///Action based on scenarios:
///1. If the you are on the first tab with all screens popped of the given tab, the app will close.
///2. If you are on another tab with all screens popped of that given tab, you will be switched to first tab.
///3. If there are screens pushed on the selected tab, a screen will pop on a respective back button press.
final bool? handleAndroidBackButtonPress;
///Bottom margin of the screen.
final double? bottomScreenMargin;
///If an already selected tab is pressed/tapped again, all the screens pushed on that particular tab will pop until the first screen in the stack. Defaults to `true`.
final bool? popAllScreensOnTapOfSelectedTab;
///If set all pop until to first screen else set once pop once
final PopActionScreensType? popActionScreens;
final bool? resizeToAvoidBottomInset;
///Preserves the state of each tab's screen. `true` by default.
final bool? stateManagement;
///If you want to perform a custom action on Android when exiting the app, you can write your logic here.
final Future<bool> Function(BuildContext)? onWillPop;
///Screen transition animation properties when switching tabs.
final ScreenTransitionAnimation? screenTransitionAnimation;
final bool? hideNavigationBarWhenKeyboardShows;
///This controls the animation properties of the items of the NavBar.
final ItemAnimationProperties? itemAnimationProperties;
///Hides the navigation bar with an transition animation. Use it in conjuction with [Provider](https://pub.dev/packages/provider) for better results.
final bool? hideNavigationBar;
///Define navigation bar route name and settings here.
///
///If you want to programmatically pop to initial screen on a specific use this route name when popping.
final CutsomWidgetRouteAndNavigatorSettings? routeAndNavigatorSettings;
final bool? isCustomWidget;
final BuildContext? context;
final Function(BuildContext)? selectedTabScreenContext;
const PersistentTabViewBase({
Key? key,
this.screens,
this.controller,
this.floatingActionButton,
this.margin,
this.confineInSafeArea,
this.handleAndroidBackButtonPress,
this.bottomScreenMargin,
this.resizeToAvoidBottomInset,
this.stateManagement,
this.screenTransitionAnimation,
this.hideNavigationBar,
this.context,
this.items,
this.backgroundColor,
this.onItemSelected,
this.decoration,
this.padding,
this.navBarStyle,
this.neumorphicProperties,
this.navBarHeight,
this.customWidget,
this.itemCount,
this.popAllScreensOnTapOfSelectedTab,
this.popActionScreens,
this.onWillPop,
this.hideNavigationBarWhenKeyboardShows,
this.itemAnimationProperties,
this.isCustomWidget,
this.selectedTabScreenContext,
this.routeAndNavigatorSettings,
}) : super(key: key);
@override
_PersistentTabViewState createState() => _PersistentTabViewState();
}
class _PersistentTabViewState extends State<PersistentTabView> {
late List<BuildContext?> _contextList;
PersistentTabController? _controller;
double? _navBarHeight;
int? _previousIndex;
int? _currentIndex;
bool? _isCompleted;
bool? _isAnimating;
late bool _sendScreenContext;
@override
void initState() {
super.initState();
_contextList = List<BuildContext?>.filled(
widget.items == null ? widget.itemCount ?? 0 : widget.items!.length,
null);
if (widget.controller == null) {
_controller = PersistentTabController(initialIndex: 0);
} else {
_controller = widget.controller;
}
_previousIndex = _controller!.index;
_currentIndex = _controller!.index;
_isCompleted = false;
_isAnimating = false;
_sendScreenContext = false;
_controller!.addListener(() {
if (_controller!.index != _currentIndex) {
if (widget.selectedTabScreenContext != null) {
_sendScreenContext = true;
}
if (mounted)
setState(
() => _currentIndex = _controller!.index,
);
}
});
if (widget.selectedTabScreenContext != null) {
WidgetsBinding.instance.addPostFrameCallback((_) {
widget.selectedTabScreenContext!(_contextList[_controller!.index]);
});
}
}
Widget _buildScreen(int index) {
RouteAndNavigatorSettings _routeAndNavigatorSettings = widget
.isCustomWidget!
? RouteAndNavigatorSettings(
defaultTitle: widget.routeAndNavigatorSettings!.defaultTitle,
initialRoute: widget.routeAndNavigatorSettings!.initialRoute,
navigatorKey:
widget.routeAndNavigatorSettings!.navigatorKeys == null
? null
: widget.routeAndNavigatorSettings!
.navigatorKeys![_controller!.index],
navigatorObservers:
widget.routeAndNavigatorSettings!.navigatorObservers,
onGenerateRoute: widget.routeAndNavigatorSettings!.onGenerateRoute,
onUnknownRoute: widget.routeAndNavigatorSettings!.onUnknownRoute,
routes: widget.routeAndNavigatorSettings!.routes,
)
: widget.items![index].routeAndNavigatorSettings;
if (widget.floatingActionButton != null) {
return Stack(
fit: StackFit.expand,
children: <Widget>[
SizedBox.expand(
child: CustomTabView(
routeAndNavigatorSettings: _routeAndNavigatorSettings,
builder: (BuildContext screenContext) {
_contextList[index] = screenContext;
if (_sendScreenContext) {
_sendScreenContext = false;
widget.selectedTabScreenContext!(_contextList[index]);
}
return Material(elevation: 0, child: widget.screens[index]);
},
),
),
Positioned(
bottom: widget.decoration!.borderRadius != BorderRadius.zero
? 25.0
: 10.0,
right: 10.0,
child: widget.floatingActionButton!,
),
],
);
} else if (widget.navBarStyle == NavBarStyle.style15) {
return Stack(
fit: StackFit.expand,
children: <Widget>[
SizedBox.expand(
child: CustomTabView(
routeAndNavigatorSettings: _routeAndNavigatorSettings,
builder: (BuildContext screenContext) {
_contextList[index] = screenContext;
if (_sendScreenContext) {
_sendScreenContext = false;
widget.selectedTabScreenContext!(_contextList[index]);
}
return Material(elevation: 0, child: widget.screens[index]);
},
),
),
_navBarHeight == 0
? SizedBox.shrink()
: Positioned(
bottom: (_navBarHeight! -
(widget.bottomScreenMargin ??
_navBarHeight! + widget.margin.top))
.abs(),
child: GestureDetector(
onTap: () {
if (widget.items![(widget.items!.length / 2).floor()]
.onPressed !=
null) {
widget.items![(widget.items!.length / 2).floor()]
.onPressed!(_contextList[_controller!.index]);
} else {
_controller!.index = (widget.items!.length / 2).floor();
}
},
child: Center(
child: Container(
height: 21.0 +
min(
widget.navBarHeight!,
max(
widget.decoration!.borderRadius!
.topRight.y,
widget.decoration!.borderRadius!.topLeft
.y) +
(widget.decoration?.border != null
? widget.decoration!.border!.dimensions
.vertical
: 0.0)),
margin: EdgeInsets.only(
left: MediaQuery.of(context).size.width / 2 -
(MediaQuery.of(context).size.width / 5.0 -
30.0) /
2),
width: MediaQuery.of(context).size.width / 5.0 - 30.0,
decoration: BoxDecoration(
color: Colors.transparent,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(100.0),
topRight: Radius.circular(100.0),
)),
),
),
),
),
],
);
} else if (widget.navBarStyle == NavBarStyle.style16) {
return Stack(
fit: StackFit.expand,
children: <Widget>[
SizedBox.expand(
child: CustomTabView(
routeAndNavigatorSettings: _routeAndNavigatorSettings,
builder: (BuildContext screenContext) {
_contextList[index] = screenContext;
if (_sendScreenContext) {
_sendScreenContext = false;
widget.selectedTabScreenContext!(_contextList[index]);
}
return Material(elevation: 0, child: widget.screens[index]);
},
),
),
_navBarHeight == 0
? SizedBox.shrink()
: Positioned(
bottom: (_navBarHeight! -
(widget.bottomScreenMargin ??
_navBarHeight! + widget.margin.top))
.abs(),
child: GestureDetector(
onTap: () {
if (widget.items![(widget.items!.length / 2).floor()]
.onPressed !=
null) {
widget.items![(widget.items!.length / 2).floor()]
.onPressed!(_contextList[_controller!.index]);
} else {
_controller!.index = (widget.items!.length / 2).floor();
}
},
child: Center(
child: Container(
height: 21 +
min(
widget.navBarHeight!,
max(
widget.decoration!.borderRadius!
.topRight.y,
widget.decoration!.borderRadius!.topLeft
.y) +
(widget.decoration?.border != null
? widget.decoration!.border!.dimensions
.vertical
: 0.0)),
margin: EdgeInsets.only(
left: MediaQuery.of(context).size.width / 2 -
(MediaQuery.of(context).size.width / 5.0 -
30.0) /
2),
width: MediaQuery.of(context).size.width / 5.0 - 30.0,
decoration: BoxDecoration(
color: Colors.transparent,
),
),
),
),
),
],
);
} else {
return CustomTabView(
routeAndNavigatorSettings: _routeAndNavigatorSettings,
builder: (BuildContext screenContext) {
_contextList[index] = screenContext;
if (_sendScreenContext) {
_sendScreenContext = false;
widget.selectedTabScreenContext!(_contextList[index]);
}
return Material(elevation: 0, child: widget.screens[index]);
});
}
}
Widget navigationBarWidget() => CupertinoPageScaffold(
resizeToAvoidBottomInset: widget.resizeToAvoidBottomInset,
backgroundColor: Colors.transparent,
child: PersistentTabScaffold(
controller: _controller,
itemCount: widget.items == null
? widget.itemCount ?? 0
: widget.items!.length,
bottomScreenMargin:
widget.hideNavigationBar != null && widget.hideNavigationBar!
? 0.0
: widget.bottomScreenMargin,
stateManagement: widget.stateManagement,
screenTransitionAnimation: widget.screenTransitionAnimation,
hideNavigationBarWhenKeyboardShows:
widget.hideNavigationBarWhenKeyboardShows,
resizeToAvoidBottomInset: widget.resizeToAvoidBottomInset,
animatePadding: _isAnimating! || _isCompleted!,
tabBar: PersistentBottomNavBar(
navBarEssentials: NavBarEssentials(
selectedIndex: _controller!.index,
previousIndex: _previousIndex,
padding: widget.padding,
selectedScreenBuildContext: _contextList[_controller!.index],
itemAnimationProperties: widget.itemAnimationProperties,
items: widget.items,
backgroundColor: widget.backgroundColor,
navBarHeight: _navBarHeight,
popScreensOnTapOfSelectedTab:
widget.popAllScreensOnTapOfSelectedTab ?? true,
onItemSelected: widget.onItemSelected != null
? (int index) {
if (_controller!.index != _previousIndex) {
_previousIndex = _controller!.index;
}
if ((widget.popAllScreensOnTapOfSelectedTab ?? true) &&
_previousIndex == index) {
popAllScreens();
}
_controller!.index = index;
widget.onItemSelected!(index);
}
: (int index) {
if (_controller!.index != _previousIndex) {
_previousIndex = _controller!.index;
}
if ((widget.popAllScreensOnTapOfSelectedTab ?? true) &&
_previousIndex == index) {
popAllScreens();
}
_controller!.index = index;
},
),
isCustomWidget: widget.isCustomWidget,
navBarDecoration: widget.decoration,
margin: widget.margin,
confineToSafeArea: widget.confineInSafeArea,
hideNavigationBar: widget.hideNavigationBar,
navBarStyle: widget.navBarStyle,
neumorphicProperties: widget.neumorphicProperties,
customNavBarWidget: widget.customWidget,
onAnimationComplete: (isAnimating, isCompleted) {
if (_isAnimating != isAnimating) {
setState(() {
_isAnimating = isAnimating;
});
}
if (_isCompleted != isCompleted) {
setState(() {
_isCompleted = isCompleted;
});
}
},
),
tabBuilder: (BuildContext context, int index) {
return SafeArea(
top: false,
right: false,
left: false,
bottom: (widget.items != null &&
widget.items![_controller!.index].opacity < 1.0) ||
(widget.hideNavigationBar != null && _isCompleted!)
? false
: widget.margin.bottom > 0
? false
: widget.confineInSafeArea,
child: _buildScreen(index),
);
},
),
);
@override
Widget build(BuildContext context) {
_navBarHeight = (widget.resizeToAvoidBottomInset &&
MediaQuery.of(widget.context).viewInsets.bottom > 0 &&
widget.hideNavigationBarWhenKeyboardShows)
? 0.0
: widget.navBarHeight ?? kBottomNavigationBarHeight;
if (_contextList.length != (widget.itemCount ?? widget.items!.length)) {
_contextList = List<BuildContext?>.filled(
(widget.items == null ? widget.itemCount ?? 0 : widget.items!.length),
null);
}
if (widget.handleAndroidBackButtonPress || widget.onWillPop != null) {
return WillPopScope(
onWillPop: !widget.handleAndroidBackButtonPress &&
widget.onWillPop != null
? widget.onWillPop!(_contextList[_controller!.index])
as Future<bool> Function()?
: widget.handleAndroidBackButtonPress && widget.onWillPop != null
? () async {
if (_controller!.index == 0 &&
!Navigator.canPop(_contextList.first!)) {
return widget.onWillPop!(_contextList.first);
} else {
if (Navigator.canPop(_contextList[_controller!.index]!)) {
Navigator.pop(_contextList[_controller!.index]!);
} else {
if (widget.onItemSelected != null) {
widget.onItemSelected!(0);
}
_controller!.index = 0;
}
return false;
}
}
: () async {
if (_controller!.index == 0 &&
!Navigator.canPop(_contextList.first!)) {
return true;
} else {
if (Navigator.canPop(_contextList[_controller!.index]!)) {
Navigator.pop(_contextList[_controller!.index]!);
} else {
if (widget.onItemSelected != null) {
widget.onItemSelected!(0);
}
_controller!.index = 0;
}
return false;
}
},
child: navigationBarWidget(),
);
} else {
return navigationBarWidget();
}
}
void popAllScreens() {
if (widget.popAllScreensOnTapOfSelectedTab!) {
if (widget.items![_controller!.index]
.onSelectedTabPressWhenNoScreensPushed !=
null &&
!Navigator.of(_contextList[_controller!.index]!).canPop()) {
widget.items![_controller!.index]
.onSelectedTabPressWhenNoScreensPushed!();
}
if (widget.popActionScreens == PopActionScreensType.once) {
if (Navigator.of(_contextList[_controller!.index]!).canPop()) {
Navigator.of(_contextList[_controller!.index]!).pop(context);
return;
}
} else {
Navigator.popUntil(
_contextList[_controller!.index]!,
ModalRoute.withName(widget.isCustomWidget!
? (widget.routeAndNavigatorSettings?.initialRoute ??
'/9f580fc5-c252-45d0-af25-9429992db112')
: widget.items![_controller!.index].routeAndNavigatorSettings
.initialRoute ??
'/9f580fc5-c252-45d0-af25-9429992db112'));
}
}
}
}
//asserts
bool assertMidButtonStyles(NavBarStyle navBarStyle, int itemCount) {
if (navBarStyle == NavBarStyle.style15 ||
navBarStyle == NavBarStyle.style16 ||
navBarStyle == NavBarStyle.style17 ||
navBarStyle == NavBarStyle.style18) {
if (itemCount % 2 != 0) {
return true;
} else {
return false;
}
}
return true;
}