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 KtStatusWidget extends StatelessWidget { final KtErrorStatusType type; final String? message; final VoidCallback? onPressed; const KtStatusWidget({ super.key, required this.type, this.message, this.onPressed, }); @override Widget build(BuildContext context) { return Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, 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 'Network Hiccup'; case KtErrorStatusType.loadFailed: return 'Error reported'; case KtErrorStatusType.nothingYet: return 'Nothing here yet'; case KtErrorStatusType.notFound: return 'No Results Found'; } } String _getSubMessage(KtErrorStatusType type, String? message) { switch (type) { case KtErrorStatusType.noNetwork: return 'Check your WiFi or cellular data'; case KtErrorStatusType.loadFailed: return 'Our team has been notified.'; case KtErrorStatusType.nothingYet: return 'Start exploring and add something!'; case KtErrorStatusType.notFound: return 'Check spelling or use simpler keywords.'; } } }