Skip to content

Commit

Permalink
added something that makes me confused lol
Browse files Browse the repository at this point in the history
  • Loading branch information
febryardiansyah committed Apr 20, 2020
1 parent b8a87c0 commit 43c2171
Show file tree
Hide file tree
Showing 12 changed files with 278 additions and 121 deletions.
14 changes: 3 additions & 11 deletions lib/components/bottom_navbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import 'package:animku/environments/dictionary.dart';
import 'package:animku/environments/end_point_path.dart';
import 'package:animku/providers/current_season_provider.dart';
import 'package:animku/providers/days_provider.dart';
import 'package:animku/ui/spring_season_screen.dart';
import 'package:animku/ui/currentSeason/current_season_screen.dart';
import 'package:animku/ui/currentseason/spring_season_screen.dart';
import 'package:animku/ui/currentseason/winter_season_screen.dart';
import 'package:bottom_navy_bar/bottom_navy_bar.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
Expand All @@ -20,17 +20,9 @@ class BottomNavBar extends StatefulWidget {
class _BottomNavBarState extends State<BottomNavBar> {
int currentIndex = 0;
List<Widget>_children = [
SpringSeasonScreen(),
WinterSeasonScreen(),
SpringSeasonScreen(),
];

@override
void initState() {
// TODO: implement initState
Provider.of<CurrentSeasonProvider>(context,listen: false).getWinter();
Provider.of<DaysProvider>(context,listen: false).getDays();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down
96 changes: 81 additions & 15 deletions lib/components/my_grid_view.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,89 @@
import 'package:animku/environments/colors.dart';
import 'package:animku/environments/end_point_path.dart';
import 'package:animku/environments/my_fonts.dart';
import 'package:animku/providers/current_season_provider.dart';
import 'package:animku/ui/detailscreen/details_screen.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:provider/provider.dart';

class MyGridView extends StatelessWidget {
class MyGridView extends StatefulWidget {
final thisPath;
const MyGridView({Key key, this.thisPath}) : super(key: key);
@override
_MyGridViewState createState() => _MyGridViewState();
}

class _MyGridViewState extends State<MyGridView> {

@override
void initState() {
// TODO: implement initState
Provider.of<CurrentSeasonProvider>(context,listen: false).getCurrentSeason(EndPointPath.winter2020);
super.initState();
}
@override
Widget build(BuildContext context) {
return GridView.count(
crossAxisCount: 3,
physics:ClampingScrollPhysics(),
shrinkWrap: true,
crossAxisSpacing: 8,
mainAxisSpacing: 15,
children: <Widget>[
Container(color: BaseColor.white,),
Container(color: BaseColor.white,),
Container(color: BaseColor.white,),
Container(color: BaseColor.white,),
Container(color: BaseColor.white,),
Container(color: BaseColor.white,),
],
ScreenUtil.init(context);
var _getData = Provider.of<CurrentSeasonProvider>(context,listen: false).getCurrentSeason(widget.thisPath);
return FutureBuilder(
future: _getData ,
builder: (context,snapshot){
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: SpinKitWave(
color: BaseColor.lightPurple,
),
);
}
return Consumer<CurrentSeasonProvider>(
builder: (context,data,_)=>
GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
mainAxisSpacing: 10,
crossAxisSpacing: 10
),
itemCount: data.currentSeason.length,
physics: ClampingScrollPhysics(),
shrinkWrap: true,
scrollDirection: Axis.vertical,
itemBuilder: (context,i){
return ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(8)),
child: InkWell(
onTap: (){
Navigator.push(context, MaterialPageRoute(
builder: (context)=>DetailsScreen(title: data.currentSeason[i].animeList[i].title,)
));
},
child: Container(
decoration: BoxDecoration(
color: BaseColor.white,
image: DecorationImage(
image: NetworkImage(data.currentSeason[i].animeList[i].imageUrl),fit: BoxFit.cover
)
),
child: Align(
alignment: Alignment.bottomCenter,
child: Container(
height: 56.h,
width: double.infinity,
color: BaseColor.purpleToBlue,
child: Center(
child: Text('${data.currentSeason[i].animeList[i].title}',style: TextStyle(color: BaseColor.white,fontFamily: MyFonts.baloo)),
),
),
),
),
),
);
},
),
);
},
);
}
}
57 changes: 31 additions & 26 deletions lib/components/my_list.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import 'package:animku/environments/colors.dart';
import 'package:animku/environments/my_fonts.dart';
import 'package:animku/providers/current_season_provider.dart';
import 'package:animku/ui/detailscreen/details_screen.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:provider/provider.dart';

class MyList extends StatefulWidget {
final image, title, genre, score, eps,itemCount;

const MyList(
{Key key, this.image, this.title, this.genre, this.score, this.eps,this.itemCount})
: super(key: key);

final thisPath;
const MyList({Key key, this.thisPath}) : super(key: key);
@override
_MyListState createState() => _MyListState();
}
Expand All @@ -24,8 +21,8 @@ class _MyListState extends State<MyList> {
@override
Widget build(BuildContext context) {
ScreenUtil.init(context);
var _getData =
Provider.of<CurrentSeasonProvider>(context, listen: false).getWinter();
var _getData = Provider.of<CurrentSeasonProvider>(context, listen: false)
.getCurrentSeason(widget.thisPath);
return FutureBuilder(
future: _getData,
builder: (context, snapshot) {
Expand All @@ -37,32 +34,40 @@ class _MyListState extends State<MyList> {
return Consumer<CurrentSeasonProvider>(
builder: (context, data, _) => ListView.builder(
scrollDirection: Axis.vertical,
itemCount: data.winter2020.length,
itemCount: data.currentSeason.length,
shrinkWrap: true,
physics: ClampingScrollPhysics(),
itemBuilder: (context, i) {
List genLst = new List();
data.winter2020[i].animeList[i].genreList.forEach((item) {
data.currentSeason[i].animeList[i].genreList.forEach((item) {
genLst.add(item.name);
});
if (i == data.winter2020.length) {
if (i == data.currentSeason.length) {
return _buildProgress();
}
return Container(
child: Stack(
children: <Widget>[
Container(
height: 600.h,
),
_background(
title: data.winter2020[i].animeList[i].title,
genre: genLst,
episodes: data.winter2020[i].animeList[i].episodes,
score: data.winter2020[i].animeList[i].score,
),
_animePic(
imageUrl: data.winter2020[i].animeList[i].imageUrl),
],
return InkWell(
onTap: () {
Navigator.push(context, MaterialPageRoute(
builder: (context)=>DetailsScreen(title: data.currentSeason[i].animeList[i].title,)
));
},
child: Container(
child: Stack(
children: <Widget>[
Container(
height: 600.h,
),
_background(
title: data.currentSeason[i].animeList[i].title,
genre: genLst,
episodes: data.currentSeason[i].animeList[i].episodes,
score: data.currentSeason[i].animeList[i].score,
),
_animePic(
imageUrl:
data.currentSeason[i].animeList[i].imageUrl),
],
),
),
);
},
Expand Down
6 changes: 6 additions & 0 deletions lib/environments/end_point_path.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
class EndPointPath{
static List pathList =[
EndPointPath.winter2020,
EndPointPath.spring2020,
EndPointPath.summer2020,
EndPointPath.fall2020
];

static String currentSeason = '/season';
static String winter2020 = '/season/2020/winter';
Expand Down
15 changes: 12 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:animku/components/bottom_navbar.dart';
import 'package:animku/providers/current_season_provider.dart';
import 'package:animku/providers/days_provider.dart';
import 'package:animku/ui/splash_screen.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

Expand All @@ -11,13 +12,21 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (_)=> CurrentSeasonProvider()),
ChangeNotifierProvider(create: (_)=>DaysProvider(),)
ChangeNotifierProvider(create: (_) => CurrentSeasonProvider()),
ChangeNotifierProvider(
create: (_) => DaysProvider(),
)
],
child: MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: BottomNavBar()),
body: BottomNavBar(),
),
// initialRoute: '/',
// routes: {
// '/':(_) => SplashScreen(),
// '/botNavBar':(_) => BottomNavBar(),
// },
),
);
}
Expand Down
38 changes: 10 additions & 28 deletions lib/providers/current_season_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,21 @@ import 'package:animku/models/current_season_model.dart';
import 'package:animku/services/api_service.dart';
import 'package:flutter/material.dart';

class CurrentSeasonProvider extends ChangeNotifier{
class CurrentSeasonProvider extends ChangeNotifier {
var api = ApiService();
List<CurrentSeasonModel> _winter2020=[];
List<CurrentSeasonModel> _spring2020 = [];
List<CurrentSeasonModel> _currentSeason = [];
List<CurrentSeasonModel> get currentSeason => _currentSeason;

List<CurrentSeasonModel> get spring2020 => _spring2020;
//fetch currentSeason
Future<List<CurrentSeasonModel>> getCurrentSeason(String path) async {
final response = await api.client.get('${api.baseUrl+path}');

List<CurrentSeasonModel> get winter2020 => _winter2020;

//fetch getWinter2020
Future<List<CurrentSeasonModel>>getWinter()async{
final response = await api.client.get('${api.baseUrl+EndPointPath.winter2020}');

if(response.statusCode == 200){
notifyListeners();
var res = currentSeasonFromJson(response.body);
_winter2020.add(res);
return _winter2020;
}else{
throw Exception();
}
}

//fetch getSpring2020
Future<List<CurrentSeasonModel>>getSpring()async{
final response = await api.client.get('${api.baseUrl+EndPointPath.spring2020}');

if(response.statusCode == 200){
if (response.statusCode == 200) {
notifyListeners();
var res = currentSeasonFromJson(response.body);
_spring2020.add(res);
return _spring2020;
}else{
_currentSeason.add(res);
return _currentSeason;
} else {
throw Exception();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import 'package:animku/components/my_grid_view.dart';
import 'package:animku/components/my_list.dart';
import 'package:animku/components/season_title.dart';
import 'package:animku/environments/colors.dart';
import 'package:animku/environments/dictionary.dart';
import 'package:animku/environments/end_point_path.dart';
import 'package:animku/environments/my_fonts.dart';
import 'package:animku/providers/current_season_provider.dart';
import 'package:flutter/material.dart';
Expand All @@ -12,22 +11,23 @@ import 'package:provider/provider.dart';
class CurrentSeasonScreen extends StatefulWidget {
static final ScrollController scrollController = new ScrollController();
final title,mylist,mygridview;
final String lazyLoadingPath;

const CurrentSeasonScreen({Key key, this.title, this.mylist, this.mygridview}) : super(key: key);
const CurrentSeasonScreen({Key key, this.title, this.mylist, this.mygridview,this.lazyLoadingPath}) : super(key: key);
@override
_CurrentSeasonScreenState createState() => _CurrentSeasonScreenState();
}

class _CurrentSeasonScreenState extends State<CurrentSeasonScreen> {

bool isList = true;

@override
void initState() {
// TODO: implement initState
super.initState();
CurrentSeasonScreen.scrollController.addListener((){
if(CurrentSeasonScreen.scrollController.position.pixels == CurrentSeasonScreen.scrollController.position.maxScrollExtent){
Provider.of<CurrentSeasonProvider>(context, listen: false).getWinter();
Provider.of<CurrentSeasonProvider>(context,listen: false).getCurrentSeason(widget.lazyLoadingPath);
}
});
}
Expand Down Expand Up @@ -64,19 +64,21 @@ class _CurrentSeasonScreenState extends State<CurrentSeasonScreen> {
],
),
),
body: SingleChildScrollView(
controller: CurrentSeasonScreen.scrollController,
child: Padding(
padding: EdgeInsets.only(top: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SeasonTitle(judul: widget.title,),
Padding(
padding: EdgeInsets.symmetric(horizontal: 15, vertical: 35),
child: isList?widget.mylist:widget.mygridview,
),
],
body: Scrollbar(
child: SingleChildScrollView(
controller: CurrentSeasonScreen.scrollController,
child: Padding(
padding: EdgeInsets.only(top: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SeasonTitle(judul: widget.title,),
Padding(
padding: EdgeInsets.symmetric(horizontal: 15, vertical: 35),
child: isList?widget.mylist:widget.mygridview,
),
],
),
),
),
),
Expand Down
Loading

0 comments on commit 43c2171

Please sign in to comment.