import 'package:flutter/material.dart';

/**
 * Created with IntelliJ IDEA.
 * Package: utils
 * Author: sirai
 * Create Time: 2019-06-24 16:10
 * QQ: 785716471
 * Email: 785716471@qq.com
 * Description:公共的titlebar
 */

class TitleBar {
  /**
   * 仅含 左侧返回按钮 及中间标题
   * appBar: TitleBar().backAppbar(context, '个人资料'),
   * appBar: TitleBar().backAppbar(context, '个人资料',(){}),
   */
  backAppbar(String title) {
    return AppBar(
      title: Text(
        title,
        style: TextStyle(color: Colors.white, fontSize: 16),
      ),
      centerTitle: true,
      leading: BackButton(),
      brightness: Brightness.light,
      backgroundColor: Color(0xFF4875EC),
      elevation: 0,
      iconTheme: IconThemeData(color: Colors.white),
    );
  }

  // backCallAppbar(String title,VoidCallback callback) {
  //   return AppBar(
  //     title: Text(
  //       title,
  //       style: TextStyle(color: Colors.white, fontSize: 16),
  //     ),
  //     centerTitle: true,
  //     leading: callback,
  //     brightness: Brightness.light,
  //     backgroundColor: Color(0xFF4875EC),
  //     elevation: 0,
  //     iconTheme: IconThemeData(color: Colors.white),
  //   );
  // }

  /**
   * 设置左侧按钮
   */
  textAppBar(String title, String text, VoidCallback rightButtonClick) {
    return AppBar(
      centerTitle: true,
      titleSpacing: 0,
      elevation: 0,
      backgroundColor: Color(0xFF4875EC),
      leading: BackButton(),
      // 返回按钮
      title: Text(
        title,
        style: TextStyle(fontSize: 16),
      ),
      automaticallyImplyLeading: false,
      // 标题
      actions: <Widget>[
        TextButton(
          // action button
          onPressed: rightButtonClick,
          style: ButtonStyle(
            padding: MaterialStateProperty.all(const EdgeInsets.only(
                left: 10, right: 20, top: 10, bottom: 10)),
            foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
          ),
          // action button
          child: Text(text,style: const TextStyle( fontSize: 15)),
        )
      ],
    );
  }

  drawAppBar(String title, VoidCallback rightButtonClick) {
    return AppBar(
      centerTitle: true,
      titleSpacing: 0,
      elevation: 0,
      backgroundColor: Color(0xFF4875EC),
      leading: BackButton(),
      // 返回按钮
      title: Text(
        title,
        style: TextStyle(fontSize: 16),
      ),
      automaticallyImplyLeading: false,
      // 标题
      actions: <Widget>[
        new IconButton(
          // action button
          padding: EdgeInsets.only(right: 20),
          icon: new Icon(Icons.drive_file_rename_outline),
          onPressed: rightButtonClick,
        ),
      ],
    );
  }

  /**
   * 关闭页面
   */
  _popThis(BuildContext context) {
    Navigator.of(context).pop();
  }
}
