fundamentos de aleteo

 

Transmisión de datos de navegación y recepción

import ' package: flutter / material.dart ' ; 

class Product { 
  final String title; // Product title 
  final String description; // Product description 
  Product ( this .title, this .description); 
} 

void main () { 
  runApp (MaterialApp ( 
    título: ' Transferencia y recepción de datos de navegación ' , 
    inicio: ProductList ( 
        productos: 
            List.generate ( 20 , (i) => Product ( ' 阿 强产品$ i ' , ' Estos son los detalles del producto, ID: $ i ' ))),
  )); 
} 

class ProductList extiende StatelessWidget { 
  final List <Product> productos; 
  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 ( 
            título: Texto (productos [index] .title), 
            onTap: () {
              Navigator.push ( 
                  context, 
                  MaterialPageRoute ( 
                      constructor: (context) => 
                          ProductDetail (product: products [index]))); 
            }, 
          ); 
        }, 
      ), // 动态 构建
    ); 
  } 
} 

class ProductDetail extiende StatelessWidget { 
  producto del producto final; 
  ProductDetail ({Key key, @required this .product}): super (key: key); 

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

 

Supongo que te gusta

Origin www.cnblogs.com/cap-rq/p/12756232.html
Recomendado
Clasificación