2017-09-26 2 views
0

私は、カードのListview.builderの周りにラップされた拡張ウィジェットを持っています。私のカードはonTapを検出するだけでなく、ナビゲーションの新しい.dartファイルに変数を渡すこともできます。私は現在、サイジングエラーが発生していますか?FlutterのListview.builderカードにGestureDectorを追加する適切な方法は?

はここ

The following assertion was thrown during performLayout(): 
RenderPointerListener object was given an infinite size during layout. 
This probably means that it is a render object that tries to be as big as possible, but it was put 
inside another render object that allows its children to pick their own size. 

私はtitle[index]に合格したいと思います...ここで

new Expanded(
       child: new ListView.builder(
        itemCount: id == null ? 0 : id.length, 
        itemBuilder: (BuildContext context, int index) { 
         return new Card(
         child: new Column(
          children: <Widget>[ 
          new Image.network(video[index]), 
          new Padding(padding: new EdgeInsets.all(3.0)), 
          new Text(title[index], 
          style: new TextStyle(fontWeight: FontWeight.bold, 
          color: Colors.black), 
          ), 
          new GestureDetector(onTap:(){ 
           print(id[index]); 
          },) 

          ], 
         ), 
        ); 

        })) 

がスローされた例外である...私のコード* *コードで更新されますSWIFTの didSelectRowAtIndexPathに似た「ビデオ[インデックス]」

+0

あなたがにコードを追加した場合も、それは良いでしょう、「私の新しい.dartに変数を渡す」この部分をしてください明確にすることができあなたが達成しようとしているものを見ることができます。 – aziza

+0

@aziza私のコードを追加してエラー例外をスローしました。 –

答えて

2

GestureDetectorColumnの子として追加していますが、Flutterはどのタッチパッドが異なるタッチイベントを検出する必要があるのか​​わかりません(GestureDetectorがそのタスクを実行するために必要な場所を指定していません)。 )

あなたがインタラクティブであることを全体Cardが必要な場合は、あなたが持っている可能性がアジザの提案と同様に

var id = ["title 1", "title 2", "title 3", "title 4", "title 5",]; 

    @override 
    Widget build(BuildContext context) { 
    return new Scaffold(
     body: new ListView.builder(
      itemCount: id == null ? 0 : id.length, 
      itemBuilder: (BuildContext context, int index) { 
      return new GestureDetector(//You need to make my child interactive 
       onTap:() => print(id[index]), 
       child: new Card(//I am the clickable child 
       child: new Column(
        children: <Widget>[ 
        //new Image.network(video[index]), 
        new Padding(padding: new EdgeInsets.all(3.0)), 
        new Text(id[index], 
         style: new TextStyle(fontWeight: FontWeight.bold, 
          color: Colors.black), 
        ), 


        ], 
       ),), 
      ); 
      }), 
    ); 
    } 
2

を次のようにGestureDecetor以内にあなたのCardをラップする必要があります基本的にはGestureDetectorですが、マテリアルデザインのスプラッシュを持つInkWellをご覧ください。

また、別のクラスに変数を渡す方法についても尋ねました。インスタンス化の際にコンストラクタ変数として渡すだけで、これを行うことができます。コード例のonTapメソッドを見てください。

コードは次のようになります。

@override 
Widget build(BuildContext context) { 
    return new Scaffold(
    body: new ListView.builder(
     itemCount: id == null ? 0 : id.length, 
     itemBuilder: (BuildContext context, int index) { 
     return new InkWell(
      onTap:() { 
      Navigator.push(
       context, 
       new MaterialPageRoute(
       builder: (context) { 
        return new OtherClass(id[index], video[index]); 
       }, 
      ), 
      ); 
      }, 
      child: new Card(
      child: new Column(
       children: <Widget>[ 
       //new Image.network(video[index]), 
       new Padding(padding: new EdgeInsets.all(3.0)), 
       new Text(id[index], 
        style: new TextStyle(fontWeight: FontWeight.bold, 
         color: Colors.black 
       ), 
       ), 
       ], 
      ), 
     ), 
     ); 
     }), 
); 
} 

*コードテストされていません

関連する問題