change the main list to row
This commit is contained in:
@ -0,0 +1,107 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:kamus_kesehatan/app/themes/app_text.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
import '../list_detail_istilah/list_detail_istilah_view.dart';
|
||||
import './halaman_utama_view_model.dart';
|
||||
|
||||
class HalamanUtamaView extends StatelessWidget {
|
||||
const HalamanUtamaView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<HalamanUtamaViewModel>.reactive(
|
||||
viewModelBuilder: () => HalamanUtamaViewModel(),
|
||||
onViewModelReady: (HalamanUtamaViewModel model) async {
|
||||
await model.init();
|
||||
},
|
||||
builder: (
|
||||
BuildContext context,
|
||||
HalamanUtamaViewModel model,
|
||||
Widget? child,
|
||||
) {
|
||||
return Scaffold(
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
for (var element in model.kategoriIstilah)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 20),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
model.navigationService
|
||||
.navigateToView(ListDetailIstilahView(
|
||||
kategori: element['kategori'],
|
||||
));
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
color: element['color'],
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
element['icon'],
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
model.myFunction
|
||||
.capitalize(element['kategori']),
|
||||
style: boldTextStyle.copyWith(
|
||||
color: Colors.white,
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
if (element['kategori'] == 'anggota tubuh')
|
||||
ForCount(
|
||||
count: model.anggotaTubuhCount.toString()),
|
||||
if (element['kategori'] == 'penyakit')
|
||||
ForCount(count: model.penyakitCount.toString()),
|
||||
if (element['kategori'] == 'obat')
|
||||
ForCount(count: model.obatCount.toString()),
|
||||
if (element['kategori'] == 'alat')
|
||||
ForCount(count: model.alatCount.toString()),
|
||||
if (element['kategori'] == 'umum')
|
||||
ForCount(count: model.umumCount.toString()),
|
||||
if (element['kategori'] == 'hormon')
|
||||
ForCount(count: model.hormonCount.toString()),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ForCount extends StatelessWidget {
|
||||
const ForCount({
|
||||
super.key,
|
||||
required this.count,
|
||||
});
|
||||
|
||||
final String count;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Text(
|
||||
count,
|
||||
style: boldTextStyle.copyWith(
|
||||
color: Colors.white,
|
||||
fontSize: 13,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../../../../app/app.logger.dart';
|
||||
import '../../../../app/core/custom_base_view_model.dart';
|
||||
import '../../../../model/istilah_model1.dart';
|
||||
|
||||
class HalamanUtamaViewModel extends CustomBaseViewModel {
|
||||
final log = getLogger('HalamanUtamaViewModel');
|
||||
List<IstilahModel1> listIstilah = [];
|
||||
List<Map<String, dynamic>> kategoriIstilah = [];
|
||||
int penyakitCount = 0;
|
||||
int anggotaTubuhCount = 0;
|
||||
int obatCount = 0;
|
||||
int alatCount = 0;
|
||||
int umumCount = 0;
|
||||
int hormonCount = 0;
|
||||
Future<void> init() async {
|
||||
setBusy(true);
|
||||
listIstilah = await rootBundle.loadString('assets/dataset1.json').then(
|
||||
(String data) {
|
||||
final List<dynamic> jsonData = json.decode(data);
|
||||
return jsonData.map((dynamic item) {
|
||||
return IstilahModel1.fromJson(item as Map<String, dynamic>);
|
||||
}).toList();
|
||||
},
|
||||
);
|
||||
|
||||
log.i(listIstilah.length);
|
||||
|
||||
for (var element in listIstilah) {
|
||||
Icon? icon;
|
||||
Color? color;
|
||||
switch (element.kategori) {
|
||||
case 'penyakit':
|
||||
icon = const Icon(Icons.health_and_safety, color: Colors.white);
|
||||
color = Colors.red;
|
||||
penyakitCount++;
|
||||
break;
|
||||
case 'anggota tubuh':
|
||||
icon = const Icon(Icons.heart_broken, color: Colors.white);
|
||||
color = Colors.red;
|
||||
anggotaTubuhCount++;
|
||||
break;
|
||||
case 'obat':
|
||||
icon = const Icon(Icons.medication_liquid, color: Colors.white);
|
||||
color = Colors.blue;
|
||||
obatCount++;
|
||||
break;
|
||||
case 'alat':
|
||||
icon = const Icon(Icons.medical_information, color: Colors.white);
|
||||
color = Colors.blue;
|
||||
alatCount++;
|
||||
case 'umum':
|
||||
icon = const Icon(Icons.medical_information, color: Colors.white);
|
||||
color = Colors.blue;
|
||||
umumCount++;
|
||||
case 'hormon':
|
||||
icon = const Icon(Icons.medical_information, color: Colors.white);
|
||||
color = Colors.blue;
|
||||
hormonCount++;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// add to kategoriIstilah and if the kategori is not in the list, add it
|
||||
if (!kategoriIstilah.any((k) => k['kategori'] == element.kategori)) {
|
||||
kategoriIstilah.add({
|
||||
'icon': icon,
|
||||
'color': color,
|
||||
'kategori': element.kategori,
|
||||
});
|
||||
}
|
||||
|
||||
// add count to the kategoriIstilah
|
||||
}
|
||||
|
||||
kategoriIstilah.sort((a, b) => a['kategori'].compareTo(b['kategori']));
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user