Skip to content

Instantly share code, notes, and snippets.

@skabber
Created May 9, 2019 00:10
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 skabber/8dbf7cdee1431b13d8b87d8ff9075fa3 to your computer and use it in GitHub Desktop.
Save skabber/8dbf7cdee1431b13d8b87d8ff9075fa3 to your computer and use it in GitHub Desktop.
Hero Widget transitionOnUserGestures bug.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoApp(
title: 'Flutter Demo',
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
child: CupertinoScrollbar(
child: CustomScrollView(
slivers: <Widget>[
CupertinoSliverNavigationBar(
largeTitle: Text("Hero"),
),
SliverList(
delegate: SliverChildBuilderDelegate((context, num) {
return Row(
children: <Widget>[
GestureDetector(
onTap: () {
print("object");
Navigator.of(context)
.push(CupertinoPageRoute(builder: (context) {
return PageTwo();
}));
},
child: Hero(
tag: "hero1",
transitionOnUserGestures: true,
child: ClipPath(
clipper: RightSlantClipper(),
child: Container(
color: Colors.green,
width: 80.0,
child: CachedNetworkImage(
imageUrl:
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSMwv2FT4pkFYxy6H1BuRK0W-DiNTmm0jwXTyJpjNzbXdUvDttB",
alignment: Alignment(0.2, -0.7),
fit: BoxFit.none,
),
),
),
),
),
Text("Flutter'n")
],
);
}, childCount: 1),
)
],
),
),
);
}
}
class RightSlantClipper extends CustomClipper<Path> {
@override
getClip(Size size) {
var path = Path();
path.lineTo(0.0, size.height);
path.lineTo(size.width, size.height);
path.lineTo(size.width - 20, 0.0);
path.close();
return path;
}
@override
bool shouldReclip(CustomClipper oldClipper) => true;
}
class PageTwo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
child: CupertinoScrollbar(
child: CustomScrollView(
slivers: <Widget>[
CupertinoSliverNavigationBar(
largeTitle: Text("page 2"),
),
SliverFillRemaining(
child: Hero(
transitionOnUserGestures: true,
tag: "hero1",
child: CachedNetworkImage(
imageUrl:
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSMwv2FT4pkFYxy6H1BuRK0W-DiNTmm0jwXTyJpjNzbXdUvDttB"),
),
)
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment