message_page.dart 5.17 KB
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/provider/message_model.dart';
import 'package:one_key/provider/user_model.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/utils/event_bus.dart';
import 'package:one_key/widgets/app_bar.dart';
import 'package:one_key/widgets/v_empty_view.dart';
import 'package:provider/provider.dart';
import 'message_online_page.dart';
import 'message_order_page.dart';

class MessagePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new MessagePageState();
  }
}

class MessagePageState extends State<MessagePage> with TickerProviderStateMixin{
  Color selectedColor = MyColours.color_199095;
  Color unSelectedColor = MyColours.color_999999;

  TabController tabController;

  MessageModel messageModel;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    tabController = TabController(length: 2,vsync: this);
    tabController.addListener(() {
      setState(() {
      });
    });
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      _getUnMsgNum();
    });
    bus.on("refresh_untreated_num", (arg) {//舒心未读消息数目
      _getUnMsgNum();
    });
  }

  _getUnMsgNum() async {
    Map<String,String> params={
      "sid":Provider.of<UserModel>(context,listen:false).user.sellerid
    };
    await messageModel.getUnMsgNum(context, params);
    setState(() {
    });
  }
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    messageModel=Provider.of<MessageModel>(context,listen: false);
    return Container(
      width: double.infinity,
      height: double.infinity,
      color: MyColours.color_ffffff,
      child: Column(
        children: <Widget>[
          MyAppBar(
            "消息中心",
            showBack: false,
          ),
          TabBar(
            controller: tabController,
            tabs: [
              Tab(
                child: SizedBox(
                  height: ScreenUtil().setWidth(60),
                  width: ScreenUtil().setWidth(144),
                  child: Stack(
                    children: [
                      Text(
                        "在线预订",
                        style: TextStyle(
                            color: tabController.index == 0
                                ? selectedColor
                                : unSelectedColor,
                            fontSize: ScreenUtil().setSp(32),fontWeight: FontWeight.bold),
                      ),
                      Positioned(
                        top: 0,
                        right: 0,
                        child: Container(
                          width: ScreenUtil().setWidth(16),
                          height: ScreenUtil().setWidth(16),
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(
                                  ScreenUtil().setWidth(16)),
                              color: messageModel.onlineTotal>0?MyColours.color_fa5151:MyColours.color_ffffff),
                        ),
                      )
                    ],
                  ),
                ),
              ),
              Tab(
                child: SizedBox(
                  height: ScreenUtil().setWidth(60),
                  width: ScreenUtil().setWidth(144),
                  child: Stack(
                    children: [
                      Text(
                        "提前点餐",
                        style: TextStyle(
                            color: tabController.index == 1
                                ? selectedColor
                                : unSelectedColor,
                            fontSize: ScreenUtil().setSp(32),fontWeight: FontWeight.bold),
                      ),
                      Positioned(
                        top: 0,
                        right: 0,
                        child: Container(
                          width: ScreenUtil().setWidth(16),
                          height: ScreenUtil().setWidth(16),
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(
                                  ScreenUtil().setWidth(16)),
                              color: messageModel.orderTotal>0?MyColours.color_fa5151:MyColours.color_ffffff),
                        ),
                      )
                    ],
                  ),
                ),
              ),
            ],
            indicatorColor: MyColours.color_199095,
            indicatorSize: TabBarIndicatorSize.label,
            indicatorPadding: EdgeInsets.only(left: ScreenUtil().setWidth(16),right: ScreenUtil().setWidth(32)),
            indicatorWeight: ScreenUtil().setWidth(6.0),
          ),
          VEmptyView(11),
          Expanded(
            flex: 1,
            child:
                TabBarView(controller:tabController,children: [MessageOnlinePage(), MessageOrderPage()]),
          )
        ],
      ),
    );
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    bus.off("refresh_untreated_num");
  }
}