im a UI-Designer who is trying to code with flutter (no experience yet, learning with the internet).
i try to code a segmented control, which shall look like this: enter image description here
After hours i came that far:
isSelected: isSelected,
borderRadius: BorderRadius.circular(12.0),
//selectedBorderColor: burple,
children: [
Container(
decoration: ShapeDecoration(
color: isSelected[0] == false ? black3 : null,
gradient: isSelected[0] == true
? primaryGradient
: null,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(12),
topLeft: Radius.circular(12),
bottomRight: Radius.circular(12),
topRight: Radius.circular(12),
),
),
),
width: MediaQuery.of(context).size.width * 0.3,
padding: const EdgeInsets.symmetric(horizontal: 24),
child: const Center(child: Text('Events')),
),
Container(
decoration: ShapeDecoration(
color: isSelected[1] == false ? black3 : null,
gradient: isSelected[1] == true
? primaryGradient
: null,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(12),
topRight: Radius.circular(12)),
),
),
width: MediaQuery.of(context).size.width * 0.3,
padding: const EdgeInsets.symmetric(horizontal: 24),
child: const Center(child: Text('Bars')),
But it looks like that:
I dont get the idea on how to add those to inner shadows (to make it look like a 3D-Pill) and How to get the padding between the borders. Sorry for the bad quality, im still fighting with the resolution of android studio.
I tried this, but the shadow is always outside and not inner:
Container(
decoration: ShapeDecoration(
color: isSelected[0] == false ? black3 : null,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
boxShadow: isSelected[0] == true
? [
BoxShadow(
color: Colors.black.withOpacity(0.4),
offset: Offset(2.0, 2.0),
blurRadius: 4.0,
),
BoxShadow(
color: Colors.white.withOpacity(0.2),
offset: Offset(-2.0, -2.0),
blurRadius: 4.0,
),
]
: null,
),
For the padding i had literally no idea
2
Answers
‘padding’ is used to add space around the child widget within its parent widget.
You can wrap main container like this to give shadow as image.