Skip to content

Commit

Permalink
Child argument is now optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Matteo Pietro Dazzi committed Mar 24, 2020
1 parent 6c06f9b commit 039dbf9
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
4 changes: 2 additions & 2 deletions example/lib/basic_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ class MyHomeState extends State<MyHomePage> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
I18nText("label.main", Text(""),
I18nText("label.main",
translationParams: {"user": "Flutter lover"}),
I18nPlural("clicked.times", clicked, Text("")),
I18nPlural("clicked.times", clicked),
FlatButton(
onPressed: () async {
incrementCounter();
Expand Down
2 changes: 1 addition & 1 deletion example/lib/namespace_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class MyHomeState extends State<MyHomePage> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
I18nText("home.label.main", Text("")),
I18nText("home.label.main", child: Text("")),
RaisedButton(
onPressed: () async {
await changeLanguage();
Expand Down
2 changes: 1 addition & 1 deletion example/lib/network_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class MyHomePage extends StatelessWidget {
children: <Widget>[
I18nText(
"args.content",
Text(""),
child: Text(""),
),
],
),
Expand Down
10 changes: 6 additions & 4 deletions lib/widgets/I18nPlural.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 7 additions & 6 deletions lib/widgets/I18nText.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> translationParams;
String _key;
Text _child;
String fallbackKey;
Map<String, String> 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) {
Expand Down
6 changes: 3 additions & 3 deletions test/test_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class TestWidgetPageState extends State<TestWidgetPage> {
return Center(
child: Column(
children: <Widget>[
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);
Expand Down

0 comments on commit 039dbf9

Please sign in to comment.