DPLYR-dev / SplashScreenFlutterPackage

A small splashscreen used as intro for flutter applications easily with a lot of customizations ❤️🥳
MIT License
294 stars 122 forks source link

No MediaQuery widget ancestor found #59

Closed Tamir198 closed 3 years ago

Tamir198 commented 3 years ago

I have tried to use the basic example from pub.dev but I am getting this error:

======== Exception caught by widgets library =======================================================
The following assertion was thrown building SplashScreen(state: _SplashScreenState#179cb):
No MediaQuery widget ancestor found.

Scaffold widgets require a MediaQuery widget ancestor.
The specific widget that could not find a MediaQuery ancestor was: Scaffold
  dirty
  state: ScaffoldState#1979d(lifecycle state: initialized, tickers: tracking 2 tickers)
The ownership chain for the affected widget is: "Scaffold ← SplashScreen ← MyApp ← [root]"

No MediaQuery ancestor could be found starting from the context that was passed to MediaQuery.of(). This can happen because you have not added a WidgetsApp, CupertinoApp, or MaterialApp widget (those widgets introduce a MediaQuery), or it can happen if the context you use comes from a widget above those widgets.

The relevant error-causing widget was: 
  SplashScreen file:///G:/TAMIR/Desktop/Ghinbli%20app/Ghibli-fun/lib/main.dart:29:13
When the exception was thrown, this was the stack: 
#0      debugCheckHasMediaQuery.<anonymous closure> (package:flutter/src/widgets/debug.dart:218:7)
#1      debugCheckHasMediaQuery (package:flutter/src/widgets/debug.dart:233:4)
#2      MediaQuery.of (package:flutter/src/widgets/media_query.dart:820:12)
#3      ScaffoldState.didChangeDependencies (package:flutter/src/material/scaffold.dart:2775:50)
#4      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4843:11)
...
====================================================================================================

My code (taken from the library readme example page):

import 'package:flutter/material.dart';
import 'package:splashscreen/splashscreen.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return  SplashScreen(
      seconds: 14,
      navigateAfterSeconds: new AfterSplash(),
      title:  Text('Welcome In SplashScreen', style:  TextStyle(fontWeight: FontWeight.bold, fontSize: 20.0),
      ),
      image:  Image.network(
          'https://flutter.io/images/catalog-widget-placeholder.png'),
      backgroundColor: Colors.white,
      loaderColor: Colors.red,
    );
  }
}

I am getting this error while using:

Widget test fails with No MediaQuery widget found is the closest thing I could find searching for this problem but it didn't solve my problem.

simone40love commented 3 years ago

You need to put Scaffold in navigateAfterSeconds , and wrap SplashScreen in MaterialApp.

ahmedmgh67 commented 3 years ago

You need to wrap your app in a MaterialApp widget

Agiofobia commented 2 years ago

As everybody else says, you need to wrap it in a MaterialApp widget

oti-adjei commented 2 years ago

You need to wrap your app in a MaterialApp widget

Do you mind demonstrating this?