From e3ef0881ad0b90925ef6980e32493a4b8eebbd3e Mon Sep 17 00:00:00 2001 From: Anders Cheow Date: Tue, 9 Jan 2024 14:08:16 +0800 Subject: [PATCH] Fixed missing material 3 text theme naming on VxText --- lib/src/flutter/rich_text.dart | 61 ++++++++++++----------- lib/src/flutter/text.dart | 91 +++++++++++++++++++--------------- lib/src/flutter/toast.dart | 11 ++-- 3 files changed, 88 insertions(+), 75 deletions(-) diff --git a/lib/src/flutter/rich_text.dart b/lib/src/flutter/rich_text.dart index 9faa298..70a4c30 100644 --- a/lib/src/flutter/rich_text.dart +++ b/lib/src/flutter/rich_text.dart @@ -14,6 +14,7 @@ import 'package:auto_size_text_pk/auto_size_text_pk.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; +import 'package:velocity_x/src/extensions/context_ext.dart'; import 'package:velocity_x/src/extensions/string_ext.dart'; import 'package:velocity_x/src/flutter/builder.dart'; import 'package:velocity_x/src/flutter/velocityx_mixins/color_mixin.dart'; @@ -208,91 +209,91 @@ class VxRichText extends VxWidgetBuilder /// Sets [TextTheme] display large VxRichText displayLarge(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.displayLarge; + _themedStyle = context.textTheme.displayLarge; return this; } /// Sets [TextTheme] display medium VxRichText displayMedium(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.displayMedium; + _themedStyle = context.textTheme.displayMedium; return this; } /// Sets [TextTheme] display small VxRichText displaySmall(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.displaySmall; + _themedStyle = context.textTheme.displaySmall; return this; } /// Sets [TextTheme] headline large VxRichText headlineLarge(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.headlineLarge; + _themedStyle = context.textTheme.headlineLarge; return this; } /// Sets [TextTheme] headline medium VxRichText headlineMedium(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.headlineMedium; + _themedStyle = context.textTheme.headlineMedium; return this; } /// Sets [TextTheme] headline small VxRichText headlineSmall(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.headlineSmall; + _themedStyle = context.textTheme.headlineSmall; return this; } /// Sets [TextTheme] title large VxRichText titleLarge(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.titleLarge; + _themedStyle = context.textTheme.titleLarge; return this; } /// Sets [TextTheme] title medium VxRichText titleMedium(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.titleMedium; + _themedStyle = context.textTheme.titleMedium; return this; } /// Sets [TextTheme] title small VxRichText titleSmall(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.titleSmall; + _themedStyle = context.textTheme.titleSmall; return this; } /// Sets [TextTheme] body large VxRichText bodyLarge(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.bodyLarge; + _themedStyle = context.textTheme.bodyLarge; return this; } /// Sets [TextTheme] body medium VxRichText bodyMedium(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.bodyMedium; + _themedStyle = context.textTheme.bodyMedium; return this; } /// Sets [TextTheme] body small VxRichText bodySmall(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.bodySmall; + _themedStyle = context.textTheme.bodySmall; return this; } /// Sets [TextTheme] label large VxRichText labelLarge(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.labelLarge; + _themedStyle = context.textTheme.labelLarge; return this; } /// Sets [TextTheme] label medium VxRichText labelMedium(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.labelMedium; + _themedStyle = context.textTheme.labelMedium; return this; } /// Sets [TextTheme] label small VxRichText labelSmall(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.labelSmall; + _themedStyle = context.textTheme.labelSmall; return this; } @@ -576,91 +577,91 @@ class VelocityXTextSpan extends VxTextSpanBuilder /// Sets [TextTheme] display large VelocityXTextSpan displayLarge(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.displayLarge; + _themedStyle = context.textTheme.displayLarge; return this; } /// Sets [TextTheme] display medium VelocityXTextSpan displayMedium(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.displayMedium; + _themedStyle = context.textTheme.displayMedium; return this; } /// Sets [TextTheme] display small VelocityXTextSpan displaySmall(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.displaySmall; + _themedStyle = context.textTheme.displaySmall; return this; } /// Sets [TextTheme] headline large VelocityXTextSpan headlineLarge(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.headlineLarge; + _themedStyle = context.textTheme.headlineLarge; return this; } /// Sets [TextTheme] headline medium VelocityXTextSpan headlineMedium(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.headlineMedium; + _themedStyle = context.textTheme.headlineMedium; return this; } /// Sets [TextTheme] headline small VelocityXTextSpan headlineSmall(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.headlineSmall; + _themedStyle = context.textTheme.headlineSmall; return this; } /// Sets [TextTheme] title large VelocityXTextSpan titleLarge(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.titleLarge; + _themedStyle = context.textTheme.titleLarge; return this; } /// Sets [TextTheme] title medium VelocityXTextSpan titleMedium(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.titleMedium; + _themedStyle = context.textTheme.titleMedium; return this; } /// Sets [TextTheme] title small VelocityXTextSpan titleSmall(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.titleSmall; + _themedStyle = context.textTheme.titleSmall; return this; } /// Sets [TextTheme] body large VelocityXTextSpan bodyLarge(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.bodyLarge; + _themedStyle = context.textTheme.bodyLarge; return this; } /// Sets [TextTheme] body medium VelocityXTextSpan bodyMedium(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.bodyMedium; + _themedStyle = context.textTheme.bodyMedium; return this; } /// Sets [TextTheme] body small VelocityXTextSpan bodySmall(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.bodySmall; + _themedStyle = context.textTheme.bodySmall; return this; } /// Sets [TextTheme] label large VelocityXTextSpan labelLarge(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.labelLarge; + _themedStyle = context.textTheme.labelLarge; return this; } /// Sets [TextTheme] label medium VelocityXTextSpan labelMedium(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.labelMedium; + _themedStyle = context.textTheme.labelMedium; return this; } /// Sets [TextTheme] label small VelocityXTextSpan labelSmall(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.labelSmall; + _themedStyle = context.textTheme.labelSmall; return this; } diff --git a/lib/src/flutter/text.dart b/lib/src/flutter/text.dart index 01dc31a..274d5ee 100644 --- a/lib/src/flutter/text.dart +++ b/lib/src/flutter/text.dart @@ -13,6 +13,7 @@ import 'package:auto_size_text_pk/auto_size_text_pk.dart'; import 'package:flutter/material.dart'; +import 'package:velocity_x/src/extensions/context_ext.dart'; import 'package:velocity_x/src/extensions/string_ext.dart'; import 'package:velocity_x/src/flutter/velocityx_mixins/render_mixin.dart'; import 'package:velocity_x/src/velocity_xx.dart'; @@ -248,81 +249,93 @@ class VxTextBuilder extends VxWidgetBuilder /// To set fontSize of the text using [size] VxTextBuilder size(double? size) => this.._fontSize = size; - /// Sets [TextTheme] headline 1 - VxTextBuilder headline1(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.displayLarge; + /// Sets [TextTheme] display large + VxTextBuilder displayLarge(BuildContext context) { + _themedStyle = context.textTheme.displayLarge; return this; } - /// Sets [TextTheme] headline 2 - VxTextBuilder headline2(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.displayMedium; + /// Sets [TextTheme] display medium + VxTextBuilder displayMedium(BuildContext context) { + _themedStyle = context.textTheme.displayMedium; return this; } - /// Sets [TextTheme] headline 3 - VxTextBuilder headline3(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.displaySmall; + /// Sets [TextTheme] display small + VxTextBuilder displaySmall(BuildContext context) { + _themedStyle = context.textTheme.displaySmall; return this; } - /// Sets [TextTheme] headline 4 - VxTextBuilder headline4(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.headlineMedium; + /// Sets [TextTheme] headline large + VxTextBuilder headlineLarge(BuildContext context) { + _themedStyle = context.textTheme.headlineLarge; return this; } - /// Sets [TextTheme] headline 5 - VxTextBuilder headline5(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.headlineSmall; + /// Sets [TextTheme] headline medium + VxTextBuilder headlineMedium(BuildContext context) { + _themedStyle = context.textTheme.headlineMedium; return this; } - /// Sets [TextTheme] headline 6 - VxTextBuilder headline6(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.titleLarge; + /// Sets [TextTheme] headline small + VxTextBuilder headlineSmall(BuildContext context) { + _themedStyle = context.textTheme.headlineSmall; return this; } - /// Sets [TextTheme] bodyText1 - VxTextBuilder bodyText1(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.bodyLarge; + /// Sets [TextTheme] title large + VxTextBuilder titleLarge(BuildContext context) { + _themedStyle = context.textTheme.titleLarge; return this; } - /// Sets [TextTheme] bodyText2 - VxTextBuilder bodyText2(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.bodyMedium; + /// Sets [TextTheme] title medium + VxTextBuilder titleMedium(BuildContext context) { + _themedStyle = context.textTheme.titleMedium; return this; } - /// Sets [TextTheme] caption - VxTextBuilder caption(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.bodySmall; + /// Sets [TextTheme] title small + VxTextBuilder titleSmall(BuildContext context) { + _themedStyle = context.textTheme.titleSmall; return this; } - /// Sets [TextTheme] subtitle1 - VxTextBuilder subtitle1(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.titleMedium; + /// Sets [TextTheme] body large + VxTextBuilder bodyLarge(BuildContext context) { + _themedStyle = context.textTheme.bodyLarge; return this; } - /// Sets [TextTheme] subtitle2 - VxTextBuilder subtitle2(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.titleSmall; + /// Sets [TextTheme] body medium + VxTextBuilder bodyMedium(BuildContext context) { + _themedStyle = context.textTheme.bodyMedium; return this; } - /// Sets [TextTheme] overline - VxTextBuilder overlineText(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.labelSmall; + /// Sets [TextTheme] body small + VxTextBuilder bodySmall(BuildContext context) { + _themedStyle = context.textTheme.bodySmall; return this; } - /// Sets [TextTheme] button - VxTextBuilder buttonText(BuildContext context) { - _themedStyle = Theme.of(context).textTheme.labelLarge; + /// Sets [TextTheme] label large + VxTextBuilder labelLarge(BuildContext context) { + _themedStyle = context.textTheme.labelLarge; + return this; + } + + /// Sets [TextTheme] label medium + VxTextBuilder labelMedium(BuildContext context) { + _themedStyle = context.textTheme.labelMedium; + return this; + } + + /// Sets [TextTheme] label small + VxTextBuilder labelSmall(BuildContext context) { + _themedStyle = context.textTheme.labelSmall; return this; } diff --git a/lib/src/flutter/toast.dart b/lib/src/flutter/toast.dart index a3abadf..4f860f2 100644 --- a/lib/src/flutter/toast.dart +++ b/lib/src/flutter/toast.dart @@ -15,6 +15,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; +import 'package:velocity_x/src/extensions/context_ext.dart'; /// Toast position enum VxToastPosition { @@ -218,8 +219,7 @@ class _VxToastViewState extends State<_VxToastView> widget.msg!, style: TextStyle( fontSize: widget.textSize, - color: widget.textColor ?? - Theme.of(context).textTheme.bodyLarge!.color, + color: widget.textColor ?? context.textTheme.bodyLarge!.color, ), ), ), @@ -228,8 +228,7 @@ class _VxToastViewState extends State<_VxToastView> } else if (widget.type == VxToastType.loading) { return Center( child: Card( - color: - widget.bgColor ?? Theme.of(context).textTheme.titleLarge!.color, + color: widget.bgColor ?? context.textTheme.titleLarge!.color, child: Padding( padding: EdgeInsets.symmetric( horizontal: widget.pdHorizontal!, @@ -250,8 +249,8 @@ class _VxToastViewState extends State<_VxToastView> widget.msg!, style: TextStyle( fontSize: widget.textSize, - color: widget.textColor ?? - Theme.of(context).textTheme.bodyLarge!.color, + color: + widget.textColor ?? context.textTheme.bodyLarge!.color, ), ) ],