flutter/examples/flutter_gallery/lib/demo
Ian Hickson 2dfdc840b1 Refactor everything to do with images (#4583)
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
2016-06-16 09:49:48 -07:00
..
calculator Review nits. 2016-06-14 15:32:42 -07:00
shrine Refactor everything to do with images (#4583) 2016-06-16 09:49:48 -07:00
all.dart Remove the redundant drop-down button demo (#4380) 2016-06-04 09:31:32 -07:00
buttons_demo.dart Use @required for onPressed and onChanged (#4534) 2016-06-12 13:25:06 -07:00
calculator_demo.dart Reorganize the calculator demo (#4536) 2016-06-13 11:44:46 -07:00
cards_demo.dart Refactor everything to do with images (#4583) 2016-06-16 09:49:48 -07:00
chip_demo.dart Call it Flutter Gallery (#3801) 2016-05-09 11:00:54 -07:00
colors_demo.dart Revert "Rename DefaultTextStyle constructor to explicit (#3920)" (#3930) 2016-05-16 11:08:07 -07:00
contacts_demo.dart Refactor everything to do with images (#4583) 2016-06-16 09:49:48 -07:00
data_table_demo.dart Header for PaginatedDataTable (#4468) 2016-06-08 17:29:26 -07:00
date_picker_demo.dart Call it Flutter Gallery (#3801) 2016-05-09 11:00:54 -07:00
dialog_demo.dart Add a Scrollable builder, refactor ScrollableList, et al (#3950) 2016-05-16 17:32:01 -07:00
fail.dart Call it Flutter Gallery (#3801) 2016-05-09 11:00:54 -07:00
full_screen_dialog_demo.dart Revert "Rename DefaultTextStyle constructor to explicit (#3920)" (#3930) 2016-05-16 11:08:07 -07:00
grid_list_demo.dart Refactor everything to do with images (#4583) 2016-06-16 09:49:48 -07:00
icons_demo.dart New gallery app bar background (#4539) 2016-06-13 12:41:29 -07:00
leave_behind_demo.dart "Swipe items to dismiss" demo needs full-bleed dividers (#4231) 2016-05-26 17:06:10 -07:00
list_demo.dart ScrollConfiguration (#4026) 2016-05-20 16:59:09 -07:00
menu_demo.dart Call it Flutter Gallery (#3801) 2016-05-09 11:00:54 -07:00
modal_bottom_sheet_demo.dart Call it Flutter Gallery (#3801) 2016-05-09 11:00:54 -07:00
overscroll_demo.dart ScrollConfiguration (#4026) 2016-05-20 16:59:09 -07:00
page_selector_demo.dart TabPageSelector demo: use chevron icons instead of arrows (#4153) 2016-05-24 09:57:33 -07:00
persistent_bottom_sheet_demo.dart Use @required for onPressed and onChanged (#4534) 2016-06-12 13:25:06 -07:00
pesto_demo.dart Refactor everything to do with images (#4583) 2016-06-16 09:49:48 -07:00
progress_indicator_demo.dart Revert "Rename DefaultTextStyle constructor to explicit (#3920)" (#3930) 2016-05-16 11:08:07 -07:00
scrollable_tabs_demo.dart Call it Flutter Gallery (#3801) 2016-05-09 11:00:54 -07:00
selection_controls_demo.dart Use @required for onPressed and onChanged (#4534) 2016-06-12 13:25:06 -07:00
shrine_demo.dart Version 0.0 of a gallery demo of the Material Design "Shrine" app (#4327) 2016-06-02 14:23:20 -07:00
slider_demo.dart Use @required for onPressed and onChanged (#4534) 2016-06-12 13:25:06 -07:00
snack_bar_demo.dart Call it Flutter Gallery (#3801) 2016-05-09 11:00:54 -07:00
tabs_demo.dart Tabs and scrolling has odd card text (#4019) 2016-05-19 14:13:43 -07:00
tabs_fab_demo.dart Call it Flutter Gallery (#3801) 2016-05-09 11:00:54 -07:00
text_field_demo.dart Use KeyboardType.phone for the Gallery app's text demo. (#3983) 2016-05-17 15:36:59 -04:00
time_picker_demo.dart Call it Flutter Gallery (#3801) 2016-05-09 11:00:54 -07:00
tooltip_demo.dart GridTileBar uses ellipsis, etc (#3881) 2016-05-12 12:27:49 -07:00
two_level_list_demo.dart Call it Flutter Gallery (#3801) 2016-05-09 11:00:54 -07:00
typography_demo.dart Call it Flutter Gallery (#3801) 2016-05-09 11:00:54 -07:00