Overview
========
This patch refactors images to achieve the following goals:
* it allows references to unresolved assets to be passed
around (previously, almost every layer of the system had to know about
whether an image came from an asset bundle or the network or
elsewhere, and had to manually interact with the image cache).
* it allows decorations to use the same API for declaring images as the
widget tree.
It requires some minor changes to call sites that use images, as
discussed below.
Widgets
-------
Change this:
```dart
child: new AssetImage(
name: 'my_asset.png',
...
)
```
...to this:
```dart
child: new Image(
image: new AssetImage('my_asset.png'),
...
)
```
Decorations
-----------
Change this:
```dart
child: new DecoratedBox(
decoration: new BoxDecoration(
backgroundImage: new BackgroundImage(
image: DefaultAssetBundle.of(context).loadImage('my_asset.png'),
...
),
...
),
child: ...
)
```
...to this:
```dart
child: new DecoratedBox(
decoration: new BoxDecoration(
backgroundImage: new BackgroundImage(
image: new AssetImage('my_asset.png'),
...
),
...
),
child: ...
)
```
DETAILED CHANGE LOG
===================
The following APIs have been replaced in this patch:
* The `AssetImage` and `NetworkImage` widgets have been split in two,
with identically-named `ImageProvider` subclasses providing the
image-loading logic, and a single `Image` widget providing all the
widget tree logic.
* `ImageResource` is now `ImageStream`. Rather than configuring it with
a `Future<ImageInfo>`, you complete it with an `ImageStreamCompleter`.
* `ImageCache.load` and `ImageCache.loadProvider` are replaced by
`ImageCache.putIfAbsent`.
The following APIs have changed in this patch:
* `ImageCache` works in terms of arbitrary keys and caches
`ImageStreamCompleter` objects using those keys. With the new model,
you should never need to interact with the cache directly.
* `Decoration` can now be `const`. The state has moved to the
`BoxPainter` class. Instead of a list of listeners, there's now just a
single callback and a `dispose()` method on the painter. The callback
is passed in to the `createBoxPainter()` method. When invoked, you
should repaint the painter.
The following new APIs are introduced:
* `AssetBundle.loadStructuredData`.
* `SynchronousFuture`, a variant of `Future` that calls the `then`
callback synchronously. This enables the asynchronous and
synchronous (in-the-cache) code paths to look identical yet for the
latter to avoid returning to the event loop mid-paint.
* `ExactAssetImage`, a variant of `AssetImage` that doesn't do anything clever.
* `ImageConfiguration`, a class that describes parameters that configure
the `AssetImage` resolver.
The following APIs are entirely removed by this patch:
* `AssetBundle.loadImage` is gone. Use an `AssetImage` instead.
* `AssetVendor` is gone. `AssetImage` handles everything `AssetVendor`
used to handle.
* `RawImageResource` and `AsyncImage` are gone.
The following code-level changes are performed:
* `Image`, which replaces `AsyncImage`, `NetworkImage`, `AssetImage`,
and `RawResourceImage`, lives in `image.dart`.
* `DecoratedBox` and `Container` live in their own file now,
`container.dart` (they reference `image.dart`).
DIRECTIONS FOR FUTURE RESEARCH
==============================
* The `ImageConfiguration` fields are mostly aspirational. Right now
only `devicePixelRatio` and `bundle` are implemented. `locale` isn't
even plumbed through, it will require work on the localisation logic.
* We should go through and make `BoxDecoration`, `AssetImage`, and
`NetworkImage` objects `const` where possible.
* This patch makes supporting animated GIFs much easier.
* This patch makes it possible to create an abstract concept of an
"Icon" that could be either an image or a font-based glyph (using
`IconData` or similar). (see
https://github.com/flutter/flutter/issues/4494)
RELATED ISSUES
==============
Fixes https://github.com/flutter/flutter/issues/4500
Fixes https://github.com/flutter/flutter/issues/4495
Obsoletes https://github.com/flutter/flutter/issues/4496
We now use the `@required` annotation to encourage developers to
explicitly set onPressed and onChanged callbacks to null when that would
disable the widget.
Fixes#287
Previously we supplied individual parameters to the various drag and pan
callbacks. However, that approach isn't extensible because each new
parameter is a breaking change to the API.
This patch makes a one-time breaking change to the API to provide a
"details" object that we can extend over time as we need to expose more
information. The first planned extension is adding enough information to
accurately produce an overscroll glow on Android.
This makes it possible to substitute 'flutter run' for 'flutter test'
and actually watch a test run on a device.
For any test that depends on flutter_test:
1. Remove any import of 'package:test/test.dart'.
2. Replace `testWidgets('...', (WidgetTester tester) {`
with `testWidgets('...', (WidgetTester tester) async {`
3. Add an "await" in front of calls to any of the following:
* tap()
* tapAt()
* fling()
* flingFrom()
* scroll()
* scrollAt()
* pump()
* pumpWidget()
4. Replace any calls to `tester.flushMicrotasks()` with calls to
`await tester.idle()`.
There's a guarding API that you can use, if you have particularly
complicated tests, to get better error messages. Search for
TestAsyncUtils.
This reverts commit 55f9145ef4.
Turns out that this commit breaks apps that use the material library,
because of the _errorTextStyle DefaultTextStyle which has inherit:true.
Just setting it to false doesn't work, unfortunately, because then you
hit some sort of issue with merging that text style with others that
have inherit:true.
To make it clear that this constructor requires an explicit style. Also
throw a descriptive error recommending the inherit constructor for
styles with the inherit bit set.
Fixes#3842
TextAlign applies to a whole paragraph instead of applying to an individual
text span. This patch moves the property out of TextStyle and into a separate
property on Text and RichText.
Instead of incorporating the margin into the button, introduce a ButtonBar
widget that supplies the proper spacing between the buttons. Also, make these
buttons more configurable via ButtonTheme so that dialogs can change the
minWidth and padding of the buttons as required by the spec.
Fixes#1843Fixes#3184
* Refactor widget test framework
Instead of:
```dart
test("Card Collection smoke test", () {
testWidgets((WidgetTester tester) {
```
...you now say:
```dart
testWidgets("Card Collection smoke test", (WidgetTester tester) {
```
Instead of:
```dart
expect(tester, hasWidget(find.text('hello')));
```
...you now say:
```dart
expect(find.text('hello'), findsOneWidget);
```
Instead of the previous API (exists, widgets, widget, stateOf,
elementOf, etc), you now have the following comprehensive API. All these
are functions that take a Finder, except the all* properties.
* `any()` - true if anything matches, c.f. `Iterable.any`
* `allWidgets` - all the widgets in the tree
* `widget()` - the one and only widget that matches the finder
* `firstWidget()` - the first widget that matches the finder
* `allElements` - all the elements in the tree
* `element()` - the one and only element that matches the finder
* `firstElement()` - the first element that matches the finder
* `allStates` - all the `State`s in the tree
* `state()` - the one and only state that matches the finder
* `firstState()` - the first state that matches the finder
* `allRenderObjects` - all the render objects in the tree
* `renderObject()` - the one and only render object that matches the finder
* `firstRenderObject()` - the first render object that matches the finder
There's also `layers' which returns the list of current layers.
`tap`, `fling`, getCenter, getSize, etc, take Finders, like the APIs
above, and expect there to only be one matching widget.
The finders are:
* `find.text(String text)`
* `find.widgetWithText(Type widgetType, String text)`
* `find.byKey(Key key)`
* `find.byType(Type type)`
* `find.byElementType(Type type)`
* `find.byConfig(Widget config)`
* `find.byWidgetPredicate(WidgetPredicate predicate)`
* `find.byElementPredicate(ElementPredicate predicate)`
The matchers (for `expect`) are:
* `findsNothing`
* `findsWidgets`
* `findsOneWidget`
* `findsNWidgets(n)`
* `isOnStage`
* `isOffStage`
* `isInCard`
* `isNotInCard`
Benchmarks now use benchmarkWidgets instead of testWidgets.
Also, for those of you using mockers, `serviceMocker` now automatically
handles the binding initialization.
This patch also:
* changes how tests are run so that we can more easily swap the logic
out for a "real" mode instead of FakeAsync.
* introduces CachingIterable.
* changes how flutter_driver interacts with the widget tree to use the
aforementioned new API rather than ElementTreeTester, which is gone.
* removes ElementTreeTester.
* changes the semantics of a test for scrollables because we couldn't
convince ourselves that the old semantics made sense; it only worked
before because flushing the microtasks after every event was broken.
* fixes the flushing of microtasks after every event.
* Reindent the tests
* Fix review comments
This reorders some classes so that this file makes more sense, and adds
a bunch of docs. It also makes the following changes:
* Move allElements from Instrumentation to TestWidgets. (Instrumentation
is going away.)
* Remove findElements.
* Rename byElement to byElementPredicate
* Rename byPredicate to byWidgetPredicate
* Implement _WidgetPredicateFinder so that byWidgetPredicate has good
messages
* Fix one use of byElementPredicate to use byWidgetPredicate.
The 'routes' table is a point of confusion with new developers. By
providing a 'home' argument that sets the '/' route, we can delay the
point at which we teach developers about 'routes' until the point where
they want to have a second route.
...by adding tests to our examples that don't import flutter_test, which
pins the relevant dependencies.
Also, provide more information when complaining about leaked transient
callbacks in tests.
Also, make tests display full information when they have an exception,
by bypassing the throttling we have for Android logging in tests.
Also, make the word wrapping not wrap stack traces if they happen to
be included in exception output.
Also, fix a leaked transient callback in the checkbox code.
This patch adds dartdoc to LazyBlock. Also, this patch fixes the scrolling
physics of LazyBlock. Previously, we updated a running simulation only when the
change in scroll behavior changed the current scroll offset. Now we update
running simulations every time the behavior changes because the simulation
might depend on quantities other than the current scroll offset.
Previously, border with '0' was ambiguous. Sometimes we treated it as
hairline borders, sometimes as "don't show the border", though even in
the latter case we did some graphics work sometimes. Now we have an
explicit BorderStyle.none flag to not draw the border efficiently.
* left -> leading (Removes an LTR bias)
* center -> title (Widget was actually centered)
* right -> actions (Removes an LTR bias, asymmetric with leading)
Fixes#2348
Well, all the easy ones, anyway.
For some reason `// ignore:` isn't working for me so I've disabled
lints that need that. Also disabled those that require a ton of work
(which I'm doing, but not in this PR, to keep it reviewable).
This adds:
- avoid_init_to_null
- library_names
- package_api_docs
- package_names
- package_prefixed_library_names
- prefer_is_not_empty
- sort_constructors_first
- sort_unnamed_constructors_first
- unnecessary_getters_setters
Most of the remaining widget examples are actually manual tests. This patch
moves them into //dev/manual_tests. A couple are examples of using services,
which I've moved to //examples/layers/services. The remainder are out-dated and
are removed by this patch.