Home > Net >  How to do a Decorated line in Flutter
How to do a Decorated line in Flutter

Time:10-21

How can I make a line that "goes down", like this:

image

CodePudding user response:

Try below code:

  Row(
          children: [
            Expanded(
              flex: 2,
              child: Container(
                height: 0.7,
                decoration: BoxDecoration(
                  color: Colors.grey,
                  gradient: LinearGradient(
                    colors: [
                      Colors.green,
                      Colors.green.shade50,
                    ],
                    begin: Alignment.centerRight,
                    end: Alignment.centerLeft,
                  ),
                ),
              ),
            ),
            const Expanded(
              flex: 1,
              child: Align(
                alignment: Alignment.center,
                child: Text(
                  'Or',
                ),
              ),
            ),
            Expanded(
              flex: 2,
              child: Container(
                height: 0.7,
                decoration: BoxDecoration(
                  color: Colors.grey,
                  gradient: LinearGradient(
                    colors: [
                      Colors.green,
                      Colors.green.shade50,
                    ],
                    begin: Alignment.centerLeft,
                    end: Alignment.centerRight,
                  ),
                ),
              ),
            ),
          ],
        ),

Result-> image

CodePudding user response:

Using LinearGradient and setting up with different opacity of colors.

class MyWidget extends StatelessWidget {
  
  final Color green = Colors.green;
  
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 50,
      width: 300,
      decoration: BoxDecoration(
        gradient: LinearGradient(
          colors: [
            green,
            green.withOpacity(0.75),
            green.withOpacity(0.50),
            green.withOpacity(0.25),
            green.withOpacity(0.0),
          ],
        ),
      ),
    );
  }
}
  • Related