first commit

This commit is contained in:
kicap
2024-02-04 20:57:23 +08:00
commit 27c529dad9
162 changed files with 8557 additions and 0 deletions

View File

@ -0,0 +1,82 @@
import 'package:flutter/material.dart';
import 'package:kamus_kesehatan/ui/widgets/my_textformfield.dart';
import 'package:stacked/stacked.dart';
import 'package:stacked_services/stacked_services.dart';
import 'package:validatorless/validatorless.dart';
import './nomor_telpon_dialog_view_model.dart';
class NomorTelponDialogView extends StatelessWidget {
final DialogRequest? request;
final Function(DialogResponse)? completer;
const NomorTelponDialogView({
Key? key,
this.request,
this.completer,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return ViewModelBuilder<NomorTelponDialogViewModel>.reactive(
viewModelBuilder: () => NomorTelponDialogViewModel(),
onViewModelReady: (NomorTelponDialogViewModel model) async {
await model.init(request!.data);
},
builder: (
BuildContext context,
NomorTelponDialogViewModel model,
Widget? child,
) {
return Dialog(
child: Container(
padding: const EdgeInsets.all(20),
child: Form(
key: model.formKey,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
MyTextFormField(
controller: model.nomorTelponController,
hintText: 'Nomor Telpon',
keyboardType: TextInputType.phone,
maxLength: 13,
validator: Validatorless.multiple([
Validatorless.required(
'Nomor Telpon tidak boleh kosong'),
Validatorless.number('Nomor Telpon harus angka'),
Validatorless.min(10, 'Nomor Telpon minimal 10 digit'),
Validatorless.regex(
RegExp(r'^[0-9]*$'), 'Nomor Telpon tidak valid')
])),
const SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: () =>
completer!(DialogResponse(confirmed: false)),
child: const Text(
'Batal',
style: TextStyle(color: Colors.red),
),
),
TextButton(
onPressed: () {
if (model.formKey.currentState!.validate()) {
model.openWhatsapp();
}
},
child: const Text('Share'),
),
],
),
],
),
),
),
);
},
);
}
}

View File

@ -0,0 +1,38 @@
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import '../../../app/app.logger.dart';
import '../../../app/core/custom_base_view_model.dart';
import '../../../model/istilah_model.dart';
class NomorTelponDialogViewModel extends CustomBaseViewModel {
final log = getLogger('NomorTelponDialogViewModel');
TextEditingController nomorTelponController = TextEditingController();
final formKey = GlobalKey<FormState>();
IstilahModel? data;
Future<void> init(IstilahModel data) async {
log.i('init');
log.i(data.istilah.toString());
log.i(data.arti.toString());
this.data = data;
// await myStorage.clear();
}
openWhatsapp() async {
// open whatsapp using url
String noTelpon = nomorTelponController.text;
// convert the number to international format
noTelpon = noTelpon.replaceAll(RegExp(r'[^0-9]'), '');
noTelpon = '62${noTelpon.substring(1)}';
log.i('no_telpon: $noTelpon');
// add the data to url with query parameter
final url = Uri.parse('https://wa.me/$noTelpon?text=Kamus Medis : \n'
'Istilah : ${data!.istilah}\n'
'Arti : ${data!.arti}');
if (!await launchUrl(url)) {
throw Exception('Could not launch $url');
}
}
}