Skip to content

Instantly share code, notes, and snippets.

@Alby-o
Created March 7, 2019 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alby-o/28819a330a3f9888e011bb5a61574fc2 to your computer and use it in GitHub Desktop.
Save Alby-o/28819a330a3f9888e011bb5a61574fc2 to your computer and use it in GitHub Desktop.
Heroes Failed assertion: line 248 pos 12: 'box != null && box.hasSize': is not true.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: PageOne(),
);
}
}
class PageOne extends StatelessWidget {
void navigate(BuildContext context) {
Navigator.of(context).push(new MaterialPageRoute(
builder: (BuildContext context) => new PageTwo()));
}
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new GestureDetector(
onTap: () => navigate(context),
child: new Box(
color: Colors.green,
height: 100,
width: 100,
),
),
);
}
}
class PageTwo extends StatelessWidget {
void navigate(BuildContext context) {
Navigator.of(context).push(new MaterialPageRoute(
builder: (BuildContext context) => new PageThree()));
}
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new GestureDetector(
onTap: () => navigate(context),
child: new Box(
color: Colors.orange,
height: 200,
width: 80,
),
),
);
}
}
class PageThree extends StatelessWidget {
void navigate(BuildContext context) {
Navigator.of(context).pushAndRemoveUntil(
new MaterialPageRoute(builder: (BuildContext context) => new PageOne()),
(Route<dynamic> route) => route.isFirst,
);
}
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new GestureDetector(
onTap: () => navigate(context),
child: new Box(
color: Colors.blue,
height: 150,
width: 200,
),
),
);
}
}
class Box extends StatelessWidget {
final Color color;
final double height;
final double width;
const Box({Key key, this.color, this.height, this.width}) : super(key: key);
@override
Widget build(BuildContext context) {
return new Center(
child: new Hero(
tag: "hero",
child: new Container(
color: color,
margin: EdgeInsets.all(80),
height: height,
width: width,
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment