如何控制小部件的高度和宽度在颤振英雄过渡?



我要指定在扑动英雄过渡中flightShuttleBuilder的高度和宽度。

import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
timeDilation = 5;
return MaterialApp(
home: Screen1(),
);
}
}
class Screen1 extends StatelessWidget {
const Screen1({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Hero(
tag: 'icon',
flightShuttleBuilder: (
BuildContext flightContext,
Animation<double> animation,
HeroFlightDirection flightDirection,
BuildContext fromHeroContext,
BuildContext toHeroContext,
) {
return AnimatedBuilder(
animation: animation,
builder: (context, child) {
return Container(
height: 200, // not working
width: 200,
decoration: BoxDecoration(
color: Colors.green,
),
);
},
);
},
transitionOnUserGestures: true,
child: IconButton(
icon: Icon(
Icons.ad_units,
size: 50,
),
onPressed: () {
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => Screen2()));
},
),
),
),
);
}
}
class Screen2 extends StatelessWidget {
const Screen2({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
alignment: Alignment.bottomCenter,
child: Hero(
child: Icon(
Icons.ad_units,
size: 100,
),
tag: 'icon',
),
),
);
}
}

UnconstrainedBox小部件包装Container。所以它变成了:

return UnconstrainedBox( // <--- add this widget here.
child: Container(
height: 200,
width: 200,
decoration: BoxDecoration(
color: Colors.green,
),
),
);

最新更新