Skip to content

Instantly share code, notes, and snippets.

@AyeshaIftikhar
Created September 12, 2021 15:51
Show Gist options
  • Save AyeshaIftikhar/372002f14887679b2c62b6a8f07f40ee to your computer and use it in GitHub Desktop.
Save AyeshaIftikhar/372002f14887679b2c62b6a8f07f40ee to your computer and use it in GitHub Desktop.
Reusable Text Widget in Flutter

Text Widget

class CustomText extends StatelessWidget {
  const CustomText({
    Key? key,
    required this.text,
    this.size = 14,
    this.font = 'Poppins',
    this.weight = FontWeight.normal,
    this.textAlign = TextAlign.left,
    this.fontStyle = FontStyle.normal,
    this.alignment = Alignment.topLeft,
    this.color = Colors.black,
  }) : super(key: key);

  final String font;
  final String text;
  final double size;
  final Color color;
  final FontWeight weight;
  final TextAlign textAlign;
  final Alignment alignment;
  final FontStyle fontStyle;

  @override
  Widget build(BuildContext context) {
    return Align(
      alignment: alignment,
      child: Text(
        text,
        textAlign: textAlign,
        style: TextStyle(
          color: color,
          fontSize: size,
          fontFamily: font,
          fontWeight: weight,
          fontStyle: fontStyle,
        ),
      ),
    );
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment