Initial commit
This commit is contained in:
105
lib/ui/views/penyewa_index/pulsa_detail/pulsa_detail_view.dart
Normal file
105
lib/ui/views/penyewa_index/pulsa_detail/pulsa_detail_view.dart
Normal file
@ -0,0 +1,105 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rfid_app/app/themes/app_text.dart';
|
||||
import 'package:rfid_app/ui/widgets/my_button.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
import '../../../../app/themes/app_colors.dart';
|
||||
import './pulsa_detail_view_model.dart';
|
||||
|
||||
class PulsaDetailView extends StatelessWidget {
|
||||
const PulsaDetailView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<PulsaDetailViewModel>.reactive(
|
||||
viewModelBuilder: () => PulsaDetailViewModel(),
|
||||
onViewModelReady: (PulsaDetailViewModel model) async {
|
||||
await model.init();
|
||||
},
|
||||
builder: (
|
||||
BuildContext context,
|
||||
PulsaDetailViewModel model,
|
||||
Widget? child,
|
||||
) {
|
||||
return Scaffold(
|
||||
body: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: mainColor,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
_RowChildren(
|
||||
title: 'NIK',
|
||||
value: model.detailPenyewaModel!.nik ?? '...',
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
_RowChildren(
|
||||
title: 'Nama',
|
||||
value: model.detailPenyewaModel!.nama ?? '...',
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
_RowChildren(
|
||||
title: 'Pulsa',
|
||||
value:
|
||||
'Rp. ${model.otherFunction.commaFormat(model.detailPenyewaModel!.saldo ?? 0)}',
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
_RowChildren(
|
||||
title: 'Card ID',
|
||||
value: model.detailPenyewaModel!.rfid ?? '...',
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
MyButton(text: 'Ganti Password')
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _RowChildren extends StatelessWidget {
|
||||
const _RowChildren({
|
||||
required this.title,
|
||||
required this.value,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final String value;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text(
|
||||
title,
|
||||
style: regularTextStyle,
|
||||
),
|
||||
),
|
||||
const Expanded(flex: 1, child: Text(':')),
|
||||
Expanded(
|
||||
flex: 5,
|
||||
child: Text(
|
||||
value,
|
||||
style: boldTextStyle,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
import '../../../../app/app.logger.dart';
|
||||
import '../../../../app/core/custom_base_view_model.dart';
|
||||
import '../../../../model/my_response_model.dart';
|
||||
import '../../../../model/penyewa_model.dart';
|
||||
|
||||
class PulsaDetailViewModel extends CustomBaseViewModel {
|
||||
final log = getLogger('PulsaDetailViewModel');
|
||||
String? nik;
|
||||
DetailPenyewaModel? detailPenyewaModel;
|
||||
Future<void> init() async {
|
||||
nik = await mySharedPrefs.getString('nik');
|
||||
await getData(nik);
|
||||
}
|
||||
|
||||
getData(String? nik) async {
|
||||
try {
|
||||
var response = await httpService.get('user/user/$nik');
|
||||
MyResponseModel myResponseModel = MyResponseModel.fromJson(response.data);
|
||||
detailPenyewaModel = DetailPenyewaModel.fromJson(myResponseModel.data);
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
log.e(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user