Commit 37ba532c authored by Tuan Anh Nguyen's avatar Tuan Anh Nguyen
Browse files

WIP: add home page with placholders

parent aaca1f27
Loading
Loading
Loading
Loading
+92 −0
Original line number Diff line number Diff line
import 'package:flutter/material.dart';
import 'package:stamped/common/util/shared_ui_constants.dart';
import 'package:stamped/common/widget/page_template.dart';
import 'package:stamped/pages/collections/postcard_tile.dart';
import 'package:stamped/pages/home/from_friend_card.dart';

final postcardPlaceholders = [
  for (var _ = 0; _ < 5; _++) PostcardTile(),
];

final fromYourFriendsPlaceholder = [
  for (var _ = 0; _ < 4; _++) FromFriendCard()
];

class HomePage extends StatelessWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return PageTemplate(
      title: 'Stamped!',
      child: SingleChildScrollView(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisSize: MainAxisSize.max,
          children: [
            _buildHeading('Postcards in Your Area'),
            _buildCardCarousel(
              context,
              height: 250,
              itemBuilder: (context, index) =>
                  postcardPlaceholders.elementAt(index),
              itemCount: postcardPlaceholders.length,
            ),
            SizedBox(
              height: STANDARD_GAP,
            ),
            _buildHeading('From Your Friends'),
            _buildCardCarousel(
              context,
              height: 150,
              itemBuilder: (context, index) =>
                  fromYourFriendsPlaceholder.elementAt(index),
              itemCount: fromYourFriendsPlaceholder.length,
            ),
            SizedBox(
              height: STANDARD_GAP,
            ),
            _buildHeading('Your Last Postcards'),
            _buildCardCarousel(
              context,
              height: 250,
              itemBuilder: (context, index) =>
                  postcardPlaceholders.elementAt(index),
              itemCount: postcardPlaceholders.length,
            )
          ],
        ),
      ),
    );
  }

  Widget _buildHeading(
    String value,
  ) =>
      Text(
        value,
        style: TextStyle(
          fontSize: 18,
          fontWeight: FontWeight.bold,
        ),
      );

  Widget _buildCardCarousel(
    BuildContext context, {
    required double height,
    required Widget Function(BuildContext, int) itemBuilder,
    required int itemCount,
  }) =>
      SizedBox(
        height: height,
        width: MediaQuery.of(context).size.width,
        child: ListView.separated(
          itemBuilder: itemBuilder,
          separatorBuilder: (context, index) => SizedBox(
            width: STANDARD_GAP,
          ),
          itemCount: itemCount,
          scrollDirection: Axis.horizontal,
        ),
      );
}