import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:liftmanager/routers/fluro_navigator.dart';
import 'package:liftmanager/internal/search/search_router.dart';
import 'package:liftmanager/res/colors.dart';
import 'package:liftmanager/res/dimens.dart';
import 'package:liftmanager/res/gaps.dart';
import 'package:liftmanager/utils/theme_utils.dart';
import 'package:liftmanager/widgets/load_image.dart';
import 'package:liftmanager/internal/wode/wode_router.dart';
import 'package:flustars/flustars.dart' as FlutterStars;
import 'package:liftmanager/common/common.dart';
import 'package:liftmanager/internal/account/account_router.dart';
import 'package:liftmanager/utils/toast.dart';

/// 自定义AppBar
class AppCitySearchAppBar extends StatelessWidget
    implements PreferredSizeWidget {
  const AppCitySearchAppBar(
      {Key key,
      this.city: "",
      this.centerTitle: "",
      this.actionName: "",
      this.actionIcon: "",
      this.backImg: "assets/images/icon_back.png",
      this.onPressed,
      this.isBack: true,
      this.display: true,
      })
      : super(key: key);

  final String city;
  final String centerTitle;
  final String backImg;
  final String actionName;
  final String actionIcon;
  final VoidCallback onPressed;
  final bool isBack;
  final bool display;

  @override
  Widget build(BuildContext context) {
    double width = MediaQuery.of(context).size.width;
    return AnnotatedRegion<SystemUiOverlayStyle>(
      value: SystemUiOverlayStyle.light,
      child: Container(
        decoration: BoxDecoration(
          gradient: const LinearGradient(
              colors: [Color(0xFF00D9FF), Color(0xFF0287FF)]),
        ),
//        child: Material(
////          color: _backgroundColor,
//          color: Colors.red,
//          shadowColor: Colors.amber,
        child: SafeArea(
          child: Stack(
            alignment: Alignment.centerLeft,
            children: <Widget>[
              Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Container(
                    alignment: Alignment.centerLeft,
                    width: double.infinity,
                    child: Text(city,
                        overflow: TextOverflow.ellipsis,
                        style: TextStyle(
                            fontSize: Dimens.font_sp16, color: Colors.white)),
                    padding: const EdgeInsets.symmetric(horizontal: 15.0),
                  ),
                ],
              ),
//              Column(
//                mainAxisAlignment: MainAxisAlignment.center,
//                children: <Widget>[
//                  Container(
//                      padding: const EdgeInsets.only(left: 50.0),
//                      child: Icon(
//                        Icons.keyboard_arrow_down,
//                        size: 20,
//                        color: Colors.white,
//                      )),
//                ],
//              ),
              GestureDetector(
                  onTap: () {
                    if(FlutterStars.SpUtil.getString(Constant.userId) == "-1"){
                      toasts("请登录");
                      NavigatorUtils.push(context, AccountRouter.loginPage, clearStack: true);
                    }else {
                      NavigatorUtils.push(context, SearchRouter.searchPage);
                    }
                  },
                  child: Container(
                    height: 35,
                    width: width*0.65,
                    margin: const EdgeInsets.only(left: 85.0, right: 15),
                    decoration: BoxDecoration(
                        color: Color(0x33FFFFFF),
                        borderRadius: BorderRadius.circular(17.5)),
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: <Widget>[
                        SizedBox(
                          width: 16,
                        ),
                        Icon(
                          Icons.search,
                          color: Colors.white,
                        ),
                        Text(
                          "搜索你想要的关键词",
                          style: TextStyle(color: Colors.white),
                        )
                      ],
                    ),
                  )),
              GestureDetector(
                onTap: (){
                  if(FlutterStars.SpUtil.getString(Constant.userId) == "-1"){
                    toasts("请登录");
                      NavigatorUtils.push(context, AccountRouter.loginPage, clearStack: true);
                  }else {
                    NavigatorUtils.push(context, WodeRouter.noticeList);
                  }
                },
                child: Container(
                alignment:Alignment.centerRight,
                padding: EdgeInsets.only(right:6),
                child:Stack(
                  children: <Widget>[
                    Icon(
                      IconData(
                        0xe64f,
                        fontFamily:"myfont"
                      ),
                      size: 26.0,
                      color:Color.fromRGBO(255, 255, 255, 1),
                    ),
                    Positioned(
                      child: (
                        RedCirle(display:display)
                      ),
                      top:0,
                      right:0
                    ),
                  ],
              )
              ),
              ),  
              
            ],
          ),
        ),
//        ),
      ),
    );
  }

  @override
  Size get preferredSize => Size.fromHeight(48.0);
}

class RedCirle extends StatelessWidget {
  final bool display;
  const RedCirle(
    {
      Key key,
      this.display:true,
    })
     : super(key: key);

  

  @override
  Widget build(BuildContext context) {
    return Offstage(
      offstage: display,
      child:Container(
        width:6,
        height:6,
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(3.0),
          color: Colors.red,
        ),
      )
    );
  }
}