import 'package:flutter/material.dart'; import 'package:twong/config/style.dart'; import 'package:twong/utils/image_utils.dart'; import 'package:twong/utils/index.dart'; class SliverBar extends StatefulWidget { final List menus; final Function clickFunc; SliverBar({ Key key, this.menus, this.clickFunc } ): super(key: key); @override State createState() { return _SliverBarState(); } } class _SliverBarState extends State { TextStyle _style = TextStyle(fontSize: 14, color: Colors.grey,); TextStyle _selectStyle = TextStyle(fontSize: 14, color: Colors.black,); int _curIdx = 0; changeType (int type) { setState(() { _curIdx = type; }); } List genMenus() { List widgets = new List(); for(var item in widget.menus) { var widget = Expanded(child: GestureDetector( onTap: () => changeType(0), child: Text("默认", textAlign: TextAlign.center, style: _curIdx == 0 ? _selectStyle : _style,), )); widgets.add(widget); } return widgets; } @override Widget build(BuildContext context) { return SliverAppBar( pinned: true, centerTitle: true, backgroundColor: Colors.white, shape: Border( bottom: BorderSide(color: Colors.grey, width: 0.3.px) ), shadowColor: Colors.black, automaticallyImplyLeading: false, title: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Expanded(child: GestureDetector( onTap: () => changeType(0), child: Text("默认", textAlign: TextAlign.center, style: _curIdx == 0 ? _selectStyle : _style,)), ), Expanded(child: GestureDetector( onTap: () => changeType(1), child: Text("销量", textAlign: TextAlign.center, style: _curIdx == 1 ? _selectStyle : _style,)), ), Expanded(child: GestureDetector( onTap: () => changeType(2), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Text("价格", textAlign: TextAlign.center, style: _curIdx == 2 ? _selectStyle : _style,), Icon(IconFonts.sort, color: _curIdx == 2 ? Colors.black : Colors.grey) ], ), )), ], ), bottom: PreferredSize( child: Container(), preferredSize: Size.fromHeight(-8.px), ), ); } }