企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] > [参考](https://docs.flutter.dev/cookbook/navigation/hero-animations) ## code <details> <summary>main.dart</summary> ``` import 'package:flutter/material.dart'; void main() => runApp(const HeroApp()); class HeroApp extends StatelessWidget { const HeroApp({super.key}); @override Widget build(BuildContext context) { return const MaterialApp( title: 'Transition Demo', home: MainScreen(), ); } } class MainScreen extends StatelessWidget { const MainScreen({super.key}); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Main Screen'), ), body: GestureDetector( onTap: () { Navigator.push(context, MaterialPageRoute(builder: (context) { return const DetailScreen(); })); }, child: Hero( tag: 'imageHero', child: Image.network( 'https://picsum.photos/250?image=9', ), ), ), ); } } class DetailScreen extends StatelessWidget { const DetailScreen({super.key}); @override Widget build(BuildContext context) { return Scaffold( body: GestureDetector( onTap: () { Navigator.pop(context); }, child: Center( child: Hero( tag: 'imageHero', child: Image.network( 'https://picsum.photos/250?image=9', ), ), ), ), ); } } ``` </details>