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.
 
 
 
 
 
 
ozgurkon-app/lib/widgets/Schedule.dart

125 lines
3.4 KiB

import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:get/get.dart';
class Schedule extends StatelessWidget {
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
flexibleSpace: new Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
new TabBar(
tabs: [
new Tab(
text: "2021-05-29",
),
new Tab(
text: "2021-05-30",
),
],
),
],
),
),
body: TabBarView(
children: [
Icon(Icons.directions_car),
Icon(Icons.directions_transit),
],
),
),
);
}
}
class ScheduleItem {
final String time;
final String name;
final List speakers;
final String lang;
ScheduleItem(
{required this.time,
required this.name,
required this.speakers,
required this.lang});
factory ScheduleItem.fromJson(Map<String, dynamic> json) {
return ScheduleItem(
time: json['time'],
name: json['name'],
speakers: json['speakers'],
lang: json['lang'],
);
}
}
class ScheduleView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return FutureBuilder<List<ScheduleItem>>(
future: _fetchSchedule(),
builder: (context, snapshot) {
if (snapshot.hasData) {
List<ScheduleItem>? data = snapshot.data;
return _scheduleListView(data);
} else if (snapshot.hasError) {
return Text("${snapshot.error}");
}
return Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [CircularProgressIndicator()]));
},
);
}
Future<List<ScheduleItem>> _fetchSchedule() 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 scheduleList = jsonResponse['data'];
return scheduleList.map((job) => new ScheduleItem.fromJson(job)).toList();
} else {
throw Exception('Failed to load schedule from API');
}
}
ListView _scheduleListView(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');
},
);
}