Created
July 26, 2020 03:07
-
-
Save dhruvilp/c6825675c6f01f41f0d844c6554624c1 to your computer and use it in GitHub Desktop.
Persona Widget
This file contains 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'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
backgroundColor: Colors.white, | |
body: Center( | |
child: Persona( | |
size: 6.0, | |
statusColor: Colors.green, | |
statusIcon: Icons.check, | |
child: Icon( | |
Icons.person, | |
size: 110.0, | |
color: Colors.blue.shade400, | |
), | |
), | |
), | |
), | |
); | |
} | |
} | |
class Persona extends StatelessWidget { | |
final double size; | |
final Color statusColor; | |
final IconData statusIcon; | |
final Widget child; | |
const Persona({ | |
Key key, | |
this.size, | |
this.statusColor, | |
this.statusIcon, | |
this.child, | |
}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
width: size * 15.0, | |
height: size * 15.0, | |
decoration: BoxDecoration( | |
color: Colors.blue.shade100, | |
shape: BoxShape.circle, | |
), | |
child: Stack( | |
children: <Widget>[ | |
Center( | |
child: Padding( | |
padding: const EdgeInsets.all(8.0), | |
child: FittedBox( | |
child: child, | |
), | |
), | |
), | |
Align( | |
alignment: const Alignment(1.0, 1.0), | |
child: Container( | |
width: size * 5.5, | |
height: size * 3.5, | |
child: OverflowBox( | |
minWidth: 0.0, | |
maxWidth: size * 10.0, | |
minHeight: 0.0, | |
maxHeight: size * 5.0, | |
child: Container( | |
width: size < 6.0 ? size * 5.0 : size * 4.5, | |
decoration: BoxDecoration( | |
color: statusColor, | |
shape: BoxShape.circle, | |
border: Border.all(width: size * 0.4, color: Colors.white), | |
), | |
child: Center( | |
child: Icon(statusIcon, size: size * 3.0, color: Colors.white) ?? | |
Container(), | |
), | |
), | |
), | |
), | |
), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment