Ben Rei
Ben Rei

Reputation: 109

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

Upvotes: 2

Views: 7754

Answers (1)

Collin Jackson
Collin Jackson

Reputation: 116728

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.

Upvotes: 5

Related Questions