Saltar al contenido

ontap listview flutter eliminar código de artículo ejemplo

Ejemplo 1: como eliminar listview en flutter

import'package:flutter/material.dart';voidmain()=>runApp(MyApp());classMyAppextendsStatelessWidget// This widget is the root of your application.
  Widget build(BuildContext context)returnMaterialApp(
      title:'Flutter Slidable Demo',
      theme:ThemeData(
        primarySwatch: Colors.blue,),
      home:MyHomePage(title:'Flutter Slidable Demo'),);classMyHomePageextendsStatefulWidgetMyHomePage(Key key,this.title):super(key: key);final String title;
  _MyHomePageState createState()=>_MyHomePageState();class_MyHomePageStateextendsState<MyHomePage>final List<_HomeItem> items = List.generate(5,(i)=>_HomeItem(
      i,'Tile n°$i',),);
  Widget build(BuildContext context)returnScaffold(
      appBar:AppBar(
        title:Text(widget.title),),
      body:Center(
        child:_buildList(context),),);

  Widget _buildList(BuildContext context)return ListView.builder(
      itemBuilder:(context, index)returnTile(items[index], _deleteItem);,
      itemCount: items.length,);void_deleteItem(_HomeItem item)setState(()print(context);print("remove: $item");print("Number of items before: $items.length");
      items.remove(item);print("Number of items after delete: $items.length"););classTileextendsStatefulWidgetfinal _HomeItem item;finalFunction delete;Tile(this.item,this.delete);
  State<StatefulWidget>createState()=>_TileState(item, delete);class_TileStateextendsState<Tile>final _HomeItem item;finalFunction delete;_TileState(this.item,this.delete);
  Widget build(BuildContext context)returnListTile(
      key:ValueKey(item.index),
      title:Text("$item.title"),
      subtitle:Text("$item.index"),
      onTap:()=>delete(item),);class_HomeItemconst_HomeItem(this.index,this.title,);final int index;final String title;

Ejemplo 2: como eliminar listview en flutter

voidmain()=>runApp(newMyApp());classMyAppextendsStatelessWidget// This widget is the root of your application.
  Widget build(BuildContext context)returnnewMaterialApp(
      title:'Flutter Demo',
      theme:newThemeData(
        primarySwatch: Colors.blue,),
      home:newMyHomePage(title:'Flutter Demo Home Page'),);classMyHomePageextendsStatefulWidgetMyHomePage(Key key,this.title):super(key: key);final String title;
  _MyHomePageState createState()=>new_MyHomePageState();class_MyHomePageStateextendsState<MyHomePage>
  int _counter =0;

  List<TestItem> items =newList<TestItem>();_MyHomePageState()for(int i =0; i <20; i++)this.items.add(newTestItem());
  Widget build(BuildContext context)returnnewScaffold(
        appBar:newAppBar(
          title:newText(widget.title),),
        body:newColumn(
          children:<Widget>[ItemInfoViewWidget(this.items,this.items.first),FlatButton(
              child:newText('Open Detailed View'),
              onPressed: buttonClicked,)],));voidbuttonClicked()
    Navigator.push(
      context,MaterialPageRoute(builder:(context)=>ItemViewWidget(this.items)),);

Calificaciones y reseñas

Si te animas, puedes dejar un enunciado acerca de qué le añadirías a este escrito.

¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *