简体   繁体   中英

How to make a card popup on flutter on click?

I've been trying to make a blog article popup in a card on flutter, but every time I run the app, it doesn't pop anything up. I've tried putting the Card object into the onTap statement.

The code is below:

article_view.dart

import 'package:flutter/material.dart';
import 'package:scip_app/articles_data.dart';

class _ArticleListItem extends ListTile {


_ArticleListItem(Article article) :
      super(
        title: new Text(article.title),
        subtitle: new Text(article.blurb),
        onTap: () {
          new FullArticleDisplay(article);
        }
    );
} 

class FullArticleDisplay extends StatelessWidget {
final Article article;

FullArticleDisplay(this.article);

@override
Widget build(BuildContext context) {
  return new Container(
    child: new Card(
      child: new Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            new ListTile(
              title: new Text(article.title),
            ),
            new Text(article.articled),
          ]
      )
    )
  );
 }
}

class ArticleList extends StatelessWidget {
final List<Article> _articles;

ArticleList(this._articles);

@override
Widget build(BuildContext context) {
  return new ListView(
      padding: new EdgeInsets.symmetric(vertical: 8.0),
      children: _buildArticleList()
  );
}

List<_ArticleListItem> _buildArticleList() {
  return _articles.map((artic) => new _ArticleListItem(artic)).toList();
 }
}

class ArticlesPage extends StatelessWidget {

@override
Widget build(BuildContext context) {
  return new Scaffold(
      appBar: new AppBar(
          title: new Text("Articles")
      ),
      body: new ArticleList(kArticles)
  );
 }
}

The other files are here: https://pastebin.com/rS2fLktF

It looks like you're constructing a widget but you're not putting it anywhere. Are you trying to show a dialog? If so, try wrapping your call to new FillArticleDisplay in a call to showDialog. Or you could call setState and save the widget somewhere so you can include it in your build method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM