From 039dbf94fe1f13c7cd81e976863c06018e30958e Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Tue, 24 Mar 2020 20:44:53 +0100 Subject: [PATCH] Child argument is now optional --- example/lib/basic_example.dart | 4 ++-- example/lib/namespace_example.dart | 2 +- example/lib/network_example.dart | 2 +- lib/widgets/I18nPlural.dart | 10 ++++++---- lib/widgets/I18nText.dart | 13 +++++++------ test/test_widget.dart | 6 +++--- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/example/lib/basic_example.dart b/example/lib/basic_example.dart index 56eb4be..95a0eec 100644 --- a/example/lib/basic_example.dart +++ b/example/lib/basic_example.dart @@ -82,9 +82,9 @@ class MyHomeState extends State { child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - I18nText("label.main", Text(""), + I18nText("label.main", translationParams: {"user": "Flutter lover"}), - I18nPlural("clicked.times", clicked, Text("")), + I18nPlural("clicked.times", clicked), FlatButton( onPressed: () async { incrementCounter(); diff --git a/example/lib/namespace_example.dart b/example/lib/namespace_example.dart index 6343c90..8148035 100644 --- a/example/lib/namespace_example.dart +++ b/example/lib/namespace_example.dart @@ -64,7 +64,7 @@ class MyHomeState extends State { child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - I18nText("home.label.main", Text("")), + I18nText("home.label.main", child: Text("")), RaisedButton( onPressed: () async { await changeLanguage(); diff --git a/example/lib/network_example.dart b/example/lib/network_example.dart index 6b52216..1183488 100644 --- a/example/lib/network_example.dart +++ b/example/lib/network_example.dart @@ -60,7 +60,7 @@ class MyHomePage extends StatelessWidget { children: [ I18nText( "args.content", - Text(""), + child: Text(""), ), ], ), diff --git a/lib/widgets/I18nPlural.dart b/lib/widgets/I18nPlural.dart index 01bf4a5..5965ab0 100644 --- a/lib/widgets/I18nPlural.dart +++ b/lib/widgets/I18nPlural.dart @@ -2,11 +2,13 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_i18n/flutter_i18n.dart'; class I18nPlural extends StatelessWidget { - final String _key; - final Text _child; - final int _pluralValue; + String _key; + Text _child; + int _pluralValue; - const I18nPlural(this._key, this._pluralValue, this._child); + I18nPlural(this._key, this._pluralValue, {child}) { + this._child = child ?? Text(""); + } @override Widget build(BuildContext context) { diff --git a/lib/widgets/I18nText.dart b/lib/widgets/I18nText.dart index fabb60c..16e22dd 100644 --- a/lib/widgets/I18nText.dart +++ b/lib/widgets/I18nText.dart @@ -2,13 +2,14 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_i18n/flutter_i18n.dart'; class I18nText extends StatelessWidget { - final String _key; - final Text _child; - final String fallbackKey; - final Map translationParams; + String _key; + Text _child; + String fallbackKey; + Map translationParams; - const I18nText(this._key, this._child, - {this.fallbackKey, this.translationParams}); + I18nText(this._key, {child, this.fallbackKey, this.translationParams}) { + this._child = child ?? Text(""); + } @override Widget build(BuildContext context) { diff --git a/test/test_widget.dart b/test/test_widget.dart index df7a3ee..3a4e886 100644 --- a/test/test_widget.dart +++ b/test/test_widget.dart @@ -42,9 +42,9 @@ class TestWidgetPageState extends State { return Center( child: Column( children: [ - I18nText("keySingle", Text("")), - I18nPlural("keyPlural", 1, Text("")), - I18nPlural("keyPlural", 2, Text("")), + I18nText("keySingle"), + I18nPlural("keyPlural", 1, child: Text("")), + I18nPlural("keyPlural", 2), RaisedButton( onPressed: () async { var locale = FlutterI18n.currentLocale(context);