import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:zhiying_base_widget/widgets/empty/empty_widget.dart';
import 'package:zhiying_comm/zhiying_comm.dart';

// 订单搜索页面
class OrderSearchPage extends StatefulWidget {
  @override
  _OrderSearchPageState createState() => _OrderSearchPageState();
}

class _OrderSearchPageState extends State<OrderSearchPage> {
  final TextEditingController _keywordController = TextEditingController();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  void dispose() {
    _keywordController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        FocusScope.of(context).requestFocus(FocusNode());
      },
      child: Scaffold(
        appBar: _createNav(),
        body: SafeArea(
          child: Container(
              width: double.infinity,
              height: double.infinity,
              child: Center(child: EmptyWidget())),
        ),
      ),
    );
  }

  // 导航栏
  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: Container(
        height: 32,
        child: CupertinoTextField(
          autofocus: true,
          padding: EdgeInsets.only(left: 12, right: 12),
          decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(16),
              color: Color(0xfff9f9f9)),
          placeholder: '搜索商品标题/粉丝姓名/订单号',
          placeholderStyle: TextStyle(color: Color(0xff999999), fontSize: 14),
          controller: _keywordController,
          style: TextStyle(fontSize: 14, color: Color(0xff333333)),
          textInputAction: TextInputAction.search,
          onSubmitted: _search,
        ),
      ),
      trailing: Container(
        padding: EdgeInsets.only(left: 10),
        child: CupertinoButton(
          padding: EdgeInsets.zero,
          child: Text(
            '搜索',
            style: TextStyle(
              fontSize: 14,
              color: Colors.redAccent,
            ),
          ),
          onPressed: () {
            Logger.debug(_keywordController.text);
            _search(_keywordController.text);
          },
        ),
      ),
    );
  }

  void _search(String keyword) {
    FocusScope.of(context).requestFocus(FocusNode());
  }
}
