Anonymous
Почему элемент ClassWidget не может быть назначена для списки виджета
Сообщение
Anonymous » 08 июн 2025, 09:21
ImagePickerOverlayWidget Элемент не может быть назначен списку виджетов. < /p>
Когда у меня есть
Код: Выделить всё
imagepickeroverly class in my file and use it, I have no problem < /code>
Но если я помесчу его в отдельный файл и импортирую, я получаю ошибку
она использую свой класс: < /p>
column (дети: [ImagePickerOverlayWidget (данные: данные: данные)]) < /p>
И это мой класс: < /p>
) < /p>
и это мой класс: < /p>
)) < /p>
И это мой класс: < /p>
)) < /p>
и это мой класс: < /p>
)) < /p>
и это мой класс: < /p>
)) < /p> и это мой класс: < /p>
).class ImagePickerOverlayWidget extends StatelessWidget {
final CheckItemModel data;
const ImagePickerOverlayWidget({super.key, required this.data});
@override
Widget build(BuildContext context) {
final controller = Get.put(
ImagePickerController(data.id.toString()),
tag: data.id.toString(),
);
return Visibility(
visible: data.isImage,
child: Column(
children: [
Container(
width: Get.width,
height: Get.height * 0.30,
decoration: BoxDecoration(
color: Colors.grey.withValues(alpha: 0.2),
borderRadius: BorderRadius.circular(12),
),
child: Center(
child: Obx(() {
int countImage = controller.capturedImages.length;
return IconButton(
iconSize: 60,
icon: Icon(Icons.camera_alt, color: Colors.grey.shade700),
onPressed:
(countImage >= data.maxImageCount)
? imageSnackbar
: () async {
final image = await Navigator.push(
context,
MaterialPageRoute(
builder: (_) => CameraOverlayScreen(),
),
);
if (image != null) {
controller.capturedImages.add(image);
}
},
);
}),
),
),
SizedBox(height: Get.height * 0.02),
Obx(
() => SizedBox(
height: Get.height * 0.1,
child: ListView.separated(
scrollDirection: Axis.horizontal,
itemCount: controller.capturedImages.length,
separatorBuilder: (_, __) => SizedBox(width: Get.width * 0.02),
itemBuilder: (context, index) {
return ClipRRect(
borderRadius: BorderRadius.circular(12),
child: Stack(
children: [
GestureDetector(
onTap: () {
showDialog(
context: context,
builder:
(_) => Dialog(
child: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: Image.file(
controller.capturedImages[index],
fit: BoxFit.contain,
),
),
),
);
},
child: Image.file(
controller.capturedImages[index],
width: Get.width * 0.18,
fit: BoxFit.cover,
),
),
Positioned(
right: 0,
child: GestureDetector(
onTap: () => controller.removeImageAt(index),
child: Icon(
Icons.delete,
color: Colors.red,
size: 30,
),
),
),
],
),
);
},
),
),
),
],
),
);
}
}
Конечно, когда он в порядке в самом файле, почему он должен дать ошибку в отдельном файле?
Подробнее здесь:
https://stackoverflow.com/questions/796 ... ist-widget
1749363701
Anonymous
ImagePickerOverlayWidget Элемент не может быть назначен списку виджетов. < /p> Когда у меня есть [code]imagepickeroverly class in my file and use it, I have no problem < /code> Но если я помесчу его в отдельный файл и импортирую, я получаю ошибку она использую свой класс: < /p> column (дети: [ImagePickerOverlayWidget (данные: данные: данные)]) < /p> И это мой класс: < /p> ) < /p> и это мой класс: < /p> )) < /p> И это мой класс: < /p> )) < /p> и это мой класс: < /p> )) < /p> и это мой класс: < /p> )) < /p> и это мой класс: < /p> ).class ImagePickerOverlayWidget extends StatelessWidget { final CheckItemModel data; const ImagePickerOverlayWidget({super.key, required this.data}); @override Widget build(BuildContext context) { final controller = Get.put( ImagePickerController(data.id.toString()), tag: data.id.toString(), ); return Visibility( visible: data.isImage, child: Column( children: [ Container( width: Get.width, height: Get.height * 0.30, decoration: BoxDecoration( color: Colors.grey.withValues(alpha: 0.2), borderRadius: BorderRadius.circular(12), ), child: Center( child: Obx(() { int countImage = controller.capturedImages.length; return IconButton( iconSize: 60, icon: Icon(Icons.camera_alt, color: Colors.grey.shade700), onPressed: (countImage >= data.maxImageCount) ? imageSnackbar : () async { final image = await Navigator.push( context, MaterialPageRoute( builder: (_) => CameraOverlayScreen(), ), ); if (image != null) { controller.capturedImages.add(image); } }, ); }), ), ), SizedBox(height: Get.height * 0.02), Obx( () => SizedBox( height: Get.height * 0.1, child: ListView.separated( scrollDirection: Axis.horizontal, itemCount: controller.capturedImages.length, separatorBuilder: (_, __) => SizedBox(width: Get.width * 0.02), itemBuilder: (context, index) { return ClipRRect( borderRadius: BorderRadius.circular(12), child: Stack( children: [ GestureDetector( onTap: () { showDialog( context: context, builder: (_) => Dialog( child: ClipRRect( borderRadius: BorderRadius.circular(12), child: Image.file( controller.capturedImages[index], fit: BoxFit.contain, ), ), ), ); }, child: Image.file( controller.capturedImages[index], width: Get.width * 0.18, fit: BoxFit.cover, ), ), Positioned( right: 0, child: GestureDetector( onTap: () => controller.removeImageAt(index), child: Icon( Icons.delete, color: Colors.red, size: 30, ), ), ), ], ), ); }, ), ), ), ], ), ); } } [/code] Конечно, когда он в порядке в самом файле, почему он должен дать ошибку в отдельном файле? Подробнее здесь: [url]https://stackoverflow.com/questions/79657540/why-the-element-classwidget-cant-assigned-to-list-widget[/url]