Skip to content

Commit

Permalink
modernize README code snippets (#429)
Browse files Browse the repository at this point in the history
  • Loading branch information
nate-thegrate authored May 30, 2024
1 parent d53783b commit 2c7a59e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 30 deletions.
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@ logic of say `initState` or `dispose`. An obvious example is `AnimationControlle

```dart
class Example extends StatefulWidget {
final Duration duration;
const Example({super.key, required this.duration});
const Example({Key? key, required this.duration})
: super(key: key);
final Duration duration;
@override
_ExampleState createState() => _ExampleState();
}
class _ExampleState extends State<Example> with SingleTickerProviderStateMixin {
AnimationController? _controller;
late final AnimationController _controller;
@override
void initState() {
Expand All @@ -41,13 +40,13 @@ class _ExampleState extends State<Example> with SingleTickerProviderStateMixin {
void didUpdateWidget(Example oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.duration != oldWidget.duration) {
_controller!.duration = widget.duration;
_controller.duration = widget.duration;
}
}
@override
void dispose() {
_controller!.dispose();
_controller.dispose();
super.dispose();
}
Expand All @@ -74,8 +73,7 @@ This library proposes a third solution:

```dart
class Example extends HookWidget {
const Example({Key? key, required this.duration})
: super(key: key);
const Example({super.key, required this.duration});
final Duration duration;
Expand Down
14 changes: 6 additions & 8 deletions packages/flutter_hooks/resources/translations/ko_kr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@

```dart
class Example extends StatefulWidget {
final Duration duration;
const Example({super.key, required this.duration});
const Example({Key? key, required this.duration})
: super(key: key);
final Duration duration;
@override
_ExampleState createState() => _ExampleState();
}
class _ExampleState extends State<Example> with SingleTickerProviderStateMixin {
AnimationController? _controller;
late final AnimationController _controller;
@override
void initState() {
Expand All @@ -39,13 +38,13 @@ class _ExampleState extends State<Example> with SingleTickerProviderStateMixin {
void didUpdateWidget(Example oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.duration != oldWidget.duration) {
_controller!.duration = widget.duration;
_controller.duration = widget.duration;
}
}
@override
void dispose() {
_controller!.dispose();
_controller.dispose();
super.dispose();
}
Expand All @@ -70,8 +69,7 @@ Dart Mixins 으로 이 문제를 해결할 수 있지만, 다른 문제점들이

```dart
class Example extends HookWidget {
const Example({Key? key, required this.duration})
: super(key: key);
const Example({super.key, required this.duration});
final Duration duration;
Expand Down
12 changes: 4 additions & 8 deletions packages/flutter_hooks/resources/translations/pt_br/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ por exemplo de um `initState` ou `dispose`. Um exemplo é o `AnimationController

```dart
class Example extends StatefulWidget {
final Duration duration;
const Example({super.key, required this.duration});
const Example({Key? key, @required this.duration})
: assert(duration != null),
super(key: key);
final Duration duration;
@override
_ExampleState createState() => _ExampleState();
}
class _ExampleState extends State<Example> with SingleTickerProviderStateMixin {
AnimationController _controller;
late final AnimationController _controller;
@override
void initState() {
Expand Down Expand Up @@ -76,9 +74,7 @@ Essa biblioteca propõe uma terceira solução:

```dart
class Example extends HookWidget {
const Example({Key? key, @required this.duration})
: assert(duration != null),
super(key: key);
const Example({super.key, required this.duration});
final Duration duration;
Expand Down
11 changes: 5 additions & 6 deletions packages/flutter_hooks/resources/translations/zh_cn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@

```dart
class Example extends StatefulWidget {
final Duration duration;
const Example({super.key, required this.duration});
const Example({Key? key, required this.duration})
: super(key: key);
final Duration duration;
@override
_ExampleState createState() => _ExampleState();
}
class _ExampleState extends State<Example> with SingleTickerProviderStateMixin {
AnimationController? _controller;
late final AnimationController _controller;
@override
void initState() {
Expand All @@ -42,13 +41,13 @@ class _ExampleState extends State<Example> with SingleTickerProviderStateMixin {
void didUpdateWidget(Example oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.duration != oldWidget.duration) {
_controller!.duration = widget.duration;
_controller.duration = widget.duration;
}
}
@override
void dispose() {
_controller!.dispose();
_controller.dispose();
super.dispose();
}
Expand Down

0 comments on commit 2c7a59e

Please sign in to comment.