0

I am making a movie app using tmdb_api.

I added package to pubspce.yml and did pubget. Of course it was added as normal.

dependencies:
  flutter:
    sdk: flutter
  tmdb_api: ^1.2.7
  google_fonts: ^2.1.0

I connected the api key and token in main.dart. Refer to pub.dev for this connection method.

main.dart

import 'package:flutter/material.dart';
import 'package:movie_app_2021/utils/text.dart';
import 'package:movie_app_2021/widgets/toprated.dart';
import 'package:movie_app_2021/widgets/trending.dart';
import 'package:movie_app_2021/widgets/tv.dart';
import 'package:tmdb_api/tmdb_api.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Home(),
      debugShowCheckedModeBanner: false,
      theme: ThemeData(brightness: Brightness.dark, primaryColor: Colors.green),
    );
  }
}

class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  List trendingmovies = [];
  List topratedmovies = [];
  List tv = [];
  final String apiKey = '6bdd6f36cb39f19fc91894a86183a8bd';
  final readAccessToken = 'eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI2YmRkNmYzNmNiMzlmMTlmYzkxODk0YTg2MTgzYThiZCIsInN1YiI6IjYxNGJjY2JmZDJjMGMxMDA0NTNkOTk4MSIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.1gDUXeVLFMdf092GNdmo3fORzVUOSy03n5p6iKAFftI';

  @override
  void initState(){
    loadMovies();
    super.initState();
  }

  loadMovies() async{
    TMDB tmdbWithCustomLogs = TMDB(ApiKeys(apiKey, readAccessToken),
    logConfig: ConfigLogger(
      showLogs: true,
      showErrorLogs: true,
    ));

    Map trendingresult = await tmdbWithCustomLogs.v3.trending.getTrending();
    Map topratedresult = await tmdbWithCustomLogs.v3.movies.getTopRated();
    Map tvresult = await tmdbWithCustomLogs.v3.tv.getPouplar();

    setState(() {
      trendingmovies = trendingresult['results'];
      topratedmovies = topratedresult['results'];
      tv = tvresult['results'];
    });
    print(tv);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      appBar: AppBar(
        backgroundColor: Colors.transparent,
        title: ModifiedText(text: 'Flutter Movie App'),
      ),
      body: ListView(
        children: [
           TopratedMovies(toprated: topratedmovies,),
           TrandingMovies(trending: trendingmovies),
           TV(tv: tv),
        ],
      ),
    );
  }
}

ModifiedText is a class that just outputs text to googleFont.

trending, toprated and tv are the values ​​fetched from tmdb_api.

import 'package:flutter/material.dart';
import 'package:movie_app_2021/utils/text.dart';

import '../description/description.dart';

class TrandingMovies extends StatelessWidget {
  final List? trending;

  const TrandingMovies({Key? key, this.trending}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(10),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          ModifiedText(
            text: 'Trending Movies',
            size: 26,
          ),
          SizedBox(
            height: 10,
          ),
          Container(
            height: 270,
            child: ListView.builder(
              itemCount: trending!.length,
              scrollDirection: Axis.horizontal,
              itemBuilder: (context, index) {
                return InkWell(
                  onTap: () {
                    Navigator.push(context, MaterialPageRoute(builder: (context)=>Description(
                      name: trending![index]['title'],
                      bannerurl: 'http://image.tmdb.org/t/p/w500'+trending![index]['backdrop_path'],
                      posterurl: 'http://image.tmdb.org/t/p/w500'+trending![index]['poster_path'],
                      description: trending![index]['overview'],
                      vote: trending![index]['vote_average'].toString(),
                      lanch_on: trending![index]['release_date'],
                    )));
                  },
                  child: trending![index]['title']!=null?Container(
                    width: 140,
                    child: Column(
                      children: [
                        Container(
                          height: 200,
                          decoration: BoxDecoration(
                            image: DecorationImage(
                              image: NetworkImage(
                                'http://image.tmdb.org/t/p/w500'+trending![index]['poster_path']
                              ),
                            ),
                          ),
                        ),
                        Container(
                          child: ModifiedText(text: trending![index]['title']!=null?
                          trending![index]['title']:'Loding',),
                        ),
                      ],
                    ),
                  ):Container(),
                );
              },
            ),
          ),
        ],
      ),
    );
  }
}

Error

Error: Cannot run with sound null safety, because the following dependencies don't support null safety:

  • package:tmdb_api

I coded it with good null-safety. Last Friday, it worked normally, but today an error occurred. Is there anything that needs to be changed since the update is in progress?

Jungwon
  • 1,038
  • 7
  • 20

1 Answers1

0

enter image description here

In Run -> Edit configuration, type the above to solve the problem.

But flutter recommends null-safety. If you know of any other workaround please let me know

Jungwon
  • 1,038
  • 7
  • 20