news 2026/4/16 16:20:40

【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/4/16 14:00:23

李飞飞团队新作:无需修改架构,重组数据即显著提升AI对视频理解能力

一种简单得令人惊讶的方法&#xff0c;只需将现有的短视频素材重组&#xff0c;就能在不增加计算成本的前提下显著提升AI对长视频的理解能力。斯坦福大学、微软研究院和威斯康辛大学团队&#xff0c;提出了VideoWeave数据中心化方法。不需要发明新的复杂架构&#xff0c;也不需…

作者头像 李华
网站建设 2026/4/16 14:33:26

别再傻等了,给 Claude Code 装个通知铃铛

最近用 Claude Code、Copilot CLI 这类 AI Agent 工具的时候&#xff0c;有一个挺烦人的问题&#xff1a;让 AI 在后台跑任务&#xff0c;我总是会忍不住去查看他的执行状态&#xff0c;有时候比较复杂的任务可能会耗时十来分钟&#xff0c;每次来回切换非常浪费时间。 背景 …

作者头像 李华
网站建设 2026/4/14 17:57:11

2026大专大数据技术专业学数据分析指南

大数据技术专业核心课程与数据分析的关系大数据技术专业通常涵盖数据采集、存储、处理、可视化等核心模块&#xff0c;数据分析作为数据处理的关键环节&#xff0c;是大数据技术栈的重要组成部分。掌握数据分析能力有助于理解数据挖掘、机器学习等高级应用场景。数据分析课程可…

作者头像 李华
网站建设 2026/4/16 14:33:09

海外仓VS本地直发,谁更容易被TRO?

引言&#xff1a;跨境发货方式如何影响 TRO 风险随着跨境电商业务快速发展&#xff0c;越来越多卖家开始在全球不同地区布局仓储和发货。海外仓&#xff08;Fulfillment by Overseas Warehouse&#xff09;和本地直发&#xff08;Direct Shipping&#xff09;各有优劣&#xff…

作者头像 李华
网站建设 2026/4/16 14:33:19

Agent Skills 终极指南:从零到精通

一个设计良好的 Skill&#xff0c;所带来的智能能力足以匹敌&#xff0c;甚至超越完整的 AI 产品。更关键的是&#xff1a;任何人都能自己开发 Skill&#xff0c;不需要技术背景。以我的 Article-Copilot 为例&#xff0c;只用一个 Skill&#xff0c;我就搭建了一个能从素材处理…

作者头像 李华