Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samuelematias/5b3465148a3244fd8f95b5d479f60a9b to your computer and use it in GitHub Desktop.
Save samuelematias/5b3465148a3244fd8f95b5d479f60a9b to your computer and use it in GitHub Desktop.
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