step 19 : fix check svg from server
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import 'package:app_petty_cash/widget/sankbar_widget.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
@@ -5,10 +7,61 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import '../app/constant.dart';
|
||||
|
||||
class HistoryRowAtasWidget extends HookConsumerWidget {
|
||||
const HistoryRowAtasWidget({super.key});
|
||||
final String icon_category_id;
|
||||
final String icon_category_name;
|
||||
final String amount;
|
||||
final String tipe;
|
||||
final String tglTransaksi;
|
||||
|
||||
const HistoryRowAtasWidget({
|
||||
Key? key,
|
||||
required this.icon_category_id,
|
||||
required this.icon_category_name,
|
||||
required this.amount,
|
||||
required this.tipe,
|
||||
required this.tglTransaksi,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
|
||||
// check file exist
|
||||
Future<Widget> checkFileExistence(String fileUrl) async {
|
||||
try {
|
||||
final dio = Dio();
|
||||
final response = await dio.head(fileUrl);
|
||||
if (response.statusCode == 200) {
|
||||
return SvgPicture.network(
|
||||
fileUrl,
|
||||
semanticsLabel: 'Icon pizza',
|
||||
placeholderBuilder: (BuildContext context) => Container(
|
||||
padding: const EdgeInsets.all(30.0),
|
||||
child: const CircularProgressIndicator(),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return SvgPicture.network(
|
||||
'https://devone.aplikasi.web.id/pettycash-media/icon/icon_13.svg',
|
||||
semanticsLabel: 'Icon pizza',
|
||||
placeholderBuilder: (BuildContext context) => Container(
|
||||
padding: const EdgeInsets.all(30.0),
|
||||
child: const CircularProgressIndicator(),
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
// print('Error checking file existence: $e');
|
||||
return SvgPicture.network(
|
||||
'https://devone.aplikasi.web.id/pettycash-media/icon/icon_13.svg',
|
||||
semanticsLabel: 'Icon pizza',
|
||||
placeholderBuilder: (BuildContext context) => Container(
|
||||
padding: const EdgeInsets.all(30.0),
|
||||
child: const CircularProgressIndicator(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return Row(
|
||||
children: [
|
||||
// kiri
|
||||
@@ -22,28 +75,40 @@ class HistoryRowAtasWidget extends HookConsumerWidget {
|
||||
),
|
||||
),
|
||||
// child: Text('s'),
|
||||
child: SvgPicture.network(
|
||||
'https://devone.aplikasi.web.id/pettycash-media/icon/icon_12.svg',
|
||||
semanticsLabel: 'Icon pizza',
|
||||
placeholderBuilder: (BuildContext context) => Container(
|
||||
padding: const EdgeInsets.all(30.0),
|
||||
child: const CircularProgressIndicator(),
|
||||
),
|
||||
child: FutureBuilder<Widget>(
|
||||
future: checkFileExistence('https://devone.aplikasi.web.id/pettycash-media/icon/icon_$icon_category_id.svg'),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return CircularProgressIndicator();
|
||||
} else if (snapshot.hasError) {
|
||||
return Icon(
|
||||
Icons.error,
|
||||
color: Colors.red,
|
||||
);
|
||||
} else {
|
||||
return snapshot.data ??
|
||||
Container();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
// tengah
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(left: 20),
|
||||
padding: EdgeInsets.only(
|
||||
left: Constant.getActualYPhone(context: context, y: 20),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Makanan & Minuman',
|
||||
icon_category_name,
|
||||
style: Constant.body2_600(context: context).copyWith(
|
||||
fontWeight: FontWeight.w600, color: Constant.textBlack),
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Constant.textBlack,
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: Constant.getActualYPhone(
|
||||
@@ -52,7 +117,7 @@ class HistoryRowAtasWidget extends HookConsumerWidget {
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'100000',
|
||||
amount,
|
||||
style: Constant.body1_600(context: context).copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Constant.pcBtnBackgroundColor),
|
||||
@@ -65,7 +130,9 @@ class HistoryRowAtasWidget extends HookConsumerWidget {
|
||||
// kanan
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(right: 8),
|
||||
padding: EdgeInsets.only(
|
||||
right: Constant.getActualYPhone(context: context, y: 8),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
@@ -74,7 +141,7 @@ class HistoryRowAtasWidget extends HookConsumerWidget {
|
||||
// width: Constant.getActualXPhone(context: context, x: 32),
|
||||
height: Constant.getActualYPhone(context: context, y: 19),
|
||||
decoration: BoxDecoration(
|
||||
color: Color.fromRGBO(241, 90, 41, 0.16),
|
||||
color: Constant.bgIconHistory,
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(6.0),
|
||||
),
|
||||
@@ -82,7 +149,7 @@ class HistoryRowAtasWidget extends HookConsumerWidget {
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(2.0),
|
||||
child: Text(
|
||||
'Kredit',
|
||||
tipe,
|
||||
style: Constant.body1_600(context: context).copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Constant.pcBtnBackgroundColor),
|
||||
@@ -96,7 +163,7 @@ class HistoryRowAtasWidget extends HookConsumerWidget {
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'15 Des 2023',
|
||||
tglTransaksi,
|
||||
style: Constant.body1_600(context: context).copyWith(
|
||||
fontWeight: FontWeight.w600, color: Constant.textGreyv2),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user