| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- 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<Widget> menus;
- final Function clickFunc;
- SliverBar({ Key key, this.menus, this.clickFunc } ): super(key: key);
- @override
- State<StatefulWidget> createState() {
- return _SliverBarState();
- }
- }
- class _SliverBarState extends State<SliverBar> {
- 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<Widget> genMenus() {
- List<Widget> widgets = new List<Widget>();
- 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: <Widget>[
- 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),
- ),
- );
- }
- }
|