hero_under.dart 4.32 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
// Copyright (c) 2015, the Flutter project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:ui' as ui;

import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';

void main() {
  timeDilation = 8.0;
  runApp(
    new MaterialApp(
      title: "Hero Under",
      routes: {
        '/': (RouteArguments args) => new HeroDemo()
      }
    )
  );
}

const String kImageSrc = 'http://uploads0.wikiart.org/images/m-c-escher/crab-canon.jpg!Blog.jpg';

const String kText = """
Low-crab diets are dietary programs that restrict crustacean consumption, often for the treatment of obesity or diabetes. Foods high in easily digestible crustaceans (e.g., crab, lobster, shrimp) are limited or replaced with foods made from other animals (e.g., poultry, beef, pork) and other crustaceans that are hard to digest (e.g., barnacles), although krill are often allowed. The amount of crab allowed varies with different low-crab diets.
""";

class HeroImage extends StatelessComponent {
  HeroImage({ this.size });
  final Size size;
  Widget build(BuildContext context) {
    return new Hero(
      child: new Container(
        width: size.width,
        height: size.height,
        decoration: new BoxDecoration(
          backgroundImage: new BackgroundImage(
            fit: ImageFit.cover,
            image: imageCache.load(kImageSrc)
          )
        )
      ),
      tag: HeroImage
    );
  }
}

class HeroDemo extends StatelessComponent {
  Widget build(BuildContext context)  {
    return new Scaffold(
      toolBar: new ToolBar(
        left: new IconButton(icon: "navigation/menu"),
        center: new Text("Diets")
      ),
      body: new Center(
        child: new GestureDetector(
          onTap: () => Navigator.push(context, new CrabRoute()),
          child: new Card(
62 63 64 65 66 67 68 69 70 71 72 73
            child: new Row(
              children: <Widget>[
                new HeroImage(
                  size: const Size(100.0, 100.0)
                ),
                new Flexible(
                  child: new Container(
                    padding: const EdgeDims.all(10.0),
                    child: new Text(
                      "Low Crab Diet",
                      style: Theme.of(context).text.title
                    )
74 75
                  )
                )
76 77
              ]
            )
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
          )
        )
      )
    );
  }
}

class CrabRoute extends MaterialPageRoute {
  CrabRoute() : super(builder: (BuildContext context) => new CrabPage());
  void insertHeroOverlayEntry(OverlayEntry entry, Object tag, OverlayState overlay) {
    overlay.insert(entry, above: overlayEntries.first);
  }
}

class CrabPage extends StatelessComponent {
  Widget build(BuildContext context)  {
    TextStyle titleStyle = Typography.white.display2.copyWith(color: Colors.white);
    return new Material(
      color: const Color(0x00000000),
      child: new Block(
        <Widget>[
99 100 101 102
          new Stack(
            children: <Widget>[
              new HeroImage(
                size: new Size(ui.window.size.width, ui.window.size.width)
103
              ),
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
              new ToolBar(
                padding: new EdgeDims.only(top: ui.window.padding.top),
                backgroundColor: const Color(0x00000000),
                left: new IconButton(
                  icon: "navigation/arrow_back",
                  onPressed: () => Navigator.pop(context)
                ),
                right: <Widget>[
                    new IconButton(icon: "navigation/more_vert")
                ]
              ),
              new Positioned(
                bottom: 10.0,
                left: 10.0,
                child: new Text("Low Crab Diet", style: titleStyle)
              )
            ]
          ),
122 123 124
          new Material(
            child: new Container(
              padding: const EdgeDims.all(10.0),
125 126 127 128 129 130 131
              child: new Column(
                children: <Widget>[
                  new Text(kText, style: Theme.of(context).text.body1),
                  new Container(height: 800.0),
                ],
                alignItems: FlexAlignItems.start
              )
132 133 134 135 136 137 138
            )
          )
        ]
      )
    );
  }
}