Flutter UI Widgets

Nov 9 2021 · Dart 2.14, Flutter 2.5, VS Code 1.61

Part 1: Flutter UI Widgets

03. Build Layouts

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 02. Explore Basic Widgets Next episode: 04. Work with Images

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

The rest of this course would focus on building a news reader app. In this episode, we’ll combine what we’ve learnt so far to build an article card widget. I’ve cleared out the previous code in the MainPage widget and the body currently returns an ArticleCard widget.

...
  final Article article;

  const ArticleCard({
    Key? key,
    required this.article,
  }) : super(key: key);
...
ArticleCard(article: articles[0])
...
return Card(
  margin: const EdgeInsets.all(16),
  elevation: 4,
  child: Column(
    children: <Widget>[
      CardBanner(),
      CardDetail(),
    ]
  ),
);
...
class CardDetail extends StatelessWidget {
  final Article? article;

  const CardDetail({Key? key, this.article}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(16),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Text(
            article!.title,
            style: const TextStyle(fontSize: 24),
            maxLines: 2,
            overflow: TextOverflow.ellipsis,
          ),
          const SizedBox(height: 16),
          Row(
            children: <Widget>[
              Text(article!.source),
              const Spacer(),
              const Text('45 Comments'),
            ],
          )
        ],
      ),
    );
  }
}
...
CardDetail(article: article),
...
class CardBanner extends StatelessWidget {
  final String? imageUrl;

  const CardBanner({Key? key, this.imageUrl}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const Placeholder(fallbackHeight: 200);
  }
}
...
Stack(
  children: [
    const Placeholder(
      fallbackHeight: 200,
    ),
    Positioned(
      top: 10,
      right: 10,
      child: IconButton(
        icon: const Icon(Icons.bookmark_border, size: 32),
        onPressed: (){},
      ),
    ),
  ],
),
...