Files
flutter_wisetronic/lib/widgets/mobile/mobile_igoshow_learn_more.dart
2021-08-31 13:28:33 -04:00

126 lines
3.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:youtube_player_iframe/youtube_player_iframe.dart';
import '../../utils/util_web.dart' if (dart.library.io) '../../utils/util_io.dart';
class MobileiGoShowLearnMore extends StatefulWidget {
final Map<String, dynamic> data;
const MobileiGoShowLearnMore(this.data, {Key key}) : super(key: key);
@override
State<StatefulWidget> createState() {
return MobileiGoShowLearnMoreState();
}
}
class MobileiGoShowLearnMoreState extends State<MobileiGoShowLearnMore> {
@override
Widget build(BuildContext context) {
Column col = Column(
children: [
Container(
margin: EdgeInsets.only(bottom: 20.0),
child: Util.showImage(
'https:${widget.data['image-top']['image']}',
fit: BoxFit.contain,
),
),
],
);
List<Widget> w = _getContent();
for (int i = 0; i < w.length; i++) {
col.children.add(w[i]);
}
return SingleChildScrollView(
child: col,
);
}
@override
void initState() {
super.initState();
}
List<Widget> _getContent() {
List<Widget> widgets = [];
for (int i = 0; i < (widget.data['sections'] as List).length; i++) {
Column col = Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [],
);
col.children.add(Container(
margin: EdgeInsets.only(top: 8.0, left: 8.0, right: 8.0, bottom: 4.0),
child: Text(
'${(widget.data['sections'] as List)[i]['title']}',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16.0,
color: Colors.black87,
),
),
));
if ((widget.data['sections'] as List)[i]['image'] != null) {
col.children.add(
Container(
padding: EdgeInsets.only(
top: 10.0, left: 8.0, right: 8.0, bottom: 8.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Util.showImage(
'https:${(widget
.data['sections'] as List)[i]['image']['image']}',
fit: BoxFit.contain,
),
),
),
);
} else if (((widget.data['sections'] as List)[i]['youtube_videos'] as List).length > 0) {
YoutubePlayerController _controller = YoutubePlayerController(
initialVideoId: '${((widget.data['sections'] as List)[i]['youtube_videos'] as List)[0] as String}',
params: YoutubePlayerParams(
playlist: ((widget.data['sections'] as List)[i]['youtube_videos'] as List).length > 1 ?
((widget.data['sections'] as List)[i]['youtube_videos'] as List).map((e) {
return '$e';
}).toList() : [], // Defining custom playlist
startAt: Duration(seconds: 0),
showControls: true,
showFullscreenButton: false,
),
);
col.children.add(
Container(
padding: EdgeInsets.only(
top: 10.0, left: 8.0, right: 8.0, bottom: 8.0,
),
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: YoutubePlayerIFrame(
controller: _controller,
aspectRatio: 2 / 1,
),
),
),
);
}
col.children.add(Container(
margin: EdgeInsets.only(top: 4.0, left: 8.0, right: 8.0, bottom: 20.0),
padding: EdgeInsets.only(bottom: 10.0),
child: Text(
'${(widget.data['sections'] as List)[i]['description']}',
style: TextStyle(
fontSize: 14.0,
color: Colors.black38,
),
),
));
widgets.add(col);
}
return widgets;
}
}