Skip to content

Instantly share code, notes, and snippets.

@enginebai
Created June 22, 2021 12:52
Show Gist options
  • Save enginebai/f111f6ec918069efb9f36638b58063b3 to your computer and use it in GitHub Desktop.
Save enginebai/f111f6ec918069efb9f36638b58063b3 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
const _labelHeight = 24.0;
const _cornerSize = 4.0;
const _textSize = 14.0;
const _strokeWidth = 2.0;
class Label extends StatelessWidget {
Label.text(
{Key? key,
required this.labelText,
this.textColor = Colors.black,
this.textSize = _textSize})
: assert(labelText.isNotEmpty),
this.backgroundColor = Colors.transparent,
this.strokeColor = Colors.transparent,
this.strokeWidth = 0.0,
super(key: key);
Label.stroke(
{Key? key,
required this.labelText,
this.textColor = Colors.black,
this.textSize = _textSize,
this.strokeColor = Colors.black,
this.strokeWidth = _strokeWidth})
: assert(labelText.isNotEmpty),
this.backgroundColor = Colors.transparent,
super(key: key);
Label.filled(
{Key? key,
required this.labelText,
this.backgroundColor = Colors.black,
this.textColor = Colors.white,
this.textSize = _textSize})
: assert(labelText.isNotEmpty),
this.strokeColor = Colors.transparent,
this.strokeWidth = 0.0,
super(key: key);
final String labelText;
final Color? textColor;
final double textSize;
final Color? backgroundColor;
final Color? strokeColor;
final double strokeWidth;
@override
Widget build(BuildContext context) {
return Container(
height: _labelHeight,
decoration: BoxDecoration(
border: Border.all(
color: this.strokeColor ?? Colors.transparent,
width: strokeWidth),
borderRadius: BorderRadius.circular(_cornerSize),
color: this.backgroundColor ?? Colors.transparent),
padding: EdgeInsets.symmetric(horizontal: 8),
child: Center(
child: Text(this.labelText,
style: Theme.of(context)
.textTheme
.caption
?.copyWith(color: this.textColor ?? Colors.black)),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment