-
Notifications
You must be signed in to change notification settings - Fork 1
/
tabs.dart
88 lines (81 loc) · 2.84 KB
/
tabs.dart
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
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:platty/src/widgets/material_patcher.dart';
import 'package:platty/src/widgets/platform.dart';
class PTabBar extends PlatformAdaptingWidget {
final List<BottomNavigationBarItem> items;
final ValueChanged<int> onTap;
final int currentIndex;
final double iconSize;
final BottomNavigationBarType androidType;
/// on iOS this is [CupertinoTabBar.inactiveColor]
/// on Android we wrap a [Theme] providing an override on the
/// [TextTheme.caption] color.
final Color inactiveColor;
/// on Android, this is the fixedColor
/// on iOS, this is the active color
final Color activeFixedColor;
/// on iOS, See [CupertinoTabBar.backgroundColor]
/// on Android, we wrap a [Theme.canvasColor] that specifies the background color
/// to match iOS property.
final Color backgroundColor;
PTabBar(
{Key key,
@required this.items,
this.onTap,
this.iconSize,
this.androidType = BottomNavigationBarType.fixed,
this.currentIndex = 0,
this.activeFixedColor,
this.inactiveColor,
this.backgroundColor,
TargetPlatform renderPlatform})
: super(key: key, renderPlatform: renderPlatform);
@override
get renderMaterial => (BuildContext context) {
final theme = Theme.of(context);
final backgroundColorFromTheme =
this.backgroundColor ?? theme.bottomAppBarColor;
return Theme(
data: theme.copyWith(
canvasColor: backgroundColorFromTheme,
textTheme: this.inactiveColor != null
? theme.textTheme.copyWith(
caption: TextStyle(
color: inactiveColor,
),
)
: theme.textTheme,
),
child: BottomNavigationBar(
fixedColor: activeFixedColor,
items: items,
onTap: onTap,
currentIndex: currentIndex,
iconSize: iconSize ?? 24.0,
type: androidType,
),
);
};
@override
get renderCupertino => (BuildContext context) {
final theme = Theme.of(context);
final backgroundColorFromTheme =
this.backgroundColor ?? theme?.bottomAppBarColor;
final inActiveFromTheme = this.inactiveColor ??
theme.textTheme.caption.color ??
CupertinoColors
.inactiveGray; // ios does not like missing inactive color.
return MaterialPatcher(
child: CupertinoTabBar(
items: items,
onTap: onTap,
currentIndex: currentIndex,
iconSize: iconSize ?? 30.0,
activeColor: activeFixedColor,
inactiveColor: inActiveFromTheme,
backgroundColor: backgroundColorFromTheme,
),
);
};
}