complete admin, mandor and user page

This commit is contained in:
kicap
2023-11-03 23:24:23 +08:00
parent 4cc9967ab8
commit 8eacfa6dee
41 changed files with 1335 additions and 492 deletions

View File

@ -1,69 +0,0 @@
import 'package:flutter/material.dart';
import 'package:stacked/stacked.dart';
import 'package:webview_flutter/webview_flutter.dart';
import './user_home_view_model.dart';
class UserHomeView extends StatelessWidget {
const UserHomeView({super.key});
@override
Widget build(BuildContext context) {
return ViewModelBuilder<UserHomeViewModel>.nonReactive(
viewModelBuilder: () => UserHomeViewModel(),
onViewModelReady: (UserHomeViewModel model) async {
await model.init();
},
disposeViewModel: false,
fireOnViewModelReadyOnce: true,
builder: (
BuildContext context,
UserHomeViewModel model,
Widget? child,
) {
return Scaffold(
body: WebView(
// initialUrl: 'http://192.168.43.125/rekam-medis',
initialUrl: 'http://20.20.20.25/perumahan',
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
// _controller.complete(webViewController);
model.webViewControllerCompleter.future
.then((value) => model.webVIewcontroller = value);
model.webViewControllerCompleter.complete(webViewController);
},
onProgress: (int progress) {
double progressDouble = progress / 100;
model.myEasyLoading.showProgress(progressDouble, "Loading Denah");
},
// javascriptChannels: <JavascriptChannel>{
// _toasterJavascriptChannel(context),
// },
javascriptChannels: <JavascriptChannel>{
JavascriptChannel(
name: 'messageHandler',
onMessageReceived: (JavascriptMessage message) {
model.log.d(message.message);
// dev.i("message from the web view=\"${message.message}\"");
// if (message.message == "coba") {
// dev.i("sini untuk coba");
// controller.runJavascript("coba22('heheheh')");
// }
},
),
},
// navigationDelegate: (NavigationRequest request) async {},
onPageStarted: (String url) {},
onPageFinished: (String url) {
// dev.i('Page finished loading: $url');
model.myEasyLoading.dismissLoading();
},
gestureNavigationEnabled: true,
backgroundColor: const Color(0x00000000),
),
);
},
);
}
}

View File

@ -1,25 +0,0 @@
import 'dart:async';
import 'dart:io';
import 'package:webview_flutter/webview_flutter.dart';
import '../../../../app/app.locator.dart';
import '../../../../app/app.logger.dart';
import '../../../../app/core/custom_base_view_model.dart';
import '../../../../services/my_easyloading.dart';
class UserHomeViewModel extends CustomBaseViewModel {
final log = getLogger('UserHomeViewModel');
final _myEasyLoading = locator<MyEasyLoading>();
get myEasyLoading => _myEasyLoading;
late WebViewController webVIewcontroller;
final Completer<WebViewController> webViewControllerCompleter =
Completer<WebViewController>();
Future<void> init() async {
if (Platform.isAndroid) {
WebView.platform = SurfaceAndroidWebView();
}
}
}

View File

@ -38,10 +38,22 @@ class UserIndexView extends StatelessWidget {
backgroundColor: mainColor,
elevation: 0,
automaticallyImplyLeading: false,
actions: [
// create logout button
IconButton(
onPressed: () {
model.logout();
},
icon: const Icon(
Icons.logout,
color: Colors.white,
),
),
],
),
// extendBody: true,
body: ExtendedNavigator(
navigatorKey: StackedService.nestedNavigationKey(2),
navigatorKey: StackedService.nestedNavigationKey(7),
router: UserIndexViewRouter(),
),
bottomNavigationBar: StylishBottomBar(

View File

@ -5,10 +5,14 @@ import 'package:stacked_services/stacked_services.dart';
import '../../../app/app.locator.dart';
import '../../../app/app.logger.dart';
import '../../../app/app.router.dart';
import '../../../services/shared_prefs.dart';
class UserIndexViewModel extends IndexTrackingViewModel {
final log = getLogger('UserIndexViewModel');
final _navigationService = locator<NavigationService>();
final _dialogService = locator<DialogService>();
final _mySharedPrefs = locator<MySharedPrefs>();
final _snackbarService = locator<SnackbarService>();
final _bottomNavBarList = [
{
@ -16,22 +20,18 @@ class UserIndexViewModel extends IndexTrackingViewModel {
'icon': Icons.list_alt_rounded,
'header': 'List Perumahan'
},
{'name': 'Denah', 'icon': Icons.home_outlined, 'header': 'Denah Perumahan'},
{'name': 'Profil', 'icon': Icons.person_outline, 'header': 'Profil'},
];
List<Map<String, dynamic>> get bottomNavBarList => _bottomNavBarList;
final List<String> _views = [
UserIndexViewRoutes.userListPembangunanView,
UserIndexViewRoutes.userHomeView,
UserIndexViewRoutes.userListPembangunanPageView,
UserIndexViewRoutes.userProfileView,
];
String header = 'Denah Perumahan';
Future<void> init() async {
setIndex(1);
}
Future<void> init() async {}
void handleNavigation(int index) {
log.d("handleNavigation: $index");
@ -43,7 +43,29 @@ class UserIndexViewModel extends IndexTrackingViewModel {
header = _bottomNavBarList[index]['header'] as String;
_navigationService.navigateTo(
_views[index],
id: 2,
id: 7,
);
}
logout() {
_dialogService
.showConfirmationDialog(
title: 'Logout',
description: 'Apakah Anda yakin ingin logout?',
cancelTitle: 'Batal',
confirmationTitle: 'Logout',
)
.then((value) async {
if (value!.confirmed) {
await _mySharedPrefs.clear();
_navigationService.clearStackAndShow(Routes.loginScreenView);
_snackbarService.showSnackbar(
message: 'Logout berhasil',
duration: const Duration(seconds: 2),
);
}
});
// await _mySharedPrefs.clear();
// _navigationService.clearStackAndShow(Routes.loginScreenView);
}
}

View File

@ -0,0 +1,26 @@
import 'package:flutter/material.dart';
import 'package:perumahan_bew/ui/views/user_index/user_list_pembangunan/user_list_pembangunan_view.dart';
import 'package:stacked/stacked.dart';
import './user_list_pembangunan_page_view_model.dart';
class UserListPembangunanPageView extends StatelessWidget {
const UserListPembangunanPageView({super.key});
@override
Widget build(BuildContext context) {
return ViewModelBuilder<UserListPembangunanPageViewModel>.nonReactive(
viewModelBuilder: () => UserListPembangunanPageViewModel(),
onViewModelReady: (UserListPembangunanPageViewModel model) async {
await model.init();
},
builder: (
BuildContext context,
UserListPembangunanPageViewModel model,
Widget? child,
) {
return const UserListPembangunanView();
},
);
}
}

View File

@ -0,0 +1,5 @@
import 'package:perumahan_bew/app/core/custom_base_view_model.dart';
class UserListPembangunanPageViewModel extends CustomBaseViewModel {
Future<void> init() async {}
}

View File

@ -25,24 +25,14 @@ class UserListPembangunanView extends StatelessWidget {
body: Column(
children: [
const SizedBox(height: 20),
const Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
MyTopWidget(
icon: Icons.list_alt_outlined,
title: 'Pembangunan',
subtitle: '15 kali',
// lastUpdate: '31/02/15 - 10.00 am',
),
MyTopWidget(
icon: Icons.home,
title: 'Progress',
subtitle: '76 %',
// lastUpdate: '31/02/15 - 10.00 am',
),
],
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: MyTopWidget(
icon: Icons.list_alt_outlined,
title: 'Pembangunan',
subtitle:
'${model.listProgress != null ? model.listProgress!.length : 0} Progress',
// lastUpdate: '31/02/15 - 10.00 am',
),
),
const SizedBox(height: 25),
@ -63,27 +53,47 @@ class UserListPembangunanView extends StatelessWidget {
],
),
// create a listview with 20 dummy data on card and scrollable
child: ListView.builder(
padding: const EdgeInsets.symmetric(
horizontal: 10, vertical: 10),
itemCount: 20,
itemBuilder: (context, index) {
return Card(
child: GestureDetector(
onTap: () {
model.log.i('Card $index tapped');
},
child: ListTile(
title: Text('1/02/15 - 10.00 am',
style: boldTextStyle.copyWith(
fontSize: 13, color: mainColor)),
subtitle: Text('Progress $index'),
trailing: Text('Pembangunan $index'),
),
),
);
},
)),
child: model.isBusy
? const Center(child: CircularProgressIndicator())
: model.status == false
? const Center(child: Text('Error Loading Data'))
: model.listProgress!.isEmpty
? const Center(child: Text('Data Kosong'))
: ListView.builder(
padding: const EdgeInsets.symmetric(
horizontal: 10, vertical: 10),
itemCount: model.listProgress!.length,
itemBuilder: (context, index) {
return Card(
child: ListTile(
title: Text(
model.listProgress![index]
.createdAt!,
style: boldTextStyle.copyWith(
fontSize: 13,
color: mainColor,
),
),
subtitle: Text(model
.listProgress![index].ket!),
// create icon show
trailing: CircleAvatar(
backgroundColor: mainColor,
child: IconButton(
icon: const Icon(
Icons.list_alt_outlined,
color: backgroundColor,
),
onPressed: () {
model.checkProgress(model
.listProgress![index]);
},
),
),
),
);
},
)),
),
),
const SizedBox(height: 20),

View File

@ -1,8 +1,52 @@
import 'package:perumahan_bew/app/core/custom_base_view_model.dart';
import 'package:perumahan_bew/model/rumah_model.dart';
import '../../../../app/app.bottomsheets.dart';
import '../../../../app/app.logger.dart';
import '../../../../app/core/custom_base_view_model.dart';
import '../../../../model/my_response_model.dart';
class UserListPembangunanViewModel extends CustomBaseViewModel {
final log = getLogger('UserListPembangunanViewModel');
Future<void> init() async {}
bool status = false;
RumahDetailModel? rumahDetailModel;
RumahModel? rumahModel;
List<ProgressModel>? listProgress;
Future<void> init() async {
String idRumah = await mySharedPrefs.getString('id') ?? '';
if (idRumah.isNotEmpty) {
await getData(idRumah);
}
}
getData(String idRumah) async {
setBusy(true);
try {
var response = await httpService.get('rumah?id=$idRumah');
MyResponseModel myResponse = MyResponseModel.fromJson(response.data);
// log.i(myResponse.toJson());
RumahDetailModel rumahDetailModel =
RumahDetailModel.fromJson(myResponse.data);
listProgress = rumahDetailModel.progressModel;
status = true;
} catch (e) {
status = false;
log.e(e);
} finally {
setBusy(false);
}
}
checkProgress(ProgressModel progressModel) async {
await bottomSheetService.showCustomSheet(
variant: BottomSheetType.tambahLihatProgressBottomSheetView,
title: 'Lihat Progress',
data: {
'idPerumahan': progressModel.idRumah,
'progressModel': progressModel,
},
);
}
}

View File

@ -21,99 +21,118 @@ class UserProfileView extends StatelessWidget {
Widget? child,
) {
return Scaffold(
body: Stack(
children: [
Column(
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(20),
child: Stack(
children: [
const SizedBox(
height: 25,
),
// create a rounded container
Center(
child: Container(
width: 150,
height: 150,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: const NetworkImage(
'http://kicap-karan.com/assets/img/me.jpg',
),
fit: BoxFit.cover,
onError: (exception, stackTrace) {
model.log.e('Error: $exception');
},
),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.5),
spreadRadius: 2,
blurRadius: 7,
offset: const Offset(0, 3),
),
],
),
),
),
const SizedBox(
height: 15,
),
Center(
child: Text(
'Kicap Karan',
style: boldTextStyle.copyWith(
fontSize: 18,
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 30, vertical: 10),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
Column(
children: [
// create a rounded container
Center(
child: Stack(
children: [
for (var i = 0; i < 10; i++) const _DetailChild(),
const CircleAvatar(
radius: 50,
backgroundColor: fontParagraphColor,
// child: model.imageBytes == null
// ? const Icon(
// Icons.person,
// size: 50,
// color: Colors.white,
// )
// : ClipRRect(
// borderRadius: BorderRadius.circular(50),
// child: Image.memory(
// model.imageBytes!,
// width: 100,
// height: 100,
// fit: BoxFit.cover,
// ),
// ),
child: Icon(
Icons.person,
size: 50,
color: Colors.white,
),
),
Positioned(
bottom: 0,
right: 0,
child: CircleAvatar(
radius: 15,
backgroundColor: mainColor,
child: IconButton(
onPressed: () {
// model.addImage();
},
icon: const Icon(
Icons.add,
color: fontColor,
size: 15,
)),
),
),
],
),
),
),
if (!model.isBusy &&
model.status == true &&
model.rumahModel != null)
Expanded(
child: Column(
children: [
const SizedBox(
height: 15,
),
_DetailChild(
text: model.rumahModel!.pemilik!,
icon: Icons.person,
),
_DetailChild(
text: model.rumahModel!.tanggalPembelian!,
icon: Icons.calendar_today_outlined,
),
_DetailChild(
text: "Rp. ${model.rumahModel!.harga!}",
icon: Icons.attach_money_outlined,
),
_DetailChild(
text: 'Rp. ${model.rumahModel!.cicilan!}',
icon: Icons.money_outlined,
),
],
),
),
if (model.isBusy)
const Expanded(
child: Center(
child: CircularProgressIndicator(),
),
),
],
),
const SizedBox(
height: 15,
// create rounded button with edit on top right
Positioned(
top: 0,
right: 0,
child: CircleAvatar(
radius: 15,
backgroundColor: mainColor,
child: IconButton(
onPressed: () {
// model.addImage();
},
icon: const Icon(
Icons.edit,
color: fontColor,
size: 15,
)),
),
),
],
),
Positioned(
top: 15,
right: 65,
child: IconButton(
onPressed: () {
model.log.i('Edit Profile');
},
icon: const Icon(
Icons.edit,
color: mainColor,
size: 30,
),
),
),
Positioned(
top: 15,
right: 15,
child: IconButton(
onPressed: () {
model.log.i('Logout');
model.logout();
},
icon: const Icon(
Icons.logout,
color: mainColor,
size: 30,
),
)),
],
),
),
);
},
@ -124,8 +143,13 @@ class UserProfileView extends StatelessWidget {
class _DetailChild extends StatelessWidget {
const _DetailChild({
Key? key,
required this.text,
required this.icon,
}) : super(key: key);
final String text;
final IconData icon;
@override
Widget build(BuildContext context) {
return Padding(
@ -133,8 +157,8 @@ class _DetailChild extends StatelessWidget {
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
const Icon(
Icons.maps_home_work_outlined,
Icon(
icon,
color: mainColor,
size: 40,
),
@ -142,7 +166,7 @@ class _DetailChild extends StatelessWidget {
width: 20,
),
Text(
'Jln 2, Blok C, No 2',
text,
style: regularTextStyle.copyWith(
fontSize: 15,
color: mainGrey,

View File

@ -1,11 +1,43 @@
import 'package:perumahan_bew/app/core/custom_base_view_model.dart';
import '../../../../app/app.logger.dart';
import '../../../../model/my_response_model.dart';
import '../../../../model/rumah_model.dart';
class UserProfileViewModel extends CustomBaseViewModel {
final log = getLogger('UserProfileViewModel');
RumahDetailModel? rumahDetailModel;
RumahModel? rumahModel;
bool status = false;
String? idRumah;
Future<void> init() async {}
Future<void> init() async {
idRumah = await mySharedPrefs.getString('id') ?? '';
if (idRumah != '') {
await getData();
}
// await getData();
}
getData() async {
setBusy(true);
try {
var response = await httpService.get('rumah?id=$idRumah');
MyResponseModel myResponseModel = MyResponseModel.fromJson(response.data);
// log.i('myResponseModel: ${myResponseModel.data}');
rumahDetailModel = RumahDetailModel.fromJson(myResponseModel.data);
rumahModel = rumahDetailModel!.rumahModel;
// rumahModel = RumahModel.fromJson(myResponseModel.data);
log.i('rumahModel: ${rumahModel!.toJson()}');
status = true;
} catch (e) {
log.e('Error: $e');
status = false;
} finally {
setBusy(false);
}
}
logout() {
log.i('logout');