• flutter学习笔记三 路由参数传递


    import 'package:flutter/material.dart';

    /**
     * 第三节,商品详情页,路由传递
     */
    void main(){
      runApp(MaterialApp(
        title:'JSPang',
        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(
          child: Text('去到选择页面'),
          onPressed: (){
            navigatorTo(context);
          },
        );
      }
    }

    navigatorTo(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(
                  onPressed:(){
                    Navigator.pop(context,'第一个,手机号123456789');
                  },
                  child: Text('第一个'),
                ),
                RaisedButton(
                  onPressed:(){
                    Navigator.pop(context,'第二个,手机号123456789');
                  },
                  child: Text('第二个'),
                ),
                RaisedButton(
                  onPressed:(){
                    Navigator.pop(context,'第三个,手机号123456789');
                  },
                  child: Text('第三个'),
                ),
              ],
            ),
          ),
        );
      }
    }

    /**
     * 第二节,商品详情页,路由传递
     */
    // class Product{
    //   String title;
    //   String description;
    //   Product(this.title,this.description);
    // }
    // void main(){
    //   runApp(MaterialApp(
    //     title:'导航的数据传递与接收',
    //     home:ProductList(
    //       products:List.generate(
    //         20,
    //         (i) => Product('商品 $i','这是一个商品详情,编号为:$i'))
    //     )
    //   ));
    // }

    // class ProductList extends StatelessWidget {
    //   final List<Product> products;
    //   ProductList({Key key,@required this.products}):super(key:key);

    //   @override
    //   Widget build(BuildContext context) {
    //     return Scaffold(
    //       appBar: AppBar(title:Text('商品列表')),
    //       body:ListView.builder(
    //         itemCount: products.length,
    //         itemBuilder:(context,index){
    //           return ListTile(
    //             title:Text(products[index].title),
    //             onTap: (){
    //               Navigator.push(
    //                 context, 
    //                 MaterialPageRoute(builder: (context)=>ProductDetail(product:products[index]))
    //                 );
    //             },
    //           );
    //         } ,
    //         )
    //     );
    //   }
    // }

    // class ProductDetail extends StatelessWidget {
    //   final Product product;
    //   ProductDetail({Key key,@required this.product}):super(key:key);

    //   @override
    //   Widget build(BuildContext context) {
    //     return Scaffold(
    //       appBar: AppBar(title:Text('${product.title}')),
    //       body: Center(child: Text('${product.description}'),),
    //     );
    //   }
    // }

    /**
     * 第一节,导航演示
     */
    // void main(){
    //   runApp(MaterialApp(
    //     title:"导航演示01",
    //     home:new FirstScreen()
    //   ));
    // }
    // class FirstScreen extends StatelessWidget{
    //   @override
    //   Widget build(BuildContext context){
    //     return Scaffold(
    //       appBar: AppBar(title:Text('导航页面')),
    //       body:Center(
    //         child: RaisedButton(
    //           child: Text('查看商品详情'),
    //           onPressed: (){
    //             Navigator.push(context,new MaterialPageRoute(
    //               builder:(context)=>new SecondScreen()
    //             ));
    //           },
    //         ),
    //       )
    //     );
    //   }
    // }

    // class SecondScreen extends StatelessWidget{
    //   @override
    //   Widget build(BuildContext context){
    //     return Scaffold(
    //       appBar: AppBar(title:Text('技术胖商品详情页')),
    //       body: Center(
    //         child: RaisedButton(
    //           child: Text('返回'),
    //           onPressed: (){
    //             Navigator.pop(context);
    //           },
    //         ),
    //       ),
    //     );
    //   }
    // }
  • 相关阅读:
    logistics regression
    dir 以及 attrib
    python 爬取有道翻译
    spss 逐步回归
    JQuery传值给.ashx乱码
    字符串转换成json的三种方式
    启动数据库SQL Server Service Broker
    ASP.NET两种缓存方式
    VS安装控件后报错
    sql server中有不是全数字的字符串
  • 原文地址:https://www.cnblogs.com/hllzww/p/12980274.html
Copyright © 2020-2023  润新知