Я хочу, чтобы индикатор был включен обе вкладки, просто разные для обеих вкладок.
Я пытаюсь применить пользовательский индикатор к свойству индикатора с помощью
Код: Выделить всё
indicator: CustomTabIndicator(
height: 4,
width: MediaQuery.of(context).size.width / 2.9,
selectedIndex: _selectedIndex,
),
this is indiactor i am calling
class CustomTabIndicator extends Decoration {
final double height;
final double width;
final int selectedIndex;
const CustomTabIndicator({
this.height = 4,
this.width = 30,
required this.selectedIndex,
});
@override
BoxPainter createBoxPainter([VoidCallback? onChanged]) {
return _CustomTabIndicatorPainter(
height: height,
width: width,
selectedIndex: selectedIndex,
);
}
}
class _CustomTabIndicatorPainter extends BoxPainter {
final double height;
final double width;
final int selectedIndex;
_CustomTabIndicatorPainter({
required this.height,
required this.width,
required this.selectedIndex,
});
@override
void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
final Paint paint = Paint();
final double tabWidth = configuration.size!.width;
paint.color = Colors.grey.withOpacity(0.5);
for (int i = 0; i < 2; i++) {
Rect greyRect = Offset(
offset.dx + (tabWidth * i) + (tabWidth - width) / 2.5,
configuration.size!.height - height - 8,
) &
Size(width, height);
canvas.drawRect(greyRect, paint);
}
paint.color = Colors.orange;
Rect orangeRect = Offset(
offset.dx + (tabWidth * selectedIndex) + (tabWidth - width) / 2.5,
configuration.size!.height - height - 8,
) &
Size(width, height);
canvas.drawRect(orangeRect, paint));
}
}
Подробнее здесь: https://stackoverflow.com/questions/789 ... ing-custom