flutter_kinetra/lib/kt_widgets/kt_status_widget.dart
2025-09-12 14:19:13 +08:00

108 lines
3.2 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/material.dart';
import 'package:flutter_kinetra/kt_utils/kt_string_extend.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
enum KtErrorStatusType { noNetwork, loadFailed, nothingYet, notFound }
enum KtLoadStatusType { loading, loadSuccess, loadFailed, loadNoData }
class BadStatusWidget extends StatelessWidget {
final KtErrorStatusType type;
final String? message;
final VoidCallback? onPressed;
const BadStatusWidget({
super.key,
required this.type,
this.message,
this.onPressed,
});
@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Stack(
alignment: Alignment.bottomCenter,
children: [
Image.asset(_getIcon(type).ktIcon, width: 290.w, height: 268.h),
Text(
_getMessage(type, message),
style: TextStyle(
fontSize: 15.sp,
color: Color(0xFF1E1E20),
fontWeight: FontWeight.w500,
),
),
],
),
Text(
_getSubMessage(type, message),
style: TextStyle(fontSize: 12.sp, color: Color(0xFF5E5E5E)),
),
if (onPressed != null)
GestureDetector(
onTap: onPressed,
child: Container(
height: 48.h,
width: 200.w,
margin: EdgeInsets.only(top: 30.h),
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border.all(color: Color(0xFF5E5E5E), width: 1.w),
borderRadius: BorderRadius.circular(50.w),
),
child: Text(
'Try Again',
style: TextStyle(fontSize: 14.sp, color: Color(0xFF1E1E20)),
),
),
),
],
),
);
}
String _getIcon(KtErrorStatusType type) {
switch (type) {
case KtErrorStatusType.noNetwork:
return 'ic_no_network.png';
case KtErrorStatusType.loadFailed:
return 'ic_load_failed.png';
case KtErrorStatusType.nothingYet:
return 'ic_nothing.png';
case KtErrorStatusType.notFound:
return 'ic_not_found.png';
}
}
String _getMessage(KtErrorStatusType type, String? message) {
switch (type) {
case KtErrorStatusType.noNetwork:
return 'No Network';
case KtErrorStatusType.loadFailed:
return 'Load Failed';
case KtErrorStatusType.nothingYet:
return 'Nothing here yet';
case KtErrorStatusType.notFound:
return 'Not found';
}
}
String _getSubMessage(KtErrorStatusType type, String? message) {
switch (type) {
case KtErrorStatusType.noNetwork:
return 'Unable to connect. Try again later.';
case KtErrorStatusType.loadFailed:
return 'Were having trouble. Hang tight.';
case KtErrorStatusType.nothingYet:
return 'Start exploring and add something!';
case KtErrorStatusType.notFound:
return 'Sorry, we couldn\'t find anything.';
}
}
}