slight change on add tim survei to add relation with caleg
This commit is contained in:
25
lib/app/app.bottomsheets.dart
Normal file
25
lib/app/app.bottomsheets.dart
Normal file
@ -0,0 +1,25 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// **************************************************************************
|
||||
// StackedBottomsheetGenerator
|
||||
// **************************************************************************
|
||||
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
|
||||
import 'app.locator.dart';
|
||||
import '../ui/views/admin_index_tracking/halaman_caleg/coba_bottom_sheet/coba_bottom_sheet_view.dart';
|
||||
|
||||
enum BottomSheetType {
|
||||
cobaBottomSheetView,
|
||||
}
|
||||
|
||||
void setupBottomSheetUi() {
|
||||
final bottomsheetService = locator<BottomSheetService>();
|
||||
|
||||
final Map<BottomSheetType, SheetBuilder> builders = {
|
||||
BottomSheetType.cobaBottomSheetView: (context, request, completer) =>
|
||||
CobaBottomSheetView(request: request, completer: completer),
|
||||
};
|
||||
|
||||
bottomsheetService.setCustomSheetBuilders(builders);
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
import 'package:cek_suara/ui/views/admin_index_tracking/halaman_caleg/coba_bottom_sheet/coba_bottom_sheet_view.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
import 'package:stacked/stacked_annotations.dart';
|
||||
|
||||
@ -46,6 +47,9 @@ import '../ui/views/splash_screen/splash_screen_view.dart';
|
||||
StackedDialog(classType: TambahEditCalegView),
|
||||
StackedDialog(classType: TambahDetailTimSurveiView)
|
||||
],
|
||||
bottomsheets: [
|
||||
StackedBottomsheet(classType: CobaBottomSheetView),
|
||||
],
|
||||
dependencies: [
|
||||
LazySingleton(classType: NavigationService),
|
||||
LazySingleton(classType: DialogService),
|
||||
|
@ -25,7 +25,7 @@ class CustomBaseViewModel extends BaseViewModel {
|
||||
}
|
||||
|
||||
quitApp(BuildContext context) {
|
||||
globalVar.backPressed = 'cantBack';
|
||||
// globalVar.backPressed = 'cantBack';
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
|
@ -3,6 +3,7 @@ import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
|
||||
import 'app/app.bottomsheets.dart';
|
||||
import 'app/app.dialogs.dart';
|
||||
import 'app/app.locator.dart';
|
||||
import 'app/app.router.dart';
|
||||
@ -10,8 +11,12 @@ import 'app/themes/app_theme.dart';
|
||||
|
||||
Future main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await dotenv.load(fileName: ".env");
|
||||
await setupAllLocator();
|
||||
await Future.wait([
|
||||
dotenv.load(fileName: ".env"),
|
||||
setupAllLocator(),
|
||||
]);
|
||||
// await dotenv.load(fileName: ".env");
|
||||
// await setupAllLocator();
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
@ -35,6 +40,6 @@ class MyApp extends StatelessWidget {
|
||||
Future<void> setupAllLocator() async {
|
||||
await setupLocator();
|
||||
setupDialogUi();
|
||||
// setupBottomsheetUi();
|
||||
setupBottomSheetUi();
|
||||
// setupSnackbarUi();
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ class TimSurveiModel {
|
||||
final myFunction = locator<MyFunction>();
|
||||
String? nik;
|
||||
String? nama;
|
||||
int? idCaleg;
|
||||
String? namaCaleg;
|
||||
String? createdAt;
|
||||
|
||||
TimSurveiModel({this.nik, this.nama, this.createdAt});
|
||||
@ -38,6 +40,8 @@ class TimSurveiModel {
|
||||
TimSurveiModel.fromJson(Map<String, dynamic> json) {
|
||||
nik = json['nik'];
|
||||
nama = json['nama'];
|
||||
idCaleg = json['id_caleg'];
|
||||
namaCaleg = json['nama_caleg'];
|
||||
createdAt = myFunction.convertDateTime(json['created_at']);
|
||||
}
|
||||
|
||||
@ -45,6 +49,8 @@ class TimSurveiModel {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
data['nik'] = nik;
|
||||
data['nama'] = nama;
|
||||
data['id_caleg'] = idCaleg;
|
||||
data['nama_caleg'] = namaCaleg;
|
||||
data['created_at'] = createdAt;
|
||||
return data;
|
||||
}
|
||||
|
@ -63,6 +63,8 @@ class HalamanAreaViewModel extends CustomBaseViewModel {
|
||||
var response = await httpService.postWithFormData('area', formData);
|
||||
log.i(response.data);
|
||||
await getData();
|
||||
// reset form
|
||||
namaAreaController.clear();
|
||||
return true;
|
||||
} catch (e) {
|
||||
log.e(e);
|
||||
|
@ -0,0 +1,44 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
|
||||
import './coba_bottom_sheet_view_model.dart';
|
||||
|
||||
class CobaBottomSheetView extends StatelessWidget {
|
||||
final SheetRequest? request;
|
||||
final Function(SheetResponse)? completer;
|
||||
|
||||
const CobaBottomSheetView({
|
||||
Key? key,
|
||||
this.request,
|
||||
this.completer,
|
||||
}) : super(key: key);
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<CobaBottomSheetViewModel>.reactive(
|
||||
viewModelBuilder: () => CobaBottomSheetViewModel(),
|
||||
onViewModelReady: (CobaBottomSheetViewModel model) async {
|
||||
await model.init();
|
||||
},
|
||||
builder: (
|
||||
BuildContext context,
|
||||
CobaBottomSheetViewModel model,
|
||||
Widget? child,
|
||||
) {
|
||||
return SafeArea(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(20),
|
||||
topRight: Radius.circular(20),
|
||||
),
|
||||
),
|
||||
child: const Text('Coba Bottom Sheet'),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
import 'package:cek_suara/app/core/custom_base_view_model.dart';
|
||||
|
||||
class CobaBottomSheetViewModel extends CustomBaseViewModel {
|
||||
Future<void> init() async {}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
import 'package:cek_suara/app/themes/app_colors.dart';
|
||||
|
||||
// import '../../../../app/app.bottomsheets.dart';
|
||||
import '../../../../app/app.dialogs.dart';
|
||||
import '../../../../app/app.logger.dart';
|
||||
import '../../../../app/core/custom_base_view_model.dart';
|
||||
@ -46,6 +47,10 @@ class HalamanCalegViewModel extends CustomBaseViewModel {
|
||||
|
||||
addCaleg() async {
|
||||
// log.i('addCaleg');
|
||||
// await bottomSheetService.showCustomSheet(
|
||||
// variant: BottomSheetType.cobaBottomSheetView,
|
||||
// title: 'Tambah Caleg',
|
||||
// );
|
||||
var res = await dialogService.showCustomDialog(
|
||||
variant: DialogType.tambahEditCalegView,
|
||||
title: 'Tambah Caleg',
|
||||
|
@ -75,6 +75,71 @@ class TambahDetailTimSurveiView extends StatelessWidget {
|
||||
'Nama Tim Survei tidak boleh kosong'),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
if (model.timSurveiModel == null)
|
||||
Column(
|
||||
children: [
|
||||
const Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
' Pilih Caleg',
|
||||
),
|
||||
),
|
||||
if (model.isBusy)
|
||||
const LinearProgressIndicator(
|
||||
minHeight: 5,
|
||||
color: mainColor,
|
||||
),
|
||||
if (!model.isBusy && model.listCalegModel.isNotEmpty)
|
||||
Container(
|
||||
width: double.infinity,
|
||||
height: 60,
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 10),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
border: Border.all(
|
||||
color: sixthGrey,
|
||||
),
|
||||
),
|
||||
child: Expanded(
|
||||
child: DropdownButtonHideUnderline(
|
||||
child: DropdownButton<String>(
|
||||
isExpanded: true,
|
||||
value: model.selectedCaleg!,
|
||||
icon: const Icon(Icons.arrow_drop_down),
|
||||
iconSize: 24,
|
||||
elevation: 16,
|
||||
style:
|
||||
const TextStyle(color: Colors.black),
|
||||
onChanged: (String? newValue) {
|
||||
model.log.i(newValue);
|
||||
model.selectedCaleg = newValue!;
|
||||
model.selectedCalegId = model
|
||||
.listCalegModel
|
||||
.firstWhere((element) =>
|
||||
element.namaCaleg ==
|
||||
model.selectedCaleg)
|
||||
.idCaleg;
|
||||
|
||||
model.log.i(model.selectedCalegId);
|
||||
|
||||
model.notifyListeners();
|
||||
},
|
||||
items: model.listCalegString
|
||||
.map<DropdownMenuItem<String>>(
|
||||
(String value) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: value,
|
||||
child: Text(value,
|
||||
overflow: TextOverflow.ellipsis),
|
||||
);
|
||||
}).toList()),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
),
|
||||
if (model.timSurveiModel == null)
|
||||
SizedBox(
|
||||
width: 200,
|
||||
@ -103,6 +168,15 @@ class TambahDetailTimSurveiView extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
if (model.timSurveiModel != null)
|
||||
Column(
|
||||
children: [
|
||||
MyTextFormField(
|
||||
labelText: 'Caleg',
|
||||
hintText: 'Caleg',
|
||||
readOnly: true,
|
||||
controller: model.namaCalegController,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
@ -144,6 +218,8 @@ class TambahDetailTimSurveiView extends StatelessWidget {
|
||||
)
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -1,9 +1,10 @@
|
||||
import 'package:cek_suara/model/tim_survei_model.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../../app/app.logger.dart';
|
||||
import '../../../../../app/core/custom_base_view_model.dart';
|
||||
import '../../../../../model/caleg_model.dart';
|
||||
import '../../../../../model/tim_survei_model.dart';
|
||||
|
||||
class TambahDetailTimSurveiViewModel extends CustomBaseViewModel {
|
||||
final log = getLogger('TambahDetailTimSurveiViewModel');
|
||||
@ -12,15 +13,45 @@ class TambahDetailTimSurveiViewModel extends CustomBaseViewModel {
|
||||
final formKey = GlobalKey<FormState>();
|
||||
TextEditingController nikController = TextEditingController();
|
||||
TextEditingController namaController = TextEditingController();
|
||||
TextEditingController namaCalegController = TextEditingController();
|
||||
|
||||
TimSurveiModel? timSurveiModel;
|
||||
|
||||
// list caleg
|
||||
List<CalegModel> listCalegModel = [];
|
||||
List<String> listCalegString = [];
|
||||
String? selectedCaleg;
|
||||
int? selectedCalegId;
|
||||
|
||||
Future<void> init(data) async {
|
||||
globalVar.backPressed = 'exitApp';
|
||||
timSurveiModel = data;
|
||||
if (timSurveiModel != null) {
|
||||
nikController.text = timSurveiModel!.nik!;
|
||||
namaController.text = timSurveiModel!.nama!;
|
||||
namaCalegController.text = timSurveiModel!.namaCaleg!;
|
||||
} else {
|
||||
await getData();
|
||||
}
|
||||
}
|
||||
|
||||
getData() async {
|
||||
setBusy(true);
|
||||
try {
|
||||
var response = await httpService.get('caleg');
|
||||
// log.i(response.data);
|
||||
CalegListModel calegListModel =
|
||||
CalegListModel.fromJson(response.data['data']);
|
||||
listCalegModel = calegListModel.caleg!;
|
||||
for (var element in listCalegModel) {
|
||||
listCalegString.add(element.namaCaleg!);
|
||||
}
|
||||
selectedCaleg = listCalegString[0];
|
||||
selectedCalegId = listCalegModel[0].idCaleg;
|
||||
} catch (e) {
|
||||
log.e(e);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,6 +64,7 @@ class TambahDetailTimSurveiViewModel extends CustomBaseViewModel {
|
||||
var formData = FormData.fromMap({
|
||||
'nik': nikController.text,
|
||||
'nama': namaController.text,
|
||||
'id_caleg': selectedCalegId,
|
||||
});
|
||||
var response = await httpService.postWithFormData('survei', formData);
|
||||
log.i(response.data);
|
||||
|
@ -1,3 +1,4 @@
|
||||
import 'package:cek_suara/app/themes/app_text.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
@ -84,8 +85,21 @@ class TimSurveiView extends StatelessWidget {
|
||||
title: Text(
|
||||
model.listTimSurveiModel[i].nama!,
|
||||
),
|
||||
subtitle: Text(
|
||||
model.listTimSurveiModel[i].nik!,
|
||||
subtitle: Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
model.listTimSurveiModel[i]
|
||||
.nik!,
|
||||
style: italicTextStyle,
|
||||
),
|
||||
Text(
|
||||
model.listTimSurveiModel[i]
|
||||
.namaCaleg!,
|
||||
style: boldTextStyle,
|
||||
),
|
||||
],
|
||||
),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
|
@ -6,11 +6,9 @@ import FlutterMacOS
|
||||
import Foundation
|
||||
|
||||
import file_selector_macos
|
||||
import location
|
||||
import path_provider_foundation
|
||||
|
||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
|
||||
LocationPlugin.register(with: registry.registrar(forPlugin: "LocationPlugin"))
|
||||
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
||||
}
|
||||
|
32
pubspec.lock
32
pubspec.lock
@ -352,14 +352,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.2"
|
||||
google_fonts:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: google_fonts
|
||||
sha256: f0b8d115a13ecf827013ec9fc883390ccc0e87a96ed5347a3114cac177ef18e8
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.1.0"
|
||||
graphs:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -496,30 +488,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
location:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: location
|
||||
sha256: "9051959f6f2ccadd887b28b66e9cbbcc25b6838e37cf9e894c421ccc0ebf80b5"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.4.0"
|
||||
location_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: location_platform_interface
|
||||
sha256: "62eeaf1658e92e4459b727f55a3c328eccbac8ba043fa6d262ac5286ad48384c"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.3.0"
|
||||
location_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: location_web
|
||||
sha256: "6c08c408a040534c0269c4ff9fe17eebb5a36dea16512fbaf116b9c8bc21545b"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.1"
|
||||
logger:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -42,10 +42,10 @@ dependencies:
|
||||
path_provider: ^2.0.9
|
||||
dio:
|
||||
flutter_easyloading:
|
||||
location: ^4.4.0
|
||||
# location: ^4.4.0
|
||||
# flutter_inappwebview:
|
||||
# webview_flutter: ^3.0.4
|
||||
google_fonts:
|
||||
# google_fonts:
|
||||
# flutter_svg:
|
||||
stylish_bottom_bar:
|
||||
validatorless: ^1.2.3
|
||||
|
Reference in New Issue
Block a user