You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
2.7 KiB
93 lines
2.7 KiB
import 'dart:async';
|
|
import 'dart:convert';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:get/get.dart';
|
|
|
|
class VideoList {
|
|
final String uuid;
|
|
final String name;
|
|
final String speaker;
|
|
final String lang;
|
|
final String thumbnail;
|
|
|
|
VideoList(
|
|
{required this.uuid,
|
|
required this.name,
|
|
required this.speaker,
|
|
required this.lang,
|
|
required this.thumbnail});
|
|
|
|
factory VideoList.fromJson(Map<String, dynamic> json) {
|
|
return VideoList(
|
|
uuid: json['uuid'],
|
|
name: json['name'].split(' | ')[0].split(' by ')[0],
|
|
speaker: json['name'].split(' | ')[0].split(' by ')[1],
|
|
lang: json['language']['id'],
|
|
thumbnail: json['thumbnailPath'],
|
|
);
|
|
}
|
|
}
|
|
|
|
class VideosListView extends StatelessWidget {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return FutureBuilder<List<VideoList>>(
|
|
future: _fetchVideos(),
|
|
builder: (context, snapshot) {
|
|
if (snapshot.hasData) {
|
|
List<VideoList>? data = snapshot.data;
|
|
return _videosListView(data);
|
|
} else if (snapshot.hasError) {
|
|
return Text("${snapshot.error}");
|
|
}
|
|
return Container(
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [CircularProgressIndicator()]));
|
|
},
|
|
);
|
|
}
|
|
|
|
Future<List<VideoList>> _fetchVideos() async {
|
|
final videosFrom2020API =
|
|
'https://video.ozgurkon.org/api/v1/video-channels/ozgurkon2020/videos';
|
|
final response = await http.get(Uri.parse(videosFrom2020API));
|
|
|
|
if (response.statusCode == 200) {
|
|
Map<String, dynamic> jsonResponse = json.decode(response.body);
|
|
List videoList = jsonResponse['data'];
|
|
return videoList.map((job) => new VideoList.fromJson(job)).toList();
|
|
} else {
|
|
throw Exception('Failed to load videos from API');
|
|
}
|
|
}
|
|
|
|
ListView _videosListView(data) {
|
|
return ListView.builder(
|
|
itemCount: data.length,
|
|
itemBuilder: (context, index) {
|
|
return _tile(data[index].uuid, data[index].name, data[index].speaker,
|
|
data[index].thumbnail, data[index].lang);
|
|
});
|
|
}
|
|
|
|
ListTile _tile(String uuid, String title, String subtitle, String thumbnail,
|
|
String lang) =>
|
|
ListTile(
|
|
title: Text(title,
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.w500,
|
|
fontSize: 20,
|
|
)),
|
|
subtitle: Text(subtitle),
|
|
leading: Image.network('https://video.ozgurkon.org/' + thumbnail),
|
|
trailing: lang == "tr" ? Text("🇹🇷") : Text('🇬🇧'),
|
|
onTap: () {
|
|
print(uuid);
|
|
Get.toNamed('/video/$uuid');
|
|
},
|
|
);
|
|
}
|
|
|