import 'package:flutter/material.dart';
import 'package:zhiying_base_widget/pages/brand_search_page/brand_search_page_bloc.dart';
import 'package:zhiying_comm/util/base_bloc.dart';
import 'package:zhiying_comm/util/extension/color.dart';

class BrandSearchPage extends StatefulWidget {
  @override
  _BrandSearchPageState createState() => _BrandSearchPageState();
}

class _BrandSearchPageState extends State<BrandSearchPage> {
  @override
  Widget build(BuildContext context) {
    return BlocProvider(
        child: BrandSearchContainer(), bloc: BrandSearchPageBloc());
  }
}

class BrandSearchContainer extends StatefulWidget {
  @override
  _BrandSearchContainerState createState() => _BrandSearchContainerState();
}

class _BrandSearchContainerState extends State<BrandSearchContainer> {
  @override
  Widget build(BuildContext context) {
    return StreamBuilder(builder: (context, asycn) {
      return Scaffold(
        appBar: AppBar(
          leading: Navigator.canPop(context)
              ? IconButton(icon: Icon(Icons.arrow_back_ios), onPressed: () {})
              : null,
          centerTitle: true,
          title: _buildTopSearch(),
        ),
      );
    });
  }

  _buildTopSearch() {
    return Container(
      height: 35,
      child: Stack(
        children: <Widget>[
          Row(
            mainAxisSize: MainAxisSize.max,
            children: <Widget>[
              Expanded(
                child: Container(
                  height: 35,
                  margin: EdgeInsets.only(right: 35),
                  padding: EdgeInsets.only(left: 16),
                  decoration: BoxDecoration(
                      color: Colors.grey[100],
                      borderRadius: BorderRadius.circular(32)),
                  child: Row(
                    children: <Widget>[
                      Icon(
                        Icons.search,
                        color: Colors.grey[400],
                      ),
                      SizedBox(
                        width: 8,
                      ),
                      Expanded(
                        child: TextField(
                          onSubmitted: (value) => toSearch(value),
                          style: TextStyle(fontSize: 16),
                          decoration: InputDecoration(
                            isDense: true,
                            border: InputBorder.none,
                            contentPadding: EdgeInsets.zero,
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
          Align(
            alignment: Alignment.centerRight,
            child: Container(
              width: 65,
              child: FlatButton(
                color: Colors.red,
                padding: EdgeInsets.only(left: 0),
                onPressed: () {},
                child: Text(
                  "搜索",
                  style: TextStyle(color: HexColor.fromHex("#FFFFFF")),
                ),
                shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(32)),
              ),
            ),
          )
        ],
      ),
    );
  }

  ///搜索
  toSearch(String value) {}
}
