step 31 : total history, change password, resize image from camera, update versi 1.2.0
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
import 'package:app_petty_cash/model/history_total_model.dart';
|
||||
import 'package:app_petty_cash/provider/current_info_account_balance_provider.dart';
|
||||
import 'package:app_petty_cash/repository/home_repository.dart';
|
||||
import 'package:app_petty_cash/repository/transaksi_repository.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../model/info_account_balance.dart';
|
||||
import '../../provider/dio_provider.dart';
|
||||
import '../../repository/base_repository.dart';
|
||||
|
||||
abstract class HistoryTotalState extends Equatable {
|
||||
final DateTime date;
|
||||
const HistoryTotalState(this.date);
|
||||
@override
|
||||
List<Object?> get props => [date];
|
||||
}
|
||||
|
||||
class HistoryTotalStateInit extends HistoryTotalState {
|
||||
HistoryTotalStateInit() : super(DateTime.now());
|
||||
}
|
||||
|
||||
class HistoryTotalStateLoading extends HistoryTotalState {
|
||||
HistoryTotalStateLoading() : super(DateTime.now());
|
||||
}
|
||||
|
||||
class HistoryTotalStateError extends HistoryTotalState {
|
||||
final String message;
|
||||
HistoryTotalStateError({
|
||||
required this.message,
|
||||
}) : super(DateTime.now());
|
||||
}
|
||||
|
||||
class HistoryTotalStateDone extends HistoryTotalState {
|
||||
final HistoryTotalModel model;
|
||||
// final String resp;
|
||||
HistoryTotalStateDone({
|
||||
required this.model,
|
||||
}) : super(DateTime.now());
|
||||
}
|
||||
|
||||
//notifier
|
||||
class HistoryTotalNotifier extends StateNotifier<HistoryTotalState> {
|
||||
final Ref ref;
|
||||
HistoryTotalNotifier({
|
||||
required this.ref,
|
||||
}) : super(HistoryTotalStateInit());
|
||||
|
||||
void historyTotal(
|
||||
String companyid,
|
||||
String tglAwal,
|
||||
String tglAkhir,
|
||||
String categoryid,
|
||||
) async {
|
||||
try {
|
||||
state = HistoryTotalStateLoading();
|
||||
final dio = ref.read(dioProvider);
|
||||
final resp = await TransaksiRepository(dio: dio).getHistoryTotal(
|
||||
companyid,
|
||||
tglAwal,
|
||||
tglAkhir,
|
||||
categoryid
|
||||
);
|
||||
state = HistoryTotalStateDone(model: resp);
|
||||
} catch (e) {
|
||||
if (e is BaseRepositoryException) {
|
||||
state = HistoryTotalStateError(message: e.message.toString());
|
||||
} else {
|
||||
state = HistoryTotalStateError(message: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//provider
|
||||
final historyTotalProvider =
|
||||
StateNotifierProvider<HistoryTotalNotifier, HistoryTotalState>(
|
||||
(ref) => HistoryTotalNotifier(ref: ref),
|
||||
);
|
||||
@@ -1,7 +1,9 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:app_petty_cash/model/history_total_model.dart';
|
||||
import 'package:app_petty_cash/screen/transaksi/confirm_transaksi_provider.dart';
|
||||
import 'package:app_petty_cash/screen/transaksi/delete_transaksi_provider.dart';
|
||||
import 'package:app_petty_cash/screen/transaksi/history_total_provider.dart';
|
||||
import 'package:app_petty_cash/screen/transaksi/search_history_transaksi_provider.dart';
|
||||
import 'package:dropdown_button2/dropdown_button2.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -17,6 +19,7 @@ import '../../app/route.dart';
|
||||
import '../../model/history_transaksi_model.dart';
|
||||
import '../../model/list_category_model.dart';
|
||||
import '../../model/list_type_model.dart';
|
||||
import '../../provider/current_total_history_provider.dart';
|
||||
import '../../provider/current_user_provider.dart';
|
||||
import '../../widget/custom_drawer.dart';
|
||||
import '../../widget/field_row_history_transaksi.dart';
|
||||
@@ -64,6 +67,8 @@ class HistoryTransaksiScreen extends HookConsumerWidget {
|
||||
),
|
||||
);
|
||||
|
||||
final historyTotalLoading = useState(false);
|
||||
|
||||
// A. LISTEN PROVIDER
|
||||
|
||||
// type
|
||||
@@ -142,6 +147,29 @@ class HistoryTransaksiScreen extends HookConsumerWidget {
|
||||
},
|
||||
);
|
||||
|
||||
// read provider info account balance
|
||||
ref.listen(
|
||||
historyTotalProvider,
|
||||
(previous, next) {
|
||||
if (next is HistoryTotalStateLoading) {
|
||||
historyTotalLoading.value = true;
|
||||
} else if (next is HistoryTotalStateError) {
|
||||
// print(next.message);
|
||||
historyTotalLoading.value = false;
|
||||
SanckbarWidget(context, next.message, snackbarType.error);
|
||||
} else if (next is HistoryTotalStateDone) {
|
||||
// print(jsonEncode(next.model));
|
||||
// print(next.model.length);
|
||||
// infoAccountBalanceObject.value = next.model;
|
||||
ref.read(currentHistoryTotalProvider.notifier).state =
|
||||
HistoryTotalModel(
|
||||
totalAll: next.model.totalAll,
|
||||
);
|
||||
historyTotalLoading.value = false;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// delete transaksi
|
||||
ref.listen(
|
||||
deleteTransaksiProvider,
|
||||
@@ -1035,6 +1063,81 @@ class HistoryTransaksiScreen extends HookConsumerWidget {
|
||||
// ),
|
||||
// ),
|
||||
|
||||
// Total by Filter Category
|
||||
|
||||
if (historyTotalLoading.value)
|
||||
Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
|
||||
(selectedListCategory.value.categoryid != "ALL" &&
|
||||
historyTotalLoading.value == false)
|
||||
? Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
'Kategori Total',
|
||||
style:
|
||||
Constant.body1(context: context).copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Constant.textBlack,
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: Constant.getActualXPhone(
|
||||
context: context,
|
||||
x: 4,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
':',
|
||||
style:
|
||||
Constant.body1(context: context).copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Constant.textBlack,
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: Constant.getActualXPhone(
|
||||
context: context,
|
||||
x: 4,
|
||||
),
|
||||
),
|
||||
Container(
|
||||
// width: 100,
|
||||
width: Constant.getActualXPhone(
|
||||
context: context, x: 100),
|
||||
child: Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
ref
|
||||
.read(currentHistoryTotalProvider
|
||||
.notifier)
|
||||
.state
|
||||
.totalAll
|
||||
.toString(),
|
||||
style: Constant.body1(context: context)
|
||||
.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Constant.pcBtnBackgroundColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
: SizedBox.shrink(),
|
||||
|
||||
SizedBox(
|
||||
height: Constant.getActualYPhone(context: context, y: 20),
|
||||
),
|
||||
|
||||
(searchHistoryIsLoading.value)
|
||||
? Center(
|
||||
child: CircularProgressIndicator(),
|
||||
|
||||
@@ -5,6 +5,7 @@ import '../../model/history_transaksi_model.dart';
|
||||
import '../../repository/transaksi_repository.dart';
|
||||
import '../../provider/dio_provider.dart';
|
||||
import '../../repository/base_repository.dart';
|
||||
import 'history_total_provider.dart';
|
||||
|
||||
abstract class SearchHistoryTransaksiState extends Equatable {
|
||||
final DateTime date;
|
||||
@@ -47,18 +48,26 @@ class SearchHistoryTransaksiNotifier
|
||||
String companyid,
|
||||
String tglAwal,
|
||||
String tglAkhir,
|
||||
String categoryid,
|
||||
String categoryid,
|
||||
) async {
|
||||
try {
|
||||
state = SearchHistoryTransaksiStateLoading();
|
||||
final dio = ref.read(dioProvider);
|
||||
final resp = await TransaksiRepository(dio: dio).getListHistoryTransaksi(
|
||||
companyid,
|
||||
tglAwal,
|
||||
tglAkhir,
|
||||
categoryid,
|
||||
companyid,
|
||||
tglAwal,
|
||||
tglAkhir,
|
||||
categoryid,
|
||||
);
|
||||
state = SearchHistoryTransaksiStateDone(model: resp);
|
||||
|
||||
// panggil provider total transaksi by category for non all
|
||||
ref.read(historyTotalProvider.notifier).historyTotal(
|
||||
companyid,
|
||||
tglAwal,
|
||||
tglAkhir,
|
||||
categoryid,
|
||||
);
|
||||
} catch (e) {
|
||||
if (e is BaseRepositoryException) {
|
||||
state = SearchHistoryTransaksiStateError(message: e.message.toString());
|
||||
|
||||
@@ -20,10 +20,13 @@ import 'package:intl/intl.dart';
|
||||
|
||||
import '../../app/constant.dart';
|
||||
import '../../model/list_category_model.dart';
|
||||
import '../../provider/current_menu_provider.dart';
|
||||
import '../../provider/current_user_provider.dart';
|
||||
import '../../widget/custom_drawer.dart';
|
||||
import '../../widget/sankbar_widget.dart';
|
||||
|
||||
import 'package:image/image.dart' as img;
|
||||
|
||||
class DummyDropdownTipe {
|
||||
final String options;
|
||||
final int id;
|
||||
@@ -151,6 +154,8 @@ class TransaksiScreen extends HookConsumerWidget {
|
||||
'Data Berhasil Disimpan',
|
||||
snackbarType.success,
|
||||
);
|
||||
// diupdate ke menu home jika sukses
|
||||
ref.read(currentPageProvider.notifier).update((state) => 0);
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pushNamed(homeRoute);
|
||||
}
|
||||
@@ -194,7 +199,7 @@ class TransaksiScreen extends HookConsumerWidget {
|
||||
|
||||
final userIDLogin = ref.read(currentUserProvider)?.model.M_UserID ?? "0";
|
||||
|
||||
getBase64() async {
|
||||
getBase64_v1() async {
|
||||
// List<int> imageBytes = await fileData.value?.readAsBytes();
|
||||
if (fileData.value != null) {
|
||||
final bytes = io.File(fileData.value!.path).readAsBytesSync();
|
||||
@@ -211,11 +216,32 @@ class TransaksiScreen extends HookConsumerWidget {
|
||||
}
|
||||
}
|
||||
|
||||
getBase64() async {
|
||||
// List<int> imageBytes = await fileData.value?.readAsBytes();
|
||||
if (fileData.value != null) {
|
||||
final bytes = io.File(fileData.value!.path).readAsBytesSync();
|
||||
String base64Image = base64Encode(await fileData.value!.readAsBytes());
|
||||
fileDataBase64.value = base64Image;
|
||||
final file = File(fileData.value!.path);
|
||||
|
||||
print(file.lengthSync() / 1000000);
|
||||
print(await fileData.value!.length());
|
||||
fileSize.value = await fileData.value!.length();
|
||||
|
||||
// await getExternalStorageDirectory();
|
||||
// print(await fileData.value!.saveTo(path));
|
||||
print(fileDataBase64.value);
|
||||
}
|
||||
}
|
||||
|
||||
final ImagePicker _picker = ImagePicker();
|
||||
pickImage() async {
|
||||
final XFile? pickedFile = await _picker.pickImage(
|
||||
source: ImageSource.camera,
|
||||
);
|
||||
source: ImageSource.camera,
|
||||
// maxWidth set untuk width image
|
||||
maxWidth: 640,
|
||||
// maxHeight set untuk width image
|
||||
maxHeight: 480);
|
||||
if (pickedFile != null) {
|
||||
final tmpFile = FilePickerResult([
|
||||
PlatformFile(
|
||||
|
||||
Reference in New Issue
Block a user