I’m trying to create a custom border with a dynamic size and a gradient color on it.
How can I create a border with the same width as the text above?
@override
Widget build(BuildContext context) {
var selectedItemIndex = 0;
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Wrap(
spacing: 32,
children: list.asMap().entries.map((entry) {
var isSelectedItem = (entry.key == selectedItemIndex);
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
entry.value,
style: TextStyle(
fontSize: 16,
color:
entry.key == selectedItemIndex ? Colors.white : lightGrey,
),
),
const SizedBox(
height: 4,
),
Flex(
direction: Axis.horizontal,
children: [
Container(
height: isSelectedItem ? 3 : 2,
width: 40, // <- fixed size
decoration: const BoxDecoration(
gradient: purpleGradient,
),
),
],
),
],
);
}).toList(),
),
);
}
ps.: I tried Flex
, Flexible
, and double.infinity
to expand the border’s width.
2
Answers
See https://medium.com/vijay-r/neon-light-effect-flutter-23a36c341fe7 will help you,
For dynamic size Try setting mainAxisSize: MainAxisSize.min on the column and adding some spacing.
Try this:
custom button:
use custom button in screen: