6 changed files with 51 additions and 316 deletions
Split View
Diff Options
-
1lib/pages/discover/discover_page.dart
-
39lib/pages/home/recommend_tab.dart
-
55lib/pages/main/main_page.dart
-
182lib/pages/main/tabbar/main_tab_bar.dart
-
77lib/pages/main/tabbar/main_tab_btn.dart
-
13lib/pages/main/tabbar/main_tab_item.dart
@ -1,182 +0,0 @@ |
|||
import 'dart:io'; |
|||
import 'package:collection/collection.dart'; |
|||
import 'package:dating_touchme_app/extension/ex_context.dart'; |
|||
import 'package:flutter/material.dart'; |
|||
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|||
|
|||
import '../../../generated/assets.dart'; |
|||
import 'main_tab_btn.dart'; |
|||
import 'main_tab_item.dart'; |
|||
|
|||
class MainTabBar extends StatefulWidget { |
|||
const MainTabBar({super.key, this.initialIndex = 0, this.onTabChanged}); |
|||
|
|||
final int initialIndex; |
|||
final void Function(int index)? onTabChanged; |
|||
|
|||
@override |
|||
State<MainTabBar> createState() => _MainTabBarState(); |
|||
} |
|||
|
|||
class _MainTabBarState extends State<MainTabBar> { |
|||
int _selecteIndex = 0; |
|||
|
|||
final List<MainTabItem> items = const [ |
|||
MainTabItem( |
|||
title: "首页", |
|||
icon: Assets.imagesHomeNol, |
|||
selectedIcon: Assets.imagesHomePre, |
|||
), |
|||
MainTabItem( |
|||
title: "找对象", |
|||
icon: Assets.imagesDiscoverNol, |
|||
selectedIcon: Assets.imagesDiscoverPre, |
|||
), |
|||
MainTabItem( |
|||
title: "消息", |
|||
icon: Assets.imagesMessageNol, |
|||
selectedIcon: Assets.imagesMessagePre, |
|||
), |
|||
MainTabItem( |
|||
title: "我的", |
|||
icon: Assets.imagesMineNol, |
|||
selectedIcon: Assets.imagesMinePre, |
|||
), |
|||
]; |
|||
|
|||
@override |
|||
void initState() { |
|||
_selecteIndex = widget.initialIndex; |
|||
super.initState(); |
|||
} |
|||
|
|||
@override |
|||
void didUpdateWidget(covariant MainTabBar oldWidget) { |
|||
super.didUpdateWidget(oldWidget); |
|||
if (_selecteIndex != widget.initialIndex) { |
|||
_selecteIndex = widget.initialIndex; |
|||
} |
|||
} |
|||
|
|||
@override |
|||
Widget build(BuildContext context) { |
|||
return Builder(builder: (context) { |
|||
if (Platform.isIOS) { |
|||
if (context.bottomPadding > 0) { |
|||
return Container( |
|||
height: 64.w, |
|||
color: Colors.white, |
|||
child: Stack( |
|||
children: [ |
|||
Column( |
|||
mainAxisAlignment: MainAxisAlignment.center, |
|||
children: [ |
|||
Row( |
|||
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|||
children: items.mapIndexed((index, item) { |
|||
return MainTabButton( |
|||
selected: index == _selecteIndex, |
|||
isRedDot: item.showRedDot, |
|||
title: item.title, |
|||
onTap: () { |
|||
if (_selecteIndex != index) { |
|||
_selecteIndex = index; |
|||
setState(() {}); |
|||
widget.onTabChanged?.call(index); |
|||
} |
|||
}, |
|||
icon: item.icon, |
|||
selectedIcon: item.selectedIcon, |
|||
); |
|||
}).toList()), |
|||
SizedBox( |
|||
height: 22.w, |
|||
) |
|||
], |
|||
) |
|||
], |
|||
), |
|||
); |
|||
} else { |
|||
return SafeArea( |
|||
top: false, |
|||
child: Container( |
|||
height: 64.w, |
|||
color: Colors.white, |
|||
child: Stack( |
|||
children: [ |
|||
Column( |
|||
mainAxisAlignment: MainAxisAlignment.center, |
|||
children: [ |
|||
Row( |
|||
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|||
children: items.mapIndexed((index, item) { |
|||
return MainTabButton( |
|||
selected: index == _selecteIndex, |
|||
isRedDot: item.showRedDot, |
|||
title: item.title, |
|||
onTap: () { |
|||
if (_selecteIndex != index) { |
|||
_selecteIndex = index; |
|||
setState(() {}); |
|||
widget.onTabChanged?.call(index); |
|||
} |
|||
}, |
|||
icon: item.icon, |
|||
selectedIcon: item.selectedIcon, |
|||
); |
|||
}).toList()), |
|||
SizedBox( |
|||
height: 14.w, |
|||
) |
|||
], |
|||
) |
|||
], |
|||
), |
|||
), |
|||
); |
|||
} |
|||
} else { |
|||
return SafeArea( |
|||
top: false, |
|||
child: Container( |
|||
// padding: EdgeInsets.only(bottom: 14.w), |
|||
// margin: EdgeInsets.only(left: 16.w, right: 16.w, bottom: 14.w), |
|||
height: 64.w, |
|||
color: Colors.white, |
|||
child: Stack( |
|||
children: [ |
|||
Column( |
|||
mainAxisAlignment: MainAxisAlignment.center, |
|||
children: [ |
|||
Row( |
|||
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|||
children: items.mapIndexed((index, item) { |
|||
return MainTabButton( |
|||
selected: index == _selecteIndex, |
|||
isRedDot: item.showRedDot, |
|||
title: item.title, |
|||
onTap: () { |
|||
if (_selecteIndex != index) { |
|||
_selecteIndex = index; |
|||
setState(() {}); |
|||
widget.onTabChanged?.call(index); |
|||
} |
|||
}, |
|||
icon: item.icon, |
|||
selectedIcon: item.selectedIcon, |
|||
); |
|||
}).toList()), |
|||
SizedBox( |
|||
height: 14.w, |
|||
) |
|||
], |
|||
) |
|||
], |
|||
), |
|||
), |
|||
); |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
@ -1,77 +0,0 @@ |
|||
import 'package:flutter/material.dart'; |
|||
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|||
|
|||
class MainTabButton extends StatefulWidget { |
|||
final VoidCallback? onTap; |
|||
final bool isRedDot; |
|||
final bool selected; |
|||
final String icon; |
|||
final String title; |
|||
final String selectedIcon; |
|||
|
|||
const MainTabButton({ |
|||
super.key, |
|||
required this.selected, |
|||
required this.icon, |
|||
required this.selectedIcon, |
|||
this.isRedDot = false, |
|||
this.onTap, |
|||
required this.title |
|||
}); |
|||
|
|||
@override |
|||
State<MainTabButton> createState() => MainTabButtonState(); |
|||
} |
|||
|
|||
class MainTabButtonState extends State<MainTabButton> { |
|||
@override |
|||
Widget build(BuildContext context) { |
|||
if (widget.isRedDot) { |
|||
return Expanded( |
|||
child: GestureDetector( |
|||
onTap: widget.onTap, |
|||
child: Container( |
|||
color: Colors.transparent, |
|||
alignment: Alignment.center, |
|||
child: Stack( |
|||
clipBehavior: Clip.none, |
|||
children: [ |
|||
Column( |
|||
children: [ |
|||
SizedBox(height: 5.w,), |
|||
widget.selected |
|||
? Image.asset(widget.selectedIcon, width: 25.w, height: 25.w) |
|||
: Image.asset(widget.icon, width: 25.w, height: 25.w), |
|||
Text(widget.title, style: const TextStyle( |
|||
fontSize: 12 |
|||
),) |
|||
], |
|||
), |
|||
], |
|||
), |
|||
), |
|||
)); |
|||
} |
|||
|
|||
return Expanded( |
|||
child: GestureDetector( |
|||
onTap: widget.onTap, |
|||
child: Container( |
|||
alignment: Alignment.center, |
|||
color: Colors.transparent, |
|||
child: Column( |
|||
children: [ |
|||
SizedBox(height: 5.w,), |
|||
widget.selected |
|||
? Image.asset(widget.selectedIcon, width: 25.w, height: 25.w) |
|||
: Image.asset(widget.icon, width: 25.w, height: 25.w), |
|||
Text(widget.title, style: const TextStyle( |
|||
fontSize: 12 |
|||
),) |
|||
], |
|||
), |
|||
), |
|||
), |
|||
); |
|||
} |
|||
} |
|||
@ -1,13 +0,0 @@ |
|||
class MainTabItem { |
|||
final String title; |
|||
final String icon; |
|||
final String selectedIcon; |
|||
final bool showRedDot; |
|||
|
|||
const MainTabItem({ |
|||
required this.title, |
|||
required this.icon, |
|||
required this.selectedIcon, |
|||
this.showRedDot = false, |
|||
}); |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save