Created
May 4, 2018 09:51
-
-
Save shaktiprakash099/310e6cbb509fb2c2e37f83ffc3cdd170 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:http/http.dart' as http; | |
import 'dart:convert'; | |
import 'package:apiintegration_demo/models/videomodel.dart'; | |
import 'package:apiintegration_demo/screens/coursedetails.dart'; | |
import 'package:apiintegration_demo/views/videocell.dart'; | |
import 'package:apiintegration_demo/utils/mainnavigator.dart'; | |
class MyApp extends StatelessWidget{ | |
@override | |
Widget build(BuildContext context) { | |
return new MyAppStatefulBody(); | |
} | |
} | |
class MyAppStatefulBody extends StatefulWidget{ | |
@override | |
State<StatefulWidget> createState() { | |
// TODO: implement createState | |
return new MYAppState(); | |
} | |
} | |
class MYAppState extends State<MyAppStatefulBody>{ | |
var _isLoading = true; | |
@override | |
void initState(){ | |
super.initState(); | |
_fetchData(); | |
} | |
final videos = new List<Video>(); | |
_fetchData()async{ | |
final urlString = "https://api.letsbuildthatapp.com/youtube/home_feed"; | |
final response = await http.get(urlString); | |
// print(response.body); | |
if (response.statusCode == 200){ | |
final courseJson = json.decode(response.body); | |
print("success"); | |
courseJson["videos"].forEach((videoDict) { | |
// final channel = videoDict["channel"]; | |
final course = new Video(videoDict["id"], videoDict["name"], videoDict["imageUrl"], | |
videoDict["numberOfViews"],videoDict["channel"]["profileImageUrl"]); | |
videos.add(course); | |
}); | |
setState(() { | |
_isLoading = false; | |
}); | |
} | |
else{ | |
} | |
} | |
@override | |
Widget build(BuildContext context) { | |
// TODO: implement build | |
return new MaterialApp( | |
title: 'Corses', | |
home: new Scaffold( | |
appBar: new AppBar( | |
title: new Text('Courses'), | |
actions: <Widget>[ | |
new IconButton( | |
icon: new Icon(Icons.refresh), | |
onPressed: (){ | |
print("Loading"); | |
setState(() { | |
_isLoading = true; | |
}); | |
_fetchData(); | |
}, | |
) | |
], | |
), | |
body: new Center( | |
child: _isLoading ? new CircularProgressIndicator(): new ListView.builder( | |
itemCount: videos.length, | |
itemBuilder: (context,i){ | |
final video = videos[i]; | |
return new FlatButton( | |
padding: new EdgeInsets.all(0.0), | |
child: new VideoCell(video: video), | |
onPressed: (){ | |
print(video.profileImageUrl); | |
// Navigator.push( | |
// context, | |
// new MaterialPageRoute( | |
// // builder: (context) => new DetailsScreen(videodetails: video) | |
// builder: (context) => new CourseDeatails(videodetails: video) | |
// ), | |
// ); | |
Mynavigator.goToDetailScreen(context, video); | |
}, | |
); | |
// return Text('hello there'); | |
}, | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment