Compare commits
1 Commits
main
...
andy/chang
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b870e7bea |
21
app_petty_cash/lib/model/company_model.dart
Normal file
21
app_petty_cash/lib/model/company_model.dart
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
class CompanyModel {
|
||||||
|
String? companyid;
|
||||||
|
String? companyname;
|
||||||
|
String? mUserDefaultCompany;
|
||||||
|
|
||||||
|
CompanyModel({this.companyid, this.companyname, this.mUserDefaultCompany});
|
||||||
|
|
||||||
|
CompanyModel.fromJson(Map<String, dynamic> json) {
|
||||||
|
companyid = json['companyid'];
|
||||||
|
companyname = json['companyname'];
|
||||||
|
mUserDefaultCompany = json['M_UserDefaultCompany'];
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||||
|
data['companyid'] = this.companyid;
|
||||||
|
data['companyname'] = this.companyname;
|
||||||
|
data['M_UserDefaultCompany'] = this.mUserDefaultCompany;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
32
app_petty_cash/lib/repository/company_repository.dart
Normal file
32
app_petty_cash/lib/repository/company_repository.dart
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:app_petty_cash/model/company_model.dart';
|
||||||
|
import 'package:app_petty_cash/model/list_type_model.dart';
|
||||||
|
|
||||||
|
import '../app/constant.dart';
|
||||||
|
import '../model/history_transaksi_model.dart';
|
||||||
|
import '../model/list_category_model.dart';
|
||||||
|
import 'base_repository.dart';
|
||||||
|
|
||||||
|
class CompanyRepository extends BaseRepository {
|
||||||
|
CompanyRepository({required super.dio});
|
||||||
|
|
||||||
|
// list company
|
||||||
|
Future<List<CompanyModel>> getListCompany({required String userID}) async {
|
||||||
|
// https: //devone.aplikasi.web.id/one-api-pettycash/pettycash/Usercompany/list_company?M_UserID=2
|
||||||
|
final service =
|
||||||
|
"${Constant.baseUrlDevone}Usercompany/list_company?M_UserID=${userID}";
|
||||||
|
final resp = await get(
|
||||||
|
service: service,
|
||||||
|
);
|
||||||
|
|
||||||
|
print("url list type : $service");
|
||||||
|
|
||||||
|
final result = List<CompanyModel>.empty(growable: true);
|
||||||
|
resp['data'].forEach((e) {
|
||||||
|
final model = CompanyModel.fromJson(e);
|
||||||
|
result.add(model);
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,13 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:app_petty_cash/model/auth_model.dart';
|
||||||
|
import 'package:app_petty_cash/model/company_model.dart';
|
||||||
|
import 'package:app_petty_cash/screen/change_company/list_company_provider.dart';
|
||||||
|
import 'package:app_petty_cash/widget/sankbar_widget.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
import '../../app/constant.dart';
|
import '../../app/constant.dart';
|
||||||
import '../../app/route.dart';
|
import '../../app/route.dart';
|
||||||
@@ -12,6 +19,14 @@ class ChangeCompanyScreen extends HookConsumerWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final listCompany = useState<List<CompanyModel>>([
|
||||||
|
CompanyModel(companyid: "1", companyname: "SAS"),
|
||||||
|
CompanyModel(companyid: "2", companyname: "SIM")
|
||||||
|
]);
|
||||||
|
final isLoading = useState(false);
|
||||||
|
final selectedCompanyID = useState("0");
|
||||||
|
final selectedCompanyName = useState("");
|
||||||
|
final auth = ref.watch(currentUserProvider);
|
||||||
useEffect(() {
|
useEffect(() {
|
||||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
|
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
|
||||||
final userID = ref.read(currentUserProvider)?.model.M_UserID ?? "0";
|
final userID = ref.read(currentUserProvider)?.model.M_UserID ?? "0";
|
||||||
@@ -23,9 +38,29 @@ class ChangeCompanyScreen extends HookConsumerWidget {
|
|||||||
// Navigator.popAndPushNamed(context, loginRoute);
|
// Navigator.popAndPushNamed(context, loginRoute);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
ref.read(ListCompanyProvider.notifier).getListCompany(userID: userID);
|
||||||
});
|
});
|
||||||
return () {};
|
return () {};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
ref.listen(
|
||||||
|
ListCompanyProvider,
|
||||||
|
(previous, next) {
|
||||||
|
if (next is ListCompanyStateLoading) {
|
||||||
|
isLoading.value = true;
|
||||||
|
} else if (next is ListCompanyStateError) {
|
||||||
|
// print(next.message);
|
||||||
|
isLoading.value = false;
|
||||||
|
SanckbarWidget(context, next.message, snackbarType.error);
|
||||||
|
} else if (next is ListCompanyStateDone) {
|
||||||
|
print(jsonEncode(next.model));
|
||||||
|
// print(next.model.length);
|
||||||
|
listCompany.value = next.model;
|
||||||
|
selectedCompanyID.value = auth?.model.M_CompanyID ?? "0";
|
||||||
|
isLoading.value = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: EdgeInsets.only(
|
padding: EdgeInsets.only(
|
||||||
top: Constant.getActualYPhone(context: context, y: 30),
|
top: Constant.getActualYPhone(context: context, y: 30),
|
||||||
@@ -43,7 +78,131 @@ class ChangeCompanyScreen extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
drawer: CustomDrawer(),
|
drawer: CustomDrawer(),
|
||||||
body: Text('Under Construction'),
|
body: SingleChildScrollView(
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.all(20),
|
||||||
|
child: isLoading.value
|
||||||
|
? Container(
|
||||||
|
height: MediaQuery.of(context).size.height,
|
||||||
|
child: Center(
|
||||||
|
child: CircularProgressIndicator(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: Column(
|
||||||
|
children: listCompany.value
|
||||||
|
.map((e) => Container(
|
||||||
|
margin: EdgeInsets.only(bottom: 20),
|
||||||
|
child: InkWell(
|
||||||
|
onTap: () async {
|
||||||
|
selectedCompanyID.value = e.companyid ?? "0";
|
||||||
|
selectedCompanyName.value =
|
||||||
|
e.companyname ?? "0";
|
||||||
|
final shared =
|
||||||
|
await SharedPreferences.getInstance();
|
||||||
|
final oldData = jsonDecode(
|
||||||
|
shared.getString(Constant.bearerName) ??
|
||||||
|
"");
|
||||||
|
print(oldData['token']);
|
||||||
|
|
||||||
|
final newModel = AuthDoctorModel.fromJson(
|
||||||
|
oldData['model']);
|
||||||
|
newModel.M_CompanyID = e.companyid ?? "0";
|
||||||
|
newModel.M_CompanyName = e.companyname ?? "";
|
||||||
|
final token = jsonEncode({
|
||||||
|
"date": oldData['date'],
|
||||||
|
"model": newModel,
|
||||||
|
"token": oldData['token']
|
||||||
|
});
|
||||||
|
final newAuthData = AuthModel(
|
||||||
|
token: oldData['token'], model: newModel);
|
||||||
|
await shared.setString(
|
||||||
|
Constant.bearerName, token);
|
||||||
|
ref.read(currentUserProvider.notifier).state =
|
||||||
|
newAuthData;
|
||||||
|
Navigator.pushNamed(context, homeRoute);
|
||||||
|
},
|
||||||
|
child: Card(
|
||||||
|
shadowColor:
|
||||||
|
selectedCompanyID.value == e.companyid
|
||||||
|
? Constant.bgIconHistory
|
||||||
|
: Colors.white,
|
||||||
|
surfaceTintColor:
|
||||||
|
selectedCompanyID.value == e.companyid
|
||||||
|
? Constant.bgIconHistory
|
||||||
|
: Colors.white,
|
||||||
|
// elevation: selectedCompanyID.value == e.companyid
|
||||||
|
// ? 0
|
||||||
|
// : 1,
|
||||||
|
elevation: 10,
|
||||||
|
color: selectedCompanyID.value == e.companyid
|
||||||
|
? Constant.bgIconHistory
|
||||||
|
: Colors.white,
|
||||||
|
child: Container(
|
||||||
|
padding: EdgeInsets.all(20),
|
||||||
|
width: MediaQuery.of(context).size.width,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
flex: 1,
|
||||||
|
child: Icon(
|
||||||
|
Icons.corporate_fare,
|
||||||
|
color:
|
||||||
|
selectedCompanyID.value ==
|
||||||
|
e.companyid
|
||||||
|
? Constant.textRed
|
||||||
|
: Colors.black,
|
||||||
|
size: 30,
|
||||||
|
)),
|
||||||
|
SizedBox(
|
||||||
|
width: 10,
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
flex: 8,
|
||||||
|
child: Text(e.companyname ?? "",
|
||||||
|
softWrap: true,
|
||||||
|
maxLines: 3,
|
||||||
|
// overflow: ,
|
||||||
|
style: Constant.body1(
|
||||||
|
context: context)
|
||||||
|
.copyWith(
|
||||||
|
color: selectedCompanyID
|
||||||
|
.value ==
|
||||||
|
e.companyid
|
||||||
|
? Constant.textRed
|
||||||
|
: Colors.black,
|
||||||
|
fontSize: 25)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.toList()
|
||||||
|
// [
|
||||||
|
// Card(
|
||||||
|
// shadowColor: Colors.white,
|
||||||
|
// // surfaceTintColor: Colors.white,
|
||||||
|
// elevation: 0,
|
||||||
|
// color: Constant.bgIconHistory,
|
||||||
|
// child: Container(
|
||||||
|
// padding: EdgeInsets.all(10),
|
||||||
|
// width: MediaQuery.of(context).size.width,
|
||||||
|
// child: Row(
|
||||||
|
// children: [
|
||||||
|
// Icon(Icons.corporate_fare),
|
||||||
|
// SizedBox(
|
||||||
|
// width: 10,
|
||||||
|
// ),
|
||||||
|
// Text("Company",
|
||||||
|
// style: Constant.body1(context: context)
|
||||||
|
// .copyWith(color: Constant.textRed)),
|
||||||
|
// ],
|
||||||
|
// )),
|
||||||
|
// )
|
||||||
|
// ],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
import 'package:app_petty_cash/model/company_model.dart';
|
||||||
|
import 'package:app_petty_cash/repository/company_repository.dart';
|
||||||
|
|
||||||
|
import '../../model/list_category_model.dart';
|
||||||
|
import '../../repository/transaksi_repository.dart';
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
|
||||||
|
import '../../provider/dio_provider.dart';
|
||||||
|
import '../../repository/base_repository.dart';
|
||||||
|
|
||||||
|
abstract class ListCompanyState extends Equatable {
|
||||||
|
final DateTime date;
|
||||||
|
const ListCompanyState(this.date);
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [date];
|
||||||
|
}
|
||||||
|
|
||||||
|
class ListCompanyStateInit extends ListCompanyState {
|
||||||
|
ListCompanyStateInit() : super(DateTime.now());
|
||||||
|
}
|
||||||
|
|
||||||
|
class ListCompanyStateLoading extends ListCompanyState {
|
||||||
|
ListCompanyStateLoading() : super(DateTime.now());
|
||||||
|
}
|
||||||
|
|
||||||
|
class ListCompanyStateError extends ListCompanyState {
|
||||||
|
final String message;
|
||||||
|
ListCompanyStateError({
|
||||||
|
required this.message,
|
||||||
|
}) : super(DateTime.now());
|
||||||
|
}
|
||||||
|
|
||||||
|
class ListCompanyStateDone extends ListCompanyState {
|
||||||
|
final List<CompanyModel> model;
|
||||||
|
ListCompanyStateDone({
|
||||||
|
required this.model,
|
||||||
|
}) : super(DateTime.now());
|
||||||
|
}
|
||||||
|
|
||||||
|
//notifier
|
||||||
|
class ListCompanyNotifier extends StateNotifier<ListCompanyState> {
|
||||||
|
final Ref ref;
|
||||||
|
ListCompanyNotifier({
|
||||||
|
required this.ref,
|
||||||
|
}) : super(ListCompanyStateInit());
|
||||||
|
|
||||||
|
void getListCompany({required String userID}) async {
|
||||||
|
try {
|
||||||
|
state = ListCompanyStateLoading();
|
||||||
|
final dio = ref.read(dioProvider);
|
||||||
|
final resp =
|
||||||
|
await CompanyRepository(dio: dio).getListCompany(userID: userID);
|
||||||
|
state = ListCompanyStateDone(model: resp);
|
||||||
|
} catch (e) {
|
||||||
|
if (e is BaseRepositoryException) {
|
||||||
|
state = ListCompanyStateError(message: e.message.toString());
|
||||||
|
} else {
|
||||||
|
state = ListCompanyStateError(message: e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//provider
|
||||||
|
final ListCompanyProvider =
|
||||||
|
StateNotifierProvider<ListCompanyNotifier, ListCompanyState>(
|
||||||
|
(ref) => ListCompanyNotifier(ref: ref),
|
||||||
|
);
|
||||||
@@ -85,10 +85,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: collection
|
name: collection
|
||||||
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
|
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.17.1"
|
version: "1.18.0"
|
||||||
convert:
|
convert:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -436,26 +436,26 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: matcher
|
name: matcher
|
||||||
sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
|
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.12.15"
|
version: "0.12.16"
|
||||||
material_color_utilities:
|
material_color_utilities:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: material_color_utilities
|
name: material_color_utilities
|
||||||
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
|
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.2.0"
|
version: "0.5.0"
|
||||||
meta:
|
meta:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: meta
|
name: meta
|
||||||
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
|
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.9.1"
|
version: "1.10.0"
|
||||||
mime:
|
mime:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@@ -689,18 +689,18 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: source_span
|
name: source_span
|
||||||
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
|
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.9.1"
|
version: "1.10.0"
|
||||||
stack_trace:
|
stack_trace:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: stack_trace
|
name: stack_trace
|
||||||
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
|
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.11.0"
|
version: "1.11.1"
|
||||||
state_notifier:
|
state_notifier:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -713,10 +713,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: stream_channel
|
name: stream_channel
|
||||||
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
|
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.1"
|
version: "2.1.2"
|
||||||
string_scanner:
|
string_scanner:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -737,10 +737,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: test_api
|
name: test_api
|
||||||
sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
|
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.5.1"
|
version: "0.6.1"
|
||||||
top_snackbar_flutter:
|
top_snackbar_flutter:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@@ -893,6 +893,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.17"
|
version: "2.0.17"
|
||||||
|
web:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: web
|
||||||
|
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "0.3.0"
|
||||||
win32:
|
win32:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -926,5 +934,5 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "3.1.2"
|
version: "3.1.2"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=3.0.6 <4.0.0"
|
dart: ">=3.2.0-194.0.dev <4.0.0"
|
||||||
flutter: ">=3.10.0"
|
flutter: ">=3.10.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user