Commit f6a8e0b6 authored by 林生雨's avatar 林生雨

commit

parent d1df55f1
...@@ -491,7 +491,7 @@ Widget askWidget() { ...@@ -491,7 +491,7 @@ Widget askWidget() {
} }
class StickyTabBarDelegate extends SliverPersistentHeaderDelegate { class StickyTabBarDelegate extends SliverPersistentHeaderDelegate {
final TabBar child; final Widget child;
StickyTabBarDelegate({@required this.child}); StickyTabBarDelegate({@required this.child});
...@@ -502,10 +502,10 @@ class StickyTabBarDelegate extends SliverPersistentHeaderDelegate { ...@@ -502,10 +502,10 @@ class StickyTabBarDelegate extends SliverPersistentHeaderDelegate {
} }
@override @override
double get maxExtent => this.child.preferredSize.height; double get maxExtent => 40;
@override @override
double get minExtent => this.child.preferredSize.height; double get minExtent => 40;
@override @override
bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) { bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) {
......
...@@ -8,18 +8,14 @@ import 'package:flutter_common/commonModel/live/LiveData.dart'; ...@@ -8,18 +8,14 @@ import 'package:flutter_common/commonModel/live/LiveData.dart';
class TopModel extends BaseModel { class TopModel extends BaseModel {
int tabIndex = 0; int tabIndex = 0;
List<String> tabs = ["全部", "眼部", "自体脂肪", "轮廓骨骼"]; List<String> tabs = ["全部", "眼部", "自体脂肪", "轮廓骨骼"];
LiveData<int> tabIndexLive = LiveData();
@override @override
void dispose() { void dispose() {}
tabIndexLive.dispost();
}
void selectTab(int index) { void selectTab(int index) {
if (tabIndex == index) { if (tabIndex == index) {
return; return;
} }
tabIndex = index; tabIndex = index;
tabIndexLive.notifyView(index);
} }
} }
...@@ -51,51 +51,50 @@ class TopPageState extends BaseState<TopPage> with TickerProviderStateMixin { ...@@ -51,51 +51,50 @@ class TopPageState extends BaseState<TopPage> with TickerProviderStateMixin {
), ),
SliverToBoxAdapter( SliverToBoxAdapter(
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
children: <Widget>[ children: <Widget>[
Container( Container(
height: 50, height: 50,
) color: Colors.pink,
], )
)), ],
)),
SliverPersistentHeader( SliverPersistentHeader(
pinned: true, pinned: true,
delegate: StickyTabBarDelegate( delegate: StickyTabBarDelegate(
child: baseTabBar(tabController, getTabs(), (index) { child: Container(
_model.selectTab(index); height: 40,
})), color: Colors.white,
child: baseTabBar(tabController, getTabs(), (index) {
_model.selectTab(index);
}),
)),
), ),
SliverFillRemaining( SliverFillRemaining(
child: TabBarView(controller: tabController, children: <Widget>[ child: TabBarView(controller: tabController, children: <Widget>[
Container( Container(
color: Colors.red, color: Colors.red,
), ),
Container( Container(
color: Colors.red, color: Colors.red,
), ),
Container( Container(
color: Colors.red, color: Colors.red,
), ),
Container( Container(
color: Colors.blue, color: Colors.blue,
) )
])) ]))
])); ]));
} }
List<Widget> getTabs() { List<Widget> getTabs() {
List<Widget> list = []; List<Widget> list = [];
for (int i = 0; i < _model.tabs.length; i++) { for (int i = 0; i < _model.tabs.length; i++) {
list.add( Container( list.add(baseTabBarItem(_model.tabs[i],
height: 40, leftPadding: i == 0 ? 24 : 28,
width: 50, rightPadding: i == _model.tabs.length - 1 ? 24 : 28));
color: Colors.red,
));
// list.add(baseTabBarItem(_model.tabs[i],
// leftPadding: i == 0 ? 24 : 28,
// color: i == _model.tabIndex ? Color(0xff282828) : Color(0xffB5B5B5)));
} }
return list; return list;
} }
......
...@@ -400,12 +400,16 @@ Widget emptyItem(double width, double height, {String detail}) { ...@@ -400,12 +400,16 @@ Widget emptyItem(double width, double height, {String detail}) {
Widget baseTabBar( Widget baseTabBar(
TabController controller, List<Widget> list, Function(int index) clickItem, TabController controller, List<Widget> list, Function(int index) clickItem,
{BaseIndicator baseIndicator}) { {BaseIndicator baseIndicator, double fontSize, Color color, bool scroll}) {
TabBar( return TabBar(
onTap: clickItem, onTap: clickItem,
controller: controller, controller: controller,
indicatorSize: TabBarIndicatorSize.tab, indicatorSize: TabBarIndicatorSize.tab,
isScrollable: true, isScrollable: scroll ?? true,
unselectedLabelColor: color ?? Color(0xffB5B5B5),
labelColor: color ?? Color(0xff282828),
labelStyle: TextStyle(fontSize: fontSize ?? 16),
unselectedLabelStyle: TextStyle(fontSize: fontSize ?? 16),
labelPadding: EdgeInsets.only(), labelPadding: EdgeInsets.only(),
indicator: baseIndicator ?? BaseIndicator(), indicator: baseIndicator ?? BaseIndicator(),
tabs: list, tabs: list,
...@@ -416,15 +420,16 @@ Widget baseTabBarItem( ...@@ -416,15 +420,16 @@ Widget baseTabBarItem(
String text, { String text, {
double leftPadding, double leftPadding,
double rightPadding, double rightPadding,
double fontSize,
Color color,
}) { }) {
double width = leftPadding??28 + text.length * 40.0 + rightPadding ??28; leftPadding = leftPadding ?? 28.0;
print("WIDTH ${width}"); rightPadding = rightPadding ?? 28.0;
double width = leftPadding + text.length * 16.0 + rightPadding;
return Container( return Container(
height: 40, height: 40,
width: width, width: width,
alignment: Alignment.center, alignment: Alignment.center,
child: baseText(text, fontSize ?? 16, color ?? Color(0xffB5B5B5)), child: Tab(
text: text,
),
); );
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment