Home > Software design >  How to create a custom border like this in Flutter?
How to create a custom border like this in Flutter?

Time:09-20

I need a border for 25%,50%,75% and 100% Required Result

CodePudding user response:

You can custom it with Stack of Containers like this:

  Widget _widget({int percent = 25}) {
    return Center(
      child: Stack(
        children: [
          Positioned.fill(
            child: Row(
              children: [
                Flexible(
                  flex: percent,
                  child: Container(
                    decoration: const BoxDecoration(
                      color: Colors.green,
                      borderRadius: BorderRadius.only(topLeft: Radius.circular(30), bottomLeft: Radius.circular(30)),
                    ),
                  ),
                ),
                Flexible(
                  flex: 100 - percent,
                  child: Container(
                    decoration: BoxDecoration(
                      color: Colors.grey[300],
                      borderRadius: BorderRadius.only(topRight: Radius.circular(30), bottomRight: Radius.circular(30)),
                    ),
                  ),
                ),
              ],
            ),
          ),
          Container(
            decoration: const BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.all(Radius.circular(30)),
            ),
            margin: const EdgeInsets.all(8),
            padding: const EdgeInsets.fromLTRB(25, 13, 25, 13),
            child: Text('${percent}% Complete'),
          )
        ],
      ),
    );
  }
  • Related