Skip to content

Commit

Permalink
Merge pull request iteatimeteam#20 from wjun94/master
Browse files Browse the repository at this point in the history
[+] 添加isButton进行配置是否有加号按钮,底部配置文件通过参数传进去
  • Loading branch information
ChenYilong authored Jul 23, 2019
2 parents 9e162b1 + 3f95ac0 commit 1a1fc58
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 16 deletions.
40 changes: 34 additions & 6 deletions lib/TapWaterTabbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ class NavigationIconView {
}

class TapWaterTabbar extends StatefulWidget {
final bool isButton;
final List<Map<String, dynamic>> btmNavbar;
TapWaterTabbar({this.btmNavbar, this.isButton = false}) {
final int _len = this.btmNavbar.length;
// final int _len = 5;
if (this.isButton) {
if (_len % 2 == 0) {
this.btmNavbar.insert(_len ~/ 2, null);
} else {
this.btmNavbar.insert(_len ~/ 2 + 1, null);
this.btmNavbar.insert(_len ~/ 2 + 2, null);
}
}
}

@override
_TapWaterTabbarState createState() => _TapWaterTabbarState();
}
Expand All @@ -42,10 +57,20 @@ class _TapWaterTabbarState extends State<TapWaterTabbar> {
void initState() {
super.initState();
_navgationViews = [
NavigationIconView(title: '微信', icon: Icon(Icons.ac_unit), avtiveIcon: Icon(Icons.backspace)),
NavigationIconView(title: '通讯录', icon: Icon(Icons.backup), avtiveIcon: Icon(Icons.cached)),
NavigationIconView(title: '', icon: Icon(Icons.publish), avtiveIcon: Icon(Icons.public)),
NavigationIconView(title: '发现', icon: Icon(Icons.dashboard), avtiveIcon: Icon(Icons.edit)),
NavigationIconView(
title: '微信',
icon: Icon(Icons.ac_unit),
avtiveIcon: Icon(Icons.backspace)),
NavigationIconView(
title: '通讯录',
icon: Icon(Icons.backup),
avtiveIcon: Icon(Icons.cached)),
NavigationIconView(
title: '', icon: Icon(Icons.publish), avtiveIcon: Icon(Icons.public)),
NavigationIconView(
title: '发现',
icon: Icon(Icons.dashboard),
avtiveIcon: Icon(Icons.edit)),
NavigationIconView(
title: '我的',
icon: Icon(Icons.memory),
Expand Down Expand Up @@ -84,7 +109,9 @@ class _TapWaterTabbarState extends State<TapWaterTabbar> {
Widget build(BuildContext context) {
final botNavbar = new BottomNavigationBar(
fixedColor: Colors.green,
items: _navgationViews.map((NavigationIconView navigationView) => navigationView.item).toList(),
items: _navgationViews
.map((NavigationIconView navigationView) => navigationView.item)
.toList(),
currentIndex: _currentIndex,
type: BottomNavigationBarType.fixed,
onTap: onTap,
Expand Down Expand Up @@ -169,7 +196,8 @@ class _TapWaterTabbarState extends State<TapWaterTabbar> {
),
Align(
alignment: Alignment.bottomCenter,
child: WaterTabBar(),
child: WaterTabBar(
isButton: widget.isButton, btmNavbar: widget.btmNavbar),
),
// Align(
// child: Padding(
Expand Down
7 changes: 6 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ class MyApp extends StatelessWidget {
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: TapWaterTabbar(),
home: TapWaterTabbar(isButton: true, btmNavbar: [
{'title': '微信', 'icon': Icon(Icons.ac_unit)},
{'title': '微信', 'icon': Icon(Icons.ac_unit)},
{'title': '微信', 'icon': Icon(Icons.ac_unit)},
{'title': '微信', 'icon': Icon(Icons.ac_unit)}
]),
);
}
}
29 changes: 20 additions & 9 deletions lib/tap_water_tab_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import 'package:tap_water_tab_bar/tab_item.dart';
const String bigImg = 'images/post_normal.png';

class WaterTabBar extends StatefulWidget {
final bool isButton;
List<Map<String, dynamic>> btmNavbar = [];
WaterTabBar({this.btmNavbar, this.isButton = false});
@override
State<StatefulWidget> createState() => _WaterTabBarState();
}
Expand All @@ -19,27 +22,35 @@ class _WaterTabBarState extends State<WaterTabBar> {
height: 60,
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [BoxShadow(color: Colors.black12, offset: Offset(0, -1), blurRadius: 8)],
boxShadow: [
BoxShadow(
color: Colors.black12, offset: Offset(0, -1), blurRadius: 8)
],
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
children: widget.btmNavbar
.map((v) => v != null ? TabItem(title: v['title'], icon: v['icon']) : (widget.isButton ? TabItem() : Text('')))
.toList() /* [
TabItem(title: '微信', icon: Icon(Icons.ac_unit)),
TabItem(title: '微信', icon: Icon(Icons.ac_unit)),
TabItem(),
widget.isButton ? TabItem() : Text(''),
TabItem(title: '微信', icon: Icon(Icons.ac_unit)),
TabItem(title: '微信', icon: Icon(Icons.ac_unit))
],
] */
,
),
),
Positioned(
child: Container(
margin: const EdgeInsets.only(bottom: 10),
width: 60,
child: Image.asset(bigImg),
),
child: widget.isButton
? Container(
margin: const EdgeInsets.only(bottom: 10),
width: 60,
child: Image.asset(bigImg),
)
: Text(''),
)
// IgnorePointer(
// child: Container(
Expand Down

0 comments on commit 1a1fc58

Please sign in to comment.