I am trying to showing picture of movie in detail page. but the result like this
======== Exception caught by widgets library ======================================================= The following NoSuchMethodError was thrown building FutureBuilder<MovieDetailModel>(dirty, dependencies: [MediaQuery], state: _FutureBuilderState<MovieDetailModel>#ac178): The getter 'bigImage' was called on null. Receiver: null Tried calling: bigImage
and here is my MovieDetailPage
import 'package:flutter/material.dart'; import 'package:movies/models/movie_detail_models.dart'; import 'package:movies/models/movies_models.dart'; import 'package:movies/services/services.dart'; import 'package:movies/theme.dart'; class MovieDetailPage extends StatelessWidget{ final MovieModels movieModel; const MovieDetailPage({ Key key, this.movieModel, }) : super (key: key); @override Widget build(BuildContext context) { MovieDetailModel movieDetailModel; return Scaffold( backgroundColor: Color(0xFFF3F4F8), body: FutureBuilder( future: MovieServices.getMovieDetail(movieModel), builder: (context, snapshot){ if(snapshot.connectionState == ConnectionState.done) { movieDetailModel = snapshot.data; print(movieDetailModel); return CustomScrollView( slivers: [ SliverAppBar( title: Container( width: MediaQuery.of(context).size.width -2 *24, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( movieModel.name, style: textBlueFont.copyWith( color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold), maxLines: 1, overflow: TextOverflow.clip, ), ], ), ), backgroundColor: blueColor, pinned: true, expandedHeight: 250, flexibleSpace: FlexibleSpaceBar( background: Container( width: double.infinity, decoration: BoxDecoration( image: DecorationImage( image: NetworkImage(movieDetailModel.bigImage), fit: BoxFit.cover ) ), ), ), ) ], ); } else if(snapshot.hasError) { return Container( child: Text("Something Error"), ); } else { return Center( child: CircularProgressIndicator(), ); } }, ) ); } }
and here is movie detail model
import 'package:movies/models/movies_models.dart'; class MovieDetailModel extends MovieModels { final List genres; final String bigImage; final String rating; final String description; MovieDetailModel(MovieModels movieModels,{ this.genres, this.bigImage, this.rating, this.description, }) : super(country: movieModels.country, endDate: movieModels.endDate, id: movieModels.id, image: movieModels.image, name: movieModels.name, network: movieModels.network, permalink: movieModels.permalink, startDate: movieModels.startDate ); @override List<Object> get props => [genres,bigImage,rating,description]; }
here is my movie services
part of 'services.dart'; class MovieServices implements Services { @override void dispose() { } @override void init() { } static Future<ServiceResult<List<MovieModels>>> getMovie(int page, {http.Client client}) async { client ??= http.Client(); try{ String url = "https://www.episodate.com/api/most-popular?page=$page"; var response = await client.get(url,headers: { "Accept" : "application/json" }); if(response.statusCode == 200) { var data = jsonDecode(response.body); List<MovieModels> movieModels = (data['tv_shows'] as Iterable) .map((e) => MovieModels.fromJson(e)) .toList(); return ServiceResult(data: movieModels); } else{ return ServiceResult (status: false, message:"Status Code ${response.statusCode}"); } } catch(e) { return ServiceResult (status: false, message:e.toString()); } } //get movie detail static Future<MovieDetailModel> getMovieDetail(MovieModels movieModels,{int id, http.Client client}) async { client ??= http.Client(); try { String url = "https://www.episodate.com/api/show-details?q=$id ?? movieModels.id}"; var response = await client.get(url, headers: { "Accept": "application/json" }); if (response.statusCode == 200) { var data = jsonDecode(response.body); final result = data['tvShow']; print(result); return MovieDetailModel( MovieModels.fromJson(result), bigImage: result['image_path'], description: result['description'], genres: result['genres'], rating: result['rating'], ); } } catch(e) { print(e); } } }
here is my main.dart
import 'package:flutter/material.dart'; import 'package:movies/dashboard.dart'; import 'package:movies/cubit/movie_cubit.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:get/get.dart'; import 'package:movies/movie_detail_page.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) { return MultiBlocProvider( providers: [ BlocProvider( create: (context) => MovieCubit(), ), ], child: GetMaterialApp( debugShowCheckedModeBanner: false, home: DashboardPages(), ), ); } }
here is my movie model
import 'package:equatable/equatable.dart'; class MovieModels extends Equatable{ final String name; final int id; final String permalink; final String startDate; final String endDate; final String country; final String network; final String image; MovieModels({ this.name, this.id, this.permalink, this.startDate, this.endDate, this.country, this.network, this.image }); factory MovieModels.fromJson(Map<String,dynamic>map) => MovieModels( name: map['name'], id: map['id'] as int, permalink: map['permalink'], startDate: map['start_date'], endDate: map['end_date'], country: map['country'], network: map['network'], image: map['image_thumbnail_path'], ); @override List<Object> get props => [name,id,permalink,startDate,endDate,country,network,image]; }
but i got this log
Performing hot restart... Syncing files to device Android SDK built for x86... Restarted application in 2,606ms. [GETX] Instance "GetMaterialController" has been created [GETX] Instance "GetMaterialController" has been initialized [GETX] WARNING, consider using: "Get.to(() => Page())" instead of "Get.to(Page())". Using a widget function instead of a widget fully guarantees that the widget and its controllers will be removed from memory when they are no longer used. [GETX] GOING TO ROUTE /MovieDetailPage I/flutter (30967): [] I/flutter (30967): type 'List<dynamic>' is not a subtype of type 'Map<String, dynamic>' I/flutter (30967): null ======== Exception caught by widgets library ======================================================= The following NoSuchMethodError was thrown building FutureBuilder<MovieDetailModel>(dirty, dependencies: [MediaQuery], state: _FutureBuilderState<MovieDetailModel>#ac178): The getter 'bigImage' was called on null. Receiver: null Tried calling: bigImage The relevant error-causing widget was: FutureBuilder<MovieDetailModel> file:///C:/Users/Administrator/AndroidStudioProjects/movies/lib/movie_detail_page.dart:20:13 When the exception was thrown, this was the stack: #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5) #1 MovieDetailPage.build.<anonymous closure> (package:movies/movie_detail_page.dart:54:65) #2 _FutureBuilderState.build (package:flutter/src/widgets/async.dart:775:55) #3 StatefulElement.build (package:flutter/src/widgets/framework.dart:4716:27) #4 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4599:15) ... ====================================================================================================
is something wrong here? i already follow step by step from this guide https://www.youtube.com/watch?v=A4EE9EQ1umQ&t=685s but i got error on image. anybody can solving this? thank you
https://stackoverflow.com/questions/67342780/nosuchmethoderror-the-getter-bigimage-was-called-on-null May 01, 2021 at 12:06PM
没有评论:
发表评论