mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 14:47:23 +00:00
add asset validation
This commit is contained in:
@ -8,6 +8,7 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/add_device_type_widget.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/dialogs/icon_selection_dialog.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/hoverable_button.dart';
|
||||
import 'package:syncrow_web/utils/asset_validator.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:syncrow_web/utils/constants/space_icon_const.dart';
|
||||
@ -60,7 +61,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
|
||||
@override
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Future<Widget> build(BuildContext context) async {
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
|
||||
return AlertDialog(
|
||||
@ -91,7 +92,9 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
),
|
||||
),
|
||||
SvgPicture.asset(
|
||||
selectedIcon,
|
||||
await AssetValidator.isValidAsset(selectedIcon)
|
||||
? selectedIcon
|
||||
: Assets.location,
|
||||
width: screenWidth * 0.04,
|
||||
height: screenWidth * 0.04,
|
||||
),
|
||||
@ -143,7 +146,8 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
}
|
||||
});
|
||||
},
|
||||
style: const TextStyle(color: ColorsManager.blackColor),
|
||||
style:
|
||||
const TextStyle(color: ColorsManager.blackColor),
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Please enter the name',
|
||||
hintStyle: const TextStyle(
|
||||
|
@ -19,23 +19,26 @@ class CommunitySpaceManagementApi {
|
||||
.replaceAll('{projectId}', TempConst.projectId),
|
||||
queryParameters: {'page': page},
|
||||
expectedResponseModel: (json) {
|
||||
List<dynamic> jsonData = json['data'];
|
||||
hasNext = json['hasNext'] ?? false;
|
||||
int currentPage = json['page'] ?? 1;
|
||||
List<CommunityModel> communityList = jsonData.map((jsonItem) {
|
||||
return CommunityModel.fromJson(jsonItem);
|
||||
}).toList();
|
||||
|
||||
allCommunities.addAll(communityList);
|
||||
page = currentPage + 1;
|
||||
return communityList;
|
||||
try {
|
||||
List<dynamic> jsonData = json['data'] ?? [];
|
||||
hasNext = json['hasNext'] ?? false;
|
||||
int currentPage = json['page'] ?? 1;
|
||||
List<CommunityModel> communityList = jsonData.map((jsonItem) {
|
||||
return CommunityModel.fromJson(jsonItem);
|
||||
}).toList();
|
||||
allCommunities.addAll(communityList);
|
||||
page = currentPage + 1;
|
||||
return communityList;
|
||||
} catch (_) {
|
||||
hasNext = false;
|
||||
return [];
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return allCommunities;
|
||||
} catch (e) {
|
||||
debugPrint('Error fetching communities: $e');
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
15
lib/utils/asset_validator.dart
Normal file
15
lib/utils/asset_validator.dart
Normal file
@ -0,0 +1,15 @@
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class AssetValidator {
|
||||
static Future<bool> isValidAsset(String? assetPath) async {
|
||||
if (assetPath == null || assetPath.isEmpty) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
await rootBundle.load(assetPath);
|
||||
return true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user