希望的效果是,被点击的cell有actived
效果,其他cell去掉效果
代码如下:
import 'package:flutter/material.dart';
class MyCell extends StatefulWidget {
final data;
MyCell({ Key key, this.data }): super(key: key);
_MyCellState createState() => _MyCellState();
}
class _MyCellState extends State<MyCell> {
String _actived = '/home';
@override
Widget build(BuildContext context) {
Color bg = _actived == widget.data['route'] ? Colors.grey[300] : Colors.white;
Color co = _actived == widget.data['route'] ? Colors.pink[300] : Colors.grey[800];
return Material(
color: bg,
child: InkWell(
onTap: () {
setState(() {
_actived = widget.data['route'];
});
},
child: Container(
height: 50,
padding: EdgeInsets.only(left: 20, right: 20),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Icon(widget.data['icon'], color: co, size: 20,),
Container(
padding: EdgeInsets.only(left: 20),
child: Text(widget.data['label'], style: TextStyle(fontSize: 16, color: co)),
),
],
),
),
),
);
}
}
这是
drawer
里单个按钮的Widget
吧,每个按钮都有自己的_activated
也只能被自己的点击事件重新赋值,点击其他按钮并不会影响现在这个按钮的_activated
应该把这个
_activated
放在drawer
里会比较好,可以管理到所有按钮的state