Created
February 3, 2022 11:58
-
-
Save misterfourtytwo/6649c14fe7585bffcedf0d58dc51ecf8 to your computer and use it in GitHub Desktop.
add border to progressbar around its content
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
const Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark().copyWith( | |
scaffoldBackgroundColor: darkBlue, | |
), | |
debugShowCheckedModeBanner: false, | |
home: MyHome(), | |
); | |
} | |
} | |
class MyHome extends StatelessWidget { | |
List<Widget> get contentWidgets => [ | |
Container( | |
height: 40, | |
width: 180, | |
color: Colors.green, | |
child: const FittedBox( | |
child: Text( | |
'60%', | |
textAlign: TextAlign.center, | |
style: TextStyle( | |
color: Colors.white, | |
), | |
), | |
), | |
), | |
Container( | |
height: 40, | |
width: 90, | |
color: Colors.blue, | |
child: const FittedBox( | |
child: Text( | |
'30%', | |
textAlign: TextAlign.center, | |
style: TextStyle( | |
color: Colors.white, | |
), | |
), | |
), | |
), | |
Container( | |
height: 40, | |
width: 30, | |
color: Colors.red, | |
child: const FittedBox( | |
child: Text( | |
'10%', | |
textAlign: TextAlign.center, | |
style: TextStyle( | |
color: Colors.white, | |
), | |
), | |
), | |
), | |
]; | |
double get borderWidth => 2; | |
double get radius => 8; | |
BorderRadius get borderRadius => BorderRadius.circular(radius); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Center( | |
child: DecoratedBox( | |
decoration: BoxDecoration( | |
borderRadius: borderRadius, | |
color: Colors.amber, | |
), | |
child: Padding( | |
padding: EdgeInsets.all(borderWidth), | |
child: ClipRRect( | |
borderRadius: borderRadius, | |
child: Row( | |
mainAxisSize: MainAxisSize.min, | |
children: contentWidgets, | |
), | |
), | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment