Untitled

 avatar
unknown
dart
4 years ago
6.2 kB
28
Indexable
# Model Class

class Shows {
  final String ShowTitle;
  final String BannerImage;
  final String ShowImage;
  bool Popular;
  bool OnGoing;

  Shows({
    this.ShowTitle,
    this.BannerImage,
    this.ShowImage,
    this.Popular,
    this.OnGoing,
  });

  factory Shows.fromJson(Map<String, dynamic> json) {
    return Shows(
      ShowTitle: json['ShowTitle'],
      BannerImage: json['BannerImage'],
      ShowImage: json['ShowImage'],
      Popular: json['Popular'],
      OnGoing: json['OnGoing'],
    );
  }
}


# Api 

import 'dart:convert';
import 'package:anime_frontend/utils/models/shows.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

class ShowsProvider with ChangeNotifier {
  ShowsProvider() {
    this.fetchTask();
  }

  List<Shows> _shows = [];

  List<Shows> get shows {
    return [..._shows];
  }

  fetchTask() async {
    final url = 'https://newstreamly.herokuapp.com/api/show/';
    final response = await http.get(url);
    if (response.statusCode == 200) {
      var data = json.decode(response.body) as List;
      _shows = data.map<Shows>((json) => Shows.fromJson(json)).toList();
      // notifyListeners();
      // ChangeNotifier();
    }
  }
}

# Main class

import 'package:anime_frontend/ui/core.dart';
import 'package:anime_frontend/utils/apis/shows.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (BuildContext context) => ShowsProvider(),
      child: MaterialApp(
        debugShowCheckedModeBanner: false,
        theme: ThemeData(
          primarySwatch: Colors.blue,
          visualDensity: VisualDensity.adaptivePlatformDensity,
        ),
        home: Core(),
      ),
    );
  }
}


# Page class

import 'package:anime_frontend/ui/widgets/show_card.dart';
import 'package:anime_frontend/ui/widgets/show_popular.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:anime_frontend/ui/constant/colors.dart';
import 'package:anime_frontend/ui/constant/teststyle.dart';
import 'package:anime_frontend/ui/widgets/banner.dart';
import 'package:anime_frontend/utils/apis/shows.dart';

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final showP = Provider.of<ShowsProvider>(context);

    return Scaffold(
      backgroundColor: kBackgroundColor,
      body: Container(
        margin: EdgeInsets.symmetric(horizontal: 10),
        child: ListView(
          scrollDirection: Axis.vertical,
          children: [
            Container(
              height: 50,
              child: Center(
                child: Text(
                  'Explore',
                  style: kAppbarTextStyle,
                  textAlign: TextAlign.center,
                ),
              ),
            ),
            SizedBox(height: 5),
            CarouselSlider(
              options: CarouselOptions(
                viewportFraction: .95,
                autoPlay: true,
              ),
              items: <Widget>[
                for (var index = 0; index < showP.shows.length; index++)
                  AnimeBanner(
                    imageUrl: showP.shows[index].BannerImage,
                    showTitle: showP.shows[index].ShowTitle,
                  )
              ],
            ),
            SizedBox(height: 5),
            Text(
              'Popular Anime',
              style: kTitleTextStyle,
            ),
            SizedBox(height: 10),
            SingleChildScrollView(
              scrollDirection: Axis.horizontal,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  for (var index = 0; index < showP.shows.length; index++)
                    if (showP.shows[index].Popular = true)
                      AnimeItem(
                        imageUrl: showP.shows[index].BannerImage,
                        showTitle: showP.shows[index].ShowTitle,
                      ),
                ],
              ),
            ),
            SizedBox(height: 5),
            Text(
              'onGoing Anime',
              style: kTitleTextStyle,
            ),
            SizedBox(height: 10),
            SingleChildScrollView(
              scrollDirection: Axis.horizontal,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  for (var index = 0; index < showP.shows.length; index++)
                    if (showP.shows[index].OnGoing = true)
          // ChangeNotifier()
                  AnimeItem(
                        imageUrl: showP.shows[index].BannerImage,
                        showTitle: showP.shows[index].ShowTitle,
                      ),
                ],
              ),
            ),
            SizedBox(height: 10),
            Container(
              padding: EdgeInsets.all(5),
              child: Text(
                'Made For You',
                style: kTitleTextStyle,
              ),
            ),
            SizedBox(height: 10),
            CarouselSlider(
              options: CarouselOptions(
                height: 300,
                viewportFraction: .7,
                enlargeCenterPage: true,
                autoPlay: true,
                autoPlayCurve: Curves.easeInOut,
              ),
              items: [
                for (var index = 0; index < showP.shows.length; index++)
                  AnimePopular(
                    imageUrl: showP.shows[index].BannerImage,
                    showTitle: showP.shows[index].ShowTitle,
                  ),
              ],
            ),
            SizedBox(height: 10),
          ],
        ),
      ),
    );
  }
}
Editor is loading...