sliver_bar.dart 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import 'package:flutter/material.dart';
  2. import 'package:twong/config/style.dart';
  3. import 'package:twong/utils/image_utils.dart';
  4. import 'package:twong/utils/index.dart';
  5. class SliverBar extends StatefulWidget {
  6. final List<Widget> menus;
  7. final Function clickFunc;
  8. SliverBar({ Key key, this.menus, this.clickFunc } ): super(key: key);
  9. @override
  10. State<StatefulWidget> createState() {
  11. return _SliverBarState();
  12. }
  13. }
  14. class _SliverBarState extends State<SliverBar> {
  15. TextStyle _style = TextStyle(fontSize: 14, color: Colors.grey,);
  16. TextStyle _selectStyle = TextStyle(fontSize: 14, color: Colors.black,);
  17. int _curIdx = 0;
  18. changeType (int type) {
  19. setState(() {
  20. _curIdx = type;
  21. });
  22. }
  23. List<Widget> genMenus() {
  24. List<Widget> widgets = new List<Widget>();
  25. for(var item in widget.menus) {
  26. var widget = Expanded(child: GestureDetector(
  27. onTap: () => changeType(0),
  28. child: Text("默认", textAlign: TextAlign.center, style: _curIdx == 0 ? _selectStyle : _style,),
  29. ));
  30. widgets.add(widget);
  31. }
  32. return widgets;
  33. }
  34. @override
  35. Widget build(BuildContext context) {
  36. return SliverAppBar(
  37. pinned: true,
  38. centerTitle: true,
  39. backgroundColor: Colors.white,
  40. shape: Border(
  41. bottom: BorderSide(color: Colors.grey, width: 0.3.px)
  42. ),
  43. shadowColor: Colors.black,
  44. automaticallyImplyLeading: false,
  45. title: Row(
  46. mainAxisAlignment: MainAxisAlignment.center,
  47. children: <Widget>[
  48. Expanded(child: GestureDetector(
  49. onTap: () => changeType(0),
  50. child: Text("默认", textAlign: TextAlign.center,
  51. style: _curIdx == 0 ? _selectStyle : _style,)),
  52. ),
  53. Expanded(child: GestureDetector(
  54. onTap: () => changeType(1),
  55. child: Text("销量", textAlign: TextAlign.center,
  56. style: _curIdx == 1 ? _selectStyle : _style,)),
  57. ),
  58. Expanded(child: GestureDetector(
  59. onTap: () => changeType(2),
  60. child: Row(
  61. mainAxisAlignment: MainAxisAlignment.center,
  62. children: [
  63. Text("价格", textAlign: TextAlign.center,
  64. style: _curIdx == 2 ? _selectStyle : _style,),
  65. Icon(IconFonts.sort,
  66. color: _curIdx == 2 ? Colors.black : Colors.grey)
  67. ],
  68. ),
  69. )),
  70. ],
  71. ),
  72. bottom: PreferredSize(
  73. child: Container(),
  74. preferredSize: Size.fromHeight(-8.px),
  75. ),
  76. );
  77. }
  78. }