Created
February 23, 2020 04:15
-
-
Save faustobdls/f9b31c1962e10d9e76b296c2cb08b8ac to your computer and use it in GitHub Desktop.
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'; | |
class NameInitialsWidget extends StatelessWidget { | |
final double width; | |
final double height; | |
final String text; | |
final double fontSize; | |
final double margin; | |
const NameInitialsWidget( | |
{Key key, | |
this.width = 50, | |
this.height = 50, | |
@required this.text, | |
this.fontSize = 22, | |
this.margin = 8}) | |
: super(key: key); | |
_getInitials() { | |
return this | |
.text | |
.split(" ").where((t) => t.isEmpty ? false : true) | |
.map((nome) { | |
return nome.isEmpty ? " " : nome.substring(0, 1).toUpperCase(); | |
}) | |
.join() | |
.substring(0, (this.text.split(" ").length < 2) ? 1 : 2) | |
.trim(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
width: this.width, | |
height: this.height, | |
alignment: Alignment.center, | |
margin: this.margin != null ? EdgeInsets.all(this.margin) : null, | |
decoration: BoxDecoration( | |
color: Theme.of(context).primaryColor, | |
borderRadius: BorderRadius.circular(200), | |
), | |
child: Text( | |
_getInitials(), | |
textAlign: TextAlign.center, | |
style: Theme.of(context).textTheme.title.copyWith( | |
color: Theme.of(context).accentColor, fontSize: this.fontSize), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment