news 2026/2/28 7:41:05

【FLUTTER】flutter中的路由管理

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
【FLUTTER】flutter中的路由管理

路由管理的基础知识点

基础概念


实现代码

方式一:不注册路由

main.dart

import'package:flutter/material.dart';classDetailPageextendsStatefulWidget{constDetailPage({super.key});@override State<DetailPage>createState()=>_DetailPageState();}class_DetailPageStateextendsState<DetailPage>{@override Widgetbuild(BuildContext context){returnScaffold(appBar:AppBar(title:Text('详情页'),centerTitle:true),body:Container(height:double.infinity,width:double.infinity,color:constColor.fromARGB(255,151,224,194),child:SafeArea(child:Center(child:Column(mainAxisAlignment:MainAxisAlignment.center,children:[Text("详情页内容"),FilledButton(onPressed:(){Navigator.pop(context);},child:Text("返回"),),],),),),),);}}

list.dart

import'package:flutter/material.dart';import'package:flutter_app_01/pages/list/detail.dart';classListPageextendsStatefulWidget{constListPage({super.key});@override State<ListPage>createState()=>_ListPageState();}class_ListPageStateextendsState<ListPage>{@override Widgetbuild(BuildContext context){returnScaffold(appBar:AppBar(title:Text('列表页'),centerTitle:true),body:Container(height:double.infinity,width:double.infinity,color:constColor.fromARGB(255,151,224,194),child:SafeArea(child:ListView.builder(itemCount:20,itemBuilder:(context,index){returnGestureDetector(onTap:(){// print("点击了$index");Navigator.push(context,MaterialPageRoute(builder:(context)=>DetailPage()),);},child:Container(height:50,alignment:Alignment.center,width:double.infinity,margin:EdgeInsets.symmetric(vertical:5),decoration:BoxDecoration(color:Colors.white),child:Text("列表项$index"),),);},),),),);}}

detail.dart

import'package:flutter/material.dart';classDetailPageextendsStatefulWidget{constDetailPage({super.key});@override State<DetailPage>createState()=>_DetailPageState();}class_DetailPageStateextendsState<DetailPage>{@override Widgetbuild(BuildContext context){returnScaffold(appBar:AppBar(title:Text('详情页'),centerTitle:true),body:Container(height:double.infinity,width:double.infinity,color:constColor.fromARGB(255,151,224,194),child:SafeArea(child:Center(child:Column(mainAxisAlignment:MainAxisAlignment.center,children:[Text("详情页内容"),FilledButton(onPressed:(){Navigator.pop(context);},child:Text("返回"),),],),),),),);}}

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/2/27 21:05:34

MySQL崩溃恢复神器:innodb_force_recovery 参数详解,DBA 必备!

在 MySQL 的日常运维中&#xff0c;最让人“心跳加速”的场景之一&#xff0c;莫过于数据库突然无法启动&#xff0c;错误日志里赫然写着&#xff1a; InnoDB: Database was not shut down normally!InnoDB: Starting crash recovery....InnoDB: Assertion failure in thread .…

作者头像 李华
网站建设 2026/2/25 14:27:13

自动搬运机械手设计

自动搬运机械手设计与实现 第一章 设计背景与核心目标 传统工业物料搬运多依赖人工或简易机械&#xff0c;存在作业精度低&#xff08;定位误差≥5mm&#xff09;、搬运效率低、劳动强度大、易发生物料磕碰与人员安全事故等问题&#xff0c;难以满足现代化生产线“高精度、高效…

作者头像 李华
网站建设 2026/2/26 22:48:20

JAVA网页分片上传大文件有哪些步骤?

《一个Java老码农的20G文件夹上传历险记》 大家好&#xff0c;我是老王&#xff0c;一个在西安写了15年Java的老程序员。最近接了个外包项目&#xff0c;需求简单概括就是&#xff1a;“用IE9上传20G文件夹&#xff0c;预算100块还要724小时支持”——这感觉就像是让我用自行车…

作者头像 李华
网站建设 2026/2/20 10:32:23

分块上传大文件在JAVA网页中如何实现?

汽车设计图纸大文件上传&#xff08;WEB 集成&#xff09;方案 一、项目背景 在汽车制造行业&#xff0c;汽车设计图纸是核心资产&#xff0c;其文件体积通常较大&#xff0c;动辄达到 100G 左右。客户提出需求&#xff0c;希望能在我们开发的 WEB 系统中实现这类大文件的安全…

作者头像 李华
网站建设 2026/2/27 18:28:18

照着用就行:自考必备的降AI率平台,千笔·降AIGC助手 VS 灵感ai

在AI技术迅速发展的今天&#xff0c;越来越多的学生开始借助AI工具辅助论文写作&#xff0c;以提升效率和内容质量。然而&#xff0c;随着各大查重系统对AI生成内容的识别能力不断提升&#xff0c;AI率超标问题日益突出&#xff0c;成为许多学生毕业路上的“拦路虎”。无论是知…

作者头像 李华
网站建设 2026/2/28 6:37:39

Windows 11 终极性能优化指南

一、精简后台&#xff1a;关闭非必要的系统服务目标&#xff1a;禁用日常使用中无需的系统服务&#xff0c;以减少内存与磁盘资源的占用。操作步骤&#xff1a;打开服务管理器&#xff1a;按下 Win R 键&#xff0c;输入 services.msc 并回车。定位并禁用建议服务&#xff08;…

作者头像 李华