mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +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/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/dialogs/icon_selection_dialog.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/hoverable_button.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/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
import 'package:syncrow_web/utils/constants/space_icon_const.dart';
|
import 'package:syncrow_web/utils/constants/space_icon_const.dart';
|
||||||
@ -60,7 +61,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Future<Widget> build(BuildContext context) async {
|
||||||
final screenWidth = MediaQuery.of(context).size.width;
|
final screenWidth = MediaQuery.of(context).size.width;
|
||||||
|
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
@ -91,7 +92,9 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
SvgPicture.asset(
|
SvgPicture.asset(
|
||||||
selectedIcon,
|
await AssetValidator.isValidAsset(selectedIcon)
|
||||||
|
? selectedIcon
|
||||||
|
: Assets.location,
|
||||||
width: screenWidth * 0.04,
|
width: screenWidth * 0.04,
|
||||||
height: 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(
|
decoration: InputDecoration(
|
||||||
hintText: 'Please enter the name',
|
hintText: 'Please enter the name',
|
||||||
hintStyle: const TextStyle(
|
hintStyle: const TextStyle(
|
||||||
|
@ -19,23 +19,26 @@ class CommunitySpaceManagementApi {
|
|||||||
.replaceAll('{projectId}', TempConst.projectId),
|
.replaceAll('{projectId}', TempConst.projectId),
|
||||||
queryParameters: {'page': page},
|
queryParameters: {'page': page},
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
List<dynamic> jsonData = json['data'];
|
try {
|
||||||
hasNext = json['hasNext'] ?? false;
|
List<dynamic> jsonData = json['data'] ?? [];
|
||||||
int currentPage = json['page'] ?? 1;
|
hasNext = json['hasNext'] ?? false;
|
||||||
List<CommunityModel> communityList = jsonData.map((jsonItem) {
|
int currentPage = json['page'] ?? 1;
|
||||||
return CommunityModel.fromJson(jsonItem);
|
List<CommunityModel> communityList = jsonData.map((jsonItem) {
|
||||||
}).toList();
|
return CommunityModel.fromJson(jsonItem);
|
||||||
|
}).toList();
|
||||||
allCommunities.addAll(communityList);
|
allCommunities.addAll(communityList);
|
||||||
page = currentPage + 1;
|
page = currentPage + 1;
|
||||||
return communityList;
|
return communityList;
|
||||||
|
} catch (_) {
|
||||||
|
hasNext = false;
|
||||||
|
return [];
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return allCommunities;
|
return allCommunities;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint('Error fetching communities: $e');
|
|
||||||
return [];
|
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