美文网首页
自定义appbar

自定义appbar

作者: zZ_d205 | 来源:发表于2020-07-23 21:47 被阅读0次

import 'package:flutter/material.dart';

import 'package:flutter_shop/config/font.dart';

import 'package:provide/provide.dart';

import '../../provide/details_info.dart';

import 'package:flutter_screenutil/flutter_screenutil.dart';

class DetailTabBarextends StatelessWidget {

@override

  Widget build(BuildContext context) {

return Provide(

builder: (context,child,val){

var isLeft=Provide.value(context).isLeft;

var isRight=Provide.value(context).isRight;

return Container(

child:Row(

children: [

_myTabBarLeft(context,isLeft),

_myTabBarRight(context,isRight),

],

),

);

}

);

}

Widget _myTabBarLeft(BuildContext context,bool isLeft){

return InkWell(

onTap: (){

Provide.value(context).changeLeftAndRight('left');

},

child:Container(

padding:EdgeInsets.all(10),

alignment: Alignment.center,

width:ScreenUtil().setWidth(375),

decoration:BoxDecoration(

color: Colors.white,

border:Border(

bottom:BorderSide(

width:1.0,

color: isLeft?Colors.pink:Colors.black12

            )

)

),

child:Text("详情",style:TextStyle(

color: isLeft?Colors.pink:Colors.black12

        ),),

),

);

}

Widget _myTabBarRight(BuildContext context,bool isRight){

return InkWell(

onTap: (){

Provide.value(context).changeLeftAndRight('right');

},

child:Container(

padding:EdgeInsets.all(10),

alignment: Alignment.center,

width:ScreenUtil().setWidth(375),

decoration:BoxDecoration(

color: Colors.white,

border:Border(

bottom:BorderSide(

width:1.0,

color: isRight?Colors.pink:Colors.black12

                )

)

),

child:Text("评论",style:TextStyle(

color: isRight?Colors.pink:Colors.black87

        ),),

),

);

}

}

provide中写

boolisLeft=true;

boolisRight=false;

//  tabbar的切换方法

  changeLeftAndRight(String changeState){

if(changeState=='left'){

isLeft=true;

isRight=false;

}else{

isLeft=false;

isRight=true;

}

//    通知监听者

    notifyListeners();

}

相关文章

网友评论

      本文标题:自定义appbar

      本文链接:https://www.haomeiwen.com/subject/bcjklktx.html