Fakultas Ilmu Komputer UI

donation_re_upload.dart 4.59 KB
Newer Older
Michael Wiryadinata Halim's avatar
Michael Wiryadinata Halim committed
1
2
3
4
5
6
7
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';
8
import 'package:home_industry/Pages/Donation/money_donation_page.dart';
Michael Wiryadinata Halim's avatar
Michael Wiryadinata Halim committed
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
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,
37
      @required String bankName,
Michael Wiryadinata Halim's avatar
Michael Wiryadinata Halim committed
38
      @required String accountName,
39
40
      @required File image,
      @required String bankIdDestination}) {
Michael Wiryadinata Halim's avatar
Michael Wiryadinata Halim committed
41
    donationReUploadBloc.add(ReUploadButtonClicked(
42
43
44
45
46
47
        donationId: widget.donation.id,
        amount: amount,
        image: image,
        bankName: bankName,
        bankAccountName: accountName,
        bankIdDestination: bankIdDestination));
Michael Wiryadinata Halim's avatar
Michael Wiryadinata Halim committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
  }

  @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) {
68
              EasyLoading.show(status: 'Bukti sedang diubah');
Michael Wiryadinata Halim's avatar
Michael Wiryadinata Halim committed
69
            } else if (state is ReUploadError) {
70
              EasyLoading.showError('Gagal mengubah bukti');
Michael Wiryadinata Halim's avatar
Michael Wiryadinata Halim committed
71
            } else if (state is ReUploadSuccess) {
72
73
              EasyLoading.showSuccess(
                  'Terima kasih!\nDonasi anda sedang dalam pengecekan');
Michael Wiryadinata Halim's avatar
Michael Wiryadinata Halim committed
74
75
76
              Navigator.pop(context);
            }
          },
77
78
79
          child: LayoutBuilder(
            builder: (BuildContext context, BoxConstraints viewport) {
              return SingleChildScrollView(
80
                padding: const EdgeInsets.only(left: 12, right: 12),
81
82
83
84
85
86
                child: ConstrainedBox(
                  constraints: BoxConstraints(minHeight: viewport.maxHeight),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
87
88
89
90
91
92
93
                      Container(
                        height: 40,
                        alignment: Alignment.centerLeft,
                        child: Text(
                          'Nomor donasi: ${widget.donation.donationNumber}',
                          style: Theme.of(context).textTheme.headline6,
                        ),
94
                      ),
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
                      Column(
                        children: <Widget>[
                          DonasiBody(
                            tap: onTap,
                            donation: widget.donation,
                          ),
                          BorderBlueButton(
                              onPressed: () {
                                FocusScope.of(context).unfocus();
                                showDialog(
                                    context: context,
                                    builder: (_) => ImageDialog(
                                        urlImage: widget
                                            .donation.proofOfBankTransfer));
                              },
110
111
112
113
                              label: 'Lihat bukti sebelumnya'),
                          const SizedBox(
                            height: 8,
                          )
114
115
116
117
118
119
120
                        ],
                      ),
                    ],
                  ),
                ),
              );
            },
Michael Wiryadinata Halim's avatar
Michael Wiryadinata Halim committed
121
122
123
124
          ),
        ));
  }
}