視頻地址:html
https://www.bilibili.com/video/av35800108/?p=23app
博客地址:less
https://jspang.com/post/flutter4.html#toc-3f5jsp
主要學習子頁面返回數據給父頁面async
下劃線很通常定義內部的方法ide
snackBar去接收post
XiaoJieJie這個類就至關於咱們的子頁面學習
快捷鍵stless快速生成類:ui
快速生成能夠誰用安卓studio裏面的 Live Template:spa
navigator.pop方法,返回數據就是啓用第二個參數
點擊按鈕回調到首頁 下面並snackbar顯示出來 子頁面傳回來的信息
import 'package:flutter/material.dart'; void main(){ runApp(MaterialApp( title: '導航的數據傳遞和接收', home:FirstPage() )); } class FirstPage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text('找小 姐姐要電話'),), body: Center( child: RouteButton(), ), ); } } class RouteButton extends StatelessWidget { @override Widget build(BuildContext context) { return RaisedButton( onPressed: (){ _navigateToXiaoJieJie(context); }, child: Text('去找小 姐姐'), ); } _navigateToXiaoJieJie(BuildContext context) async{ final result= await Navigator.push( context, MaterialPageRoute(builder: (context)=>XiaoJieJie()) ); Scaffold.of(context).showSnackBar(SnackBar(content:Text('$result'))); } } class XiaoJieJie extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title:Text('我是小姐姐'), ), body: Center( child: Column( children: <Widget>[ RaisedButton( child: Text('大長腿小姐姐'), onPressed: (){ Navigator.pop(context,'大長腿小姐姐:1511111111'); },), RaisedButton( child: Text('小蠻腰小姐姐'), onPressed: (){ Navigator.pop(context,'小蠻腰小姐姐:152222222'); },), ], ), ), ); } }