Commit 87bfc42b authored by Tuan Anh Nguyen's avatar Tuan Anh Nguyen
Browse files

feat: add create back page

parent 5a56fe53
Loading
Loading
Loading
Loading
+154 −0
Original line number Original line Diff line number Diff line
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:stamped/common/service/ioc_container.dart';
import 'package:stamped/common/util/shared_ui_constants.dart';
import 'package:stamped/common/widget/page_template.dart';
import 'package:stamped/pages/create/notifiers/create_postcard_notifier.dart';
import 'package:stamped/service/auth_service.dart';

const FONT_SIZE = 18.0;

class CreateBackPage extends StatefulWidget {
  const CreateBackPage({Key? key}) : super(key: key);

  @override
  State<CreateBackPage> createState() => _CreateBackPageState();
}

class _CreateBackPageState extends State<CreateBackPage> {
  late final TextEditingController _textEditingController;

  @override
  void initState() {
    super.initState();
    _textEditingController = TextEditingController();
  }

  @override
  void dispose() {
    _textEditingController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final authService = get<AuthService>();
    final createPostcardNotifier = context.watch<CreatePostcardNotifier>();

    return PageTemplate(
      title: 'Create a Postcard',
      actions: [
        IconButton(
          onPressed: () {
            createPostcardNotifier.text = _textEditingController.text;
            // TODO: select destination country
          },
          icon: Icon(Icons.navigate_next),
        ),
      ],
      child: Container(
        decoration: BoxDecoration(
          color: Colors.white,
          border: Border.all(
            color: Colors.grey,
            width: 2,
          ),
        ),
        padding: EdgeInsets.all(STANDARD_GAP),
        height: double.infinity,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            _buildTextField(),
            Spacer(),
            Divider(
              color: Colors.black87,
            ),
            Spacer(),
            _buildGreetingsText(),
            _buildLocationText(createPostcardNotifier),
            Spacer(),
            _buildFooter(
              createPostcardNotifier,
              authService,
            ),
            Spacer(),
          ],
        ),
      ),
    );
  }

  Widget _buildTextField() {
    return TextField(
      maxLength: 220,
      maxLines: 12,
      style: TextStyle(
        fontSize: FONT_SIZE,
      ),
      decoration: InputDecoration(
        border: InputBorder.none,
      ),
      controller: _textEditingController,
    );
  }

  Widget _buildGreetingsText() {
    return Text(
      'Greetings from',
      style: TextStyle(
        color: Colors.grey,
        fontSize: FONT_SIZE,
        fontWeight: FontWeight.w600,
      ),
    );
  }

  Widget _buildLocationText(CreatePostcardNotifier notifier) {
    return Text(
      notifier.location,
      style: TextStyle(
        color: Colors.black,
        fontSize: FONT_SIZE,
        fontWeight: FontWeight.w800,
      ),
    );
  }

  Widget _buildFooter(
    CreatePostcardNotifier notifier,
    AuthService authService,
  ) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.start,
      mainAxisSize: MainAxisSize.max,
      children: [
        Container(
          height: 100,
          width: 100,
          decoration: BoxDecoration(
            border: Border.all(
              color: Colors.grey[350]!,
              width: 2,
            ),
          ),
        ),
        _buildSignature(authService),
      ],
    );
  }

  Widget _buildSignature(AuthService authService) {
    return Expanded(
      child: Text(
        textAlign: TextAlign.right,
        authService.currentUser.userName,
        style: TextStyle(
          fontSize: FONT_SIZE,
          fontWeight: FontWeight.w800,
        ),
      ),
    );
  }
}