Fakultas Ilmu Komputer UI

donation_re_upload.dart 3.48 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:home_industry/Component/border_blue_button.dart';
import 'package:home_industry/Component/image_dialog.dart';
import 'package:home_industry/Pages/Donation/donation_page.dart';
import 'package:home_industry/Pages/DonationHistory/model/donation.dart';
import 'package:home_industry/Pages/DonationReupload/bloc/donation_reupload_bloc.dart';
import 'package:home_industry/Pages/DonationReupload/bloc/donation_reupload_event.dart';
import 'package:home_industry/Pages/DonationReupload/repositories/reupload_repository.dart';
import 'package:home_industry/State/Auth/repositories/depedencies_repositories.dart';

import 'bloc/donation_reupload_state.dart';

class DonationReUpload extends StatefulWidget {
  final Donation donation;

  const DonationReUpload({Key key, @required this.donation}) : super(key: key);
  @override
  _DonationReUploadState createState() => _DonationReUploadState();
}

class _DonationReUploadState extends State<DonationReUpload> {
  DonationReUploadBloc donationReUploadBloc;

  @override
  void initState() {
    donationReUploadBloc = DonationReUploadBloc(ReUploadRepository(
        RepositoryProvider.of<DependenciesRepositories>(context).dio));
    super.initState();
  }

  void onTap(
      {@required String amount,
      @required String accountName,
      @required String accountNumber,
      @required File image}) {
    donationReUploadBloc.add(ReUploadButtonClicked(
        donationId: widget.donation.id,
        amount: amount,
        image: image,
        bankAccountName: accountName,
        bankAccountNumber: accountNumber));
  }

  @override
  void dispose() {
    donationReUploadBloc.close();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text('Unggah bukti'),
          centerTitle: true,
        ),
        backgroundColor: Colors.white,
        body: BlocListener<DonationReUploadBloc, DonationReUploadState>(
          bloc: donationReUploadBloc,
          listener: (_, state) {
            if (state is ReUploadLoading) {
              EasyLoading.show(status: "Bukti sedang diunggah");
            } else if (state is ReUploadError) {
              EasyLoading.showError("Gagal unggah bukti");
            } else if (state is ReUploadSuccess) {
              EasyLoading.showSuccess("Bukti berhasil diunggah");
              Navigator.pop(context);
            }
          },
          child: ListView(
75
            padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 8),
76
77
78
79
80
81
82
83
84
            children: <Widget>[
              Text(
                'Nomor donasi: ${widget.donation.donationNumber}',
                style: Theme.of(context).textTheme.headline,
              ),
              DonasiBody(
                tap: onTap,
                donation: widget.donation,
              ),
85
              const Divider(
86
87
88
89
                height: 8,
              ),
              BorderBlueButton(
                  onPressed: () {
90
                    FocusScope.of(context).requestFocus(FocusNode());
91
92
93
94
95
96
97
98
99
100
101
                    showDialog(
                        context: context,
                        builder: (_) => ImageDialog(
                            urlImage: widget.donation.proofOfBankTransfer));
                  },
                  label: "Lihat bukti sebelumnya")
            ],
          ),
        ));
  }
}