Instead of doing a push, you can use DefaultTabController
to change the current index using animateTo
. You need to wrap IconButton
in a Builder
since DefaultTabController
is accessed in the same widget where it's created.
Builder(
builder: (context) => IconButton(
icon: icon,
onPressed: () {
DefaultTabController.of(context).animateTo(1); // 1 is index of 2nd tab (cart tab).
},
),
);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…