Normalize examples (#111223)

This commit is contained in:
Greg Spencer
2022-09-09 14:17:11 -07:00
committed by GitHub
parent d63442c1da
commit e617d003fb
370 changed files with 991 additions and 924 deletions

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for SharedAppData
/// Flutter code sample for [SharedAppData].
import 'package:flutter/material.dart';
@@ -13,16 +13,16 @@ class ShowSharedValue extends StatelessWidget {
@override
Widget build(BuildContext context) {
// The SharedAppData.getValue() call here causes this widget to depend
// on the value of the SharedAppData's 'foo' key. If it's changed, with
// The SharedAppData.getValue() call causes this widget to depend on the
// value of the SharedAppData's 'foo' key. If it's changed, with
// SharedAppData.setValue(), then this widget will be rebuilt.
final String value = SharedAppData.getValue<String, String>(context, appDataKey, () => 'initial');
return Text('$appDataKey: $value');
}
}
// Demonstrates that changes to the SharedAppData _only_ cause the dependent widgets
// to be rebuilt. In this case that's the ShowSharedValue widget that's
// Demonstrates that changes to the SharedAppData _only_ cause the dependent
// widgets to be rebuilt. In this case that's the ShowSharedValue widget that's
// displaying the value of a key whose value has been updated.
class Home extends StatefulWidget {
const Home({ super.key });
@@ -50,8 +50,8 @@ class _HomeState extends State<Home> {
child: const Text('change foo'),
onPressed: () {
_fooVersion += 1;
// Changing the SharedAppData's value for 'foo' causes the widgets that
// depend on 'foo' to be rebuilt.
// Changing the SharedAppData's value for 'foo' causes the
// widgets that depend on 'foo' to be rebuilt.
SharedAppData.setValue<String, String?>(context, 'foo', 'FOO $_fooVersion'); // note: no setState()
},
),

View File

@@ -2,15 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for SharedAppData
/// Flutter code sample for [SharedAppData].
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
// A single lazily constructed object that's shared with the entire
// application via `SharedObject.of(context)`. The value of the object
// can be changed with `SharedObject.reset(context)`. Resetting the value
// will cause all of the widgets that depend on it to be rebuilt.
// A single lazily-constructed object that's shared with the entire application
// via `SharedObject.of(context)`. The value of the object can be changed with
// `SharedObject.reset(context)`. Resetting the value will cause all of the
// widgets that depend on it to be rebuilt.
class SharedObject {
SharedObject._();
@@ -31,8 +31,8 @@ class SharedObject {
}
}
// An example of a widget which depends on the SharedObject's value,
// which might be provided - along with SharedObject - in a Dart package.
// An example of a widget which depends on the SharedObject's value, which might
// be provided - along with SharedObject - in a Dart package.
class CustomWidget extends StatelessWidget {
const CustomWidget({ super.key });