Flutter: where can we use linear gradient instead of container

Issue

I want to put a LinearGradient instead of using Container’s BoxDecorations,

For example:

return CustomSlidingSegmentedControl<int>(
  children: myTabs,
  innerPadding: 2,
  duration: Duration(milliseconds: 200),
  thumbColor: [HERE I WANT TO USE LINEAR-GRADIENT],
  backgroundColor: Color(0xFFF3F3F3),
  radius: 30.0,
  onValueChanged: (i) {
    this.index  i;
    widget.onChanged(i);
  },
);

If you know a solution, your share would be helpful!

Also if my instruction is insufficient, please let me know where I should add it.

Thank you in advance:D

Solution

You can wrap the CustomSlidingSegmentedControl widget in a container with Linear Gradient.

return Container(
  decoration:
  BoxDecoration(gradient: LinearGradient()),
  child: CustomSlidingSegmentedControl<int>(
  children: myTabs),
  innerPadding: 2,
  duration: Duration(milliseconds: 200),
  backgroundColor: Color(0xFFF3F3F3),
  radius: 30.0,
  onValueChanged: (i) {
    this.index  i;
    widget.onChanged(i);
  },
);

Answered By – That Guy

Leave a Comment