ExtendContentList.dart 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import 'package:flutter/widgets.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import '../models/entities/ExtendContent.dart';
  4. class ExtendContentList extends StatelessWidget {
  5. final List<ExtendContent> list;
  6. ExtendContentList({ Key? key, required this.list }) : super(key: key);
  7. Widget? _image(String? content) {
  8. if (null == content || content.isEmpty) return null;
  9. return Image.network(content, fit: BoxFit.cover);
  10. }
  11. Widget? _text(String? content) {
  12. if (null == content || content.isEmpty) return null;
  13. return Text(content);
  14. }
  15. @override
  16. Widget build(BuildContext context) {
  17. List<Widget> _widgets = [];
  18. for (var i = 0; i < list.length; i += 1) {
  19. if (i != 0 ) {
  20. _widgets.add(SizedBox(height: 20.w,));
  21. }
  22. var item = list[i];
  23. _widgets.add(Container(
  24. child: item.contentType == "image" ? _image(item.content) : _text(item.content),
  25. ));
  26. }
  27. return Column(
  28. children: _widgets,
  29. );
  30. }
  31. }