import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:zhiying_base_widget/pages/orders_page/views/order_filter.dart';
import 'package:zhiying_base_widget/pages/orders_page/views/order_item_widget.dart';
import 'package:zhiying_base_widget/pages/orders_page/views/order_serch_widget.dart';
import 'package:zhiying_base_widget/pages/orders_page/views/order_tabbar_widget.dart';

// 订单页面
class OrdersPage extends StatefulWidget {
  final Map<String, dynamic> data;

  const OrdersPage(
    this.data, {
    Key key,
  }) : super(key: key);

  @override
  _OrdersPageState createState() => _OrdersPageState();
}

class _OrdersPageState extends State<OrdersPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color(0xfff9f9f9),
      appBar: _createNav(),
      body: SafeArea(
        child: _OrdersContainer(),
      ),
    );
  }

  // 导航栏
  Widget _createNav() {
    return CupertinoNavigationBar(
      border: Border(
        bottom: BorderSide(
          width: 0.0, // One physical pixel.
          style: BorderStyle.none,
        ),
      ),
      backgroundColor: Colors.white,
      leading: Navigator.canPop(context)
          ? GestureDetector(
              child: Container(
                padding: EdgeInsets.zero,
                child: Icon(
                  Icons.arrow_back_ios,
                  size: 20,
                ),
              ),
              onTap: () {
                if (Navigator.canPop(context)) {
                  Navigator.pop(context);
                }
              },
            )
          : Container(),
      middle: Text(
        '我的订单',
        style: TextStyle(
          fontSize: 15,
          color: Color(0xff333333),
        ),
      ),
    );
  }
}

class _OrdersContainer extends StatefulWidget {
  @override
  _OrdersContainerState createState() => _OrdersContainerState();
}

class _OrdersContainerState extends State<_OrdersContainer>
    with TickerProviderStateMixin {
  TabController _tabController;

  GlobalKey _tabKey = GlobalKey();

  bool _isFilterShow = false;

  @override
  void initState() {
    _tabController = TabController(length: 6, vsync: this);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        OrderSearchWidget(),
        OrderTabbarWidget(
          _tabController,
          [
            '全部',
            '已付款',
            '已结算',
            '已失效',
            '全部',
            '已付款',
          ],
          key: _tabKey,
          onMoreClick: () {
            setState(() {
              _isFilterShow = !_isFilterShow;
            });
          },
        ),
        Expanded(
          child: Stack(
            children: <Widget>[
              ListView.builder(
                  itemCount: 20,
                  itemBuilder: (context, index) {
                    return OrderItemWidget();
                  }),
              Visibility(
                visible: _isFilterShow,
                child: OrderFilterWidget(),
              )
            ],
          ),
        )
      ],
    );
  }
}
