From 3294ce09ebfb6a9726d1120266a7fd48b493ea8d Mon Sep 17 00:00:00 2001 From: iLTeoooD Date: Fri, 24 Apr 2020 21:33:41 +0200 Subject: [PATCH] Fix immutable warning --- lib/widgets/I18nPlural.dart | 33 ++++++++++++++++----------------- lib/widgets/I18nText.dart | 36 ++++++++++++++++++------------------ 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/lib/widgets/I18nPlural.dart b/lib/widgets/I18nPlural.dart index 5965ab0..9f42a6c 100644 --- a/lib/widgets/I18nPlural.dart +++ b/lib/widgets/I18nPlural.dart @@ -2,29 +2,28 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_i18n/flutter_i18n.dart'; class I18nPlural extends StatelessWidget { - String _key; - Text _child; - int _pluralValue; + final String _key; + final int _pluralValue; + final Text child; + static const _default_text = Text(""); - I18nPlural(this._key, this._pluralValue, {child}) { - this._child = child ?? Text(""); - } + I18nPlural(this._key, this._pluralValue, {this.child = _default_text}); @override Widget build(BuildContext context) { return Text( FlutterI18n.plural(context, _key, _pluralValue), - key: _child.key, - style: _child.style, - strutStyle: _child.strutStyle, - textAlign: _child.textAlign, - textDirection: _child.textDirection, - softWrap: _child.softWrap, - overflow: _child.overflow, - textScaleFactor: _child.textScaleFactor, - maxLines: _child.maxLines, - semanticsLabel: _child.semanticsLabel, - textWidthBasis: _child.textWidthBasis, + key: child.key, + style: child.style, + strutStyle: child.strutStyle, + textAlign: child.textAlign, + textDirection: child.textDirection, + softWrap: child.softWrap, + overflow: child.overflow, + textScaleFactor: child.textScaleFactor, + maxLines: child.maxLines, + semanticsLabel: child.semanticsLabel, + textWidthBasis: child.textWidthBasis, ); } } diff --git a/lib/widgets/I18nText.dart b/lib/widgets/I18nText.dart index 16e22dd..830c4f3 100644 --- a/lib/widgets/I18nText.dart +++ b/lib/widgets/I18nText.dart @@ -2,31 +2,31 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_i18n/flutter_i18n.dart'; class I18nText extends StatelessWidget { - String _key; - Text _child; - String fallbackKey; - Map translationParams; + final String _key; + final Text child; + final String fallbackKey; + final Map translationParams; + static const _default_text = Text(""); - I18nText(this._key, {child, this.fallbackKey, this.translationParams}) { - this._child = child ?? Text(""); - } + I18nText(this._key, + {this.child = _default_text, this.fallbackKey, this.translationParams}); @override Widget build(BuildContext context) { return Text( FlutterI18n.translate(context, _key, fallbackKey: fallbackKey, translationParams: translationParams), - key: _child.key, - style: _child.style, - strutStyle: _child.strutStyle, - textAlign: _child.textAlign, - textDirection: _child.textDirection, - softWrap: _child.softWrap, - overflow: _child.overflow, - textScaleFactor: _child.textScaleFactor, - maxLines: _child.maxLines, - semanticsLabel: _child.semanticsLabel, - textWidthBasis: _child.textWidthBasis, + key: child.key, + style: child.style, + strutStyle: child.strutStyle, + textAlign: child.textAlign, + textDirection: child.textDirection, + softWrap: child.softWrap, + overflow: child.overflow, + textScaleFactor: child.textScaleFactor, + maxLines: child.maxLines, + semanticsLabel: child.semanticsLabel, + textWidthBasis: child.textWidthBasis, ); } }