Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a colored bottom border on a rounded corner Container in flutter?

Tags:

ios

flutter

I'm trying to create a rounded cornered Container with a colored bottom border(One side).

I tried applying border radius and borderSide color to them but I seem to seem to get an error, and the widget fails to render.

Container(
  margin: EdgeInsets.only(
    top:15.0
  ),
  decoration: BoxDecoration(
    color: Colors.white,
    borderRadius: BorderRadius.all(
      Radius.circular(3)
    ),
    border: Border(
      bottom: BorderSide(color: Color.fromRGBO(0, 83, 79, 1),
      width: 3.0
      ))
  )...

I get this Error Message: A border-radius can only be given for uniform borders.This is what I'm trying to achieve

like image 977
Mussa Kalokola Avatar asked Sep 26 '19 09:09

Mussa Kalokola


2 Answers

I think you need to use ClipPath like:

ClipPath(
    clipper: ShapeBorderClipper(
        shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.all(Radius.circular(10))
        )
    ),
    child: Container(
        height: 70.0,
        width: 200.0,
        decoration: BoxDecoration(
            color: Colors.orange,
            border: Border(
                bottom: BorderSide(
                    color: Color.fromRGBO(0, 83, 79, 1),
                    width: 7.0
                )
            )
        )
    )
)

Output for reference:

see output here

like image 78
Hagar2M Avatar answered Sep 27 '22 23:09

Hagar2M


Use InkWell widget with BoxDecoration

  import 'package:flutter/material.dart';

    void main() {
    runApp(MyApp());
    }

    class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
        return MaterialApp(
        title: 'Flutter Demo',
        home: HomePage(),
        );
    }
    }

    class HomePage extends StatefulWidget {
    @override
    _HomePageState createState() => _HomePageState();
    }

    class _HomePageState extends State<HomePage> {
    @override
    Widget build(BuildContext context) {
        return Scaffold(
        appBar: AppBar(),
        body: Center(
            child: Padding(
            padding: EdgeInsets.all(18.0),
            child: Container(
            padding: EdgeInsets.only(
                top: 18.0,
            ),
            margin: EdgeInsets.only(top: 13.0, right: 8.0),
            decoration: BoxDecoration(
                color: Colors.white,
                shape: BoxShape.rectangle,
                borderRadius: BorderRadius.circular(16.0),
                boxShadow: <BoxShadow>[
                    BoxShadow(
                    color: Colors.black26,
                    blurRadius: 0.0,
                    offset: Offset(0.0, 0.0),
                    ),
                ]),
            child: Column(
                mainAxisSize: MainAxisSize.min,
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: <Widget>[
                SizedBox(
                    height: 20.0,
                ),
                Center(
                    child: Padding(
                    padding: const EdgeInsets.all(10.0),
                    child: new Text("Your Text",
                        style: TextStyle(fontSize: 30.0, color: Colors.black)),
                )),
                SizedBox(height: 24.0),
                InkWell(
                    child: Container(
                    padding: EdgeInsets.only(top: 4.0, bottom: 4.0),
                    decoration: BoxDecoration(
                        color: Colors.green,
                        borderRadius: BorderRadius.only(
                            bottomLeft: Radius.circular(16.0),
                            bottomRight: Radius.circular(16.0)),
                    ),
                    ),
                    onTap: () {
                    Navigator.pop(context);
                    },
                )
                ],
            ),
            ),
        )),
        );
    }
    }

enter image description here

like image 35
Amit Prajapati Avatar answered Sep 27 '22 23:09

Amit Prajapati