MediaQuery.of() called with a context that does not contain MediaQuery

0

I was recently watching a video to convert an adobe xd prototype into an app using flutter. however I got this error:

MediaQuery.of() called with a context that does not contain MediaQuery. No MediaQuery could be found starting from the context that was passed to MediaQuery.of(). This can happen because you do not have a WidgetApp or MaterialApp widget (those widgets introduce MediaQuery), or it can happen if the context you use comes above those widgets. the context used was : Scaffold

Here's my code :

import 'package:adobe_xd/pinned.dart';
import './Purple1.dart';
import 'package:adobe_xd/page_link.dart';
import 'package:flutter_svg/flutter_svg.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) { 
     return MaterialApp( debugShowCheckedModeBanner: false, home: Scaffold(
      backgroundColor: const Color(0xffa118ea),
      body: Stack(
        children: <Widget>[
          Pinned.fromSize(
            bounds: Rect.fromLTWH(26.0, 175.9, 324.0, 477.0),
            size: Size(375.0, 812.0),
            pinLeft: true,
            pinRight: true,
            fixedHeight: true,
            child:
                // Adobe XD layer: 'Purple background' (shape)
                Container(
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(162.0),
                gradient: LinearGradient(
                  begin: Alignment(0.0, -1.0),
                  end: Alignment(0.0, 0.77),
                  colors: [
                    const Color(0xff67bcc9),
                    const Color(0x8168bcca),
                    const Color(0x0068bcca)
                  ],
                  stops: [0.0, 0.463, 1.0],
                ),
              ),
            ),
          ),
          Pinned.fromSize(
            bounds: Rect.fromLTWH(9.6, 0.0, 349.3, 779.2),
            size: Size(375.0, 812.0),
            pinLeft: true,
            pinRight: true,
            pinTop: true,
            pinBottom: true,
            child:
                // Adobe XD layer: 'Stars' (group)
                Stack(
              children: <Widget>[
                Pinned.fromSize(
                  bounds: Rect.fromLTWH(30.4, 162.5, 16.0, 16.0),
                  size: Size(349.3, 779.2),
                  pinLeft: true,
                  fixedWidth: true,
                  fixedHeight: true,
                  child: SvgPicture.string(
                    _svg_7lp0ce,
                    allowDrawingOutsideViewBox: true,
                    fit: BoxFit.fill,
                  ),
                ),
                Pinned.fromSize(
                  bounds: Rect.fromLTWH(81.4, 0.0, 16.0, 16.0),
                  size: Size(349.3, 779.2),
                  pinTop: true,
                  fixedWidth: true,
                  fixedHeight: true,
                  child: SvgPicture.string(
                    _svg_3v354e,
                    allowDrawingOutsideViewBox: true,
                    fit: BoxFit.fill,
                  ),
                ),
                Pinned.fromSize(
                  bounds: Rect.fromLTWH(312.8, 17.4, 13.2, 13.2),
                  size: Size(349.3, 779.2),
                  pinRight: true,
                  pinTop: true,
                  fixedWidth: true,
                  fixedHeight: true,
                  child: SvgPicture.string(
                    _svg_wvx5ws,
                    allowDrawingOutsideViewBox: true,
                    fit: BoxFit.fill,
                  ),
                ),
                Pinned.fromSize(
                  bounds: Rect.fromLTWH(0.0, 675.6, 20.8, 20.8),
                  size: Size(349.3, 779.2),
                  pinLeft: true,
                  pinBottom: true,
                  fixedWidth: true,
                  fixedHeight: true,
                  child: SvgPicture.string(
                    _svg_iizdfm,
                    allowDrawingOutsideViewBox: true,
                    fit: BoxFit.fill,
                  ),
                ),
                Pinned.fromSize(
                  bounds: Rect.fromLTWH(231.2, 768.8, 10.4, 10.4),
                  size: Size(349.3, 779.2),
                  pinBottom: true,
                  fixedWidth: true,
                  fixedHeight: true,
                  child: SvgPicture.string(
                    _svg_mpl7eu,
                    allowDrawingOutsideViewBox: true,
                    fit: BoxFit.fill,
                  ),
                ),
                Pinned.fromSize(
                  bounds: Rect.fromLTWH(339.5, 597.1, 9.8, 9.8),
                  size: Size(349.3, 779.2),
                  pinRight: true,
                  fixedWidth: true,
                  fixedHeight: true,
                  child: SvgPicture.string(
                    _svg_8fh4qi,
                    allowDrawingOutsideViewBox: true,
                    fit: BoxFit.fill,
                  ),
                ),
                Pinned.fromSize(
                  bounds: Rect.fromLTWH(255.5, 299.2, 9.8, 9.8),
                  size: Size(349.3, 779.2),
                  fixedWidth: true,
                  fixedHeight: true,
                  child: SvgPicture.string(
                    _svg_u22uq8,
                    allowDrawingOutsideViewBox: true,
                    fit: BoxFit.fill,
                  ),
                ),
                Pinned.fromSize(
                  bounds: Rect.fromLTWH(339.5, 597.1, 9.8, 9.8),
                  size: Size(349.3, 779.2),
                  pinRight: true,
                  fixedWidth: true,
                  fixedHeight: true,
                  child: SvgPicture.string(
                    _svg_8fh4qi,
                    allowDrawingOutsideViewBox: true,
                    fit: BoxFit.fill,
                  ),
                ),
              ],
            ),
          ),
          Pinned.fromSize(
            bounds: Rect.fromLTWH(-9.0, 510.0, 392.0, 143.0),
            size: Size(375.0, 812.0),
            pinLeft: true,
            pinRight: true,
            fixedHeight: true,
            child: Text(
              'YOU\'VE BEEN INVITED TO A WEDDING\n',
              style: TextStyle(
                fontFamily: 'Mark Pro',
                fontSize: 25,
                color: const Color(0xffffffff),
                letterSpacing: 15,
                fontWeight: FontWeight.w700,
                height: 1.4,
              ),
              textAlign: TextAlign.center,
            ),
          ),
          Pinned.fromSize(
            bounds: Rect.fromLTWH(51.0, 236.8, 273.0, 273.0),
            size: Size(375.0, 812.0),
            pinLeft: true,
            pinRight: true,
            fixedHeight: true,
            child:
                // Adobe XD layer: 'jewel' (shape)
                Container(
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(9.0),
                image: DecorationImage(
                  image: const AssetImage(''),
                  fit: BoxFit.fill,
                ),
              ),
            ),
          ),
          Pinned.fromSize(
            bounds: Rect.fromLTWH(17.0, 75.0, 342.0, 45.0),
            size: Size(375.0, 812.0),
            child: Text(
              'CONGRATULATIONS\n',
              style: TextStyle(
                fontFamily: 'Mark Pro',
                fontSize: 19,
                color: const Color(0xffffffff),
                letterSpacing: 11.4,
                fontWeight: FontWeight.w700,
                height: 1,
              ),
              textAlign: TextAlign.center,
            ),
          ),
          Pinned.fromSize(
            bounds: Rect.fromLTWH(26.0, 652.0, 324.0, 76.0),
            size: Size(375.0, 812.0),
            pinLeft: true,
            pinRight: true,
            pinBottom: true,
            fixedHeight: true,
            child: PageLink(
              links: [
                PageLinkInfo(
                  transition: LinkTransition.SlideLeft,
                  ease: Curves.easeOut,
                  duration: 0.6,
                  pageBuilder: () => Purple1(),
                ),
              ],
              child: Container(
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(38.0),
                  color: const Color(0xffffffff),
                  border:
                      Border.all(width: 1.0, color: const Color(0xff707070)),
                ),
              ),
            ),
          ),
          Pinned.fromSize(
            bounds: Rect.fromLTWH(46.0, 669.7, 283.0, 74.0),
            size: Size(375.0, 812.0),
            pinLeft: true,
            pinRight: true,
            pinBottom: true,
            fixedHeight: true,
            child: PageLink(
              links: [
                PageLinkInfo(
                  transition: LinkTransition.SlideLeft,
                  ease: Curves.easeOut,
                  duration: 0.6,
                  pageBuilder: () => Purple1(),
                ),
              ],
              child: Text(
                'I\'M IN!',
                style: TextStyle(
                  fontFamily: 'Mark Pro',
                  fontSize: 30,
                  color: const Color(0xff8105f3),
                  letterSpacing: 18,
                  fontWeight: FontWeight.w700,
                  height: 0.6666666666666666,
                ),
                textAlign: TextAlign.center,
              ),
            ),
          ),
        ],
      ),
   )
     );
  
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      // This call to setState tells the Flutter framework that something has
      // changed in this State, which causes it to rerun the build method below
      // so that the display can reflect the updated values. If we changed
      // _counter without calling setState(), then the build method would not be
      // called again, and so nothing would appear to happen.
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: Column(
          // Column is also a layout widget. It takes a list of children and
          // arranges them vertically. By default, it sizes itself to fit its
          // children horizontally, and tries to be as tall as its parent.
          //
          // Invoke "debug painting" (press "p" in the console, choose the
          // "Toggle Debug Paint" action from the Flutter Inspector in Android
          // Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
          // to see the wireframe for each widget.
          //
          // Column has various properties to control how it sizes itself and
          // how it positions its children. Here we use mainAxisAlignment to
          // center the children vertically; the main axis here is the vertical
          // axis because Columns are vertical (the cross axis would be
          // horizontal).
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
const String _svg_7lp0ce =
    '<svg viewBox="30.4 162.5 16.0 16.0" ><path transform="translate(30.41, 162.54)" d="M 5.000400066375732 12.99960041046143 L 5.000400066375732 10.99980068206787 L 2.99970006942749 10.99980068206787 C 1.34280002117157 10.99980068206787 0 9.657000541687012 0 8.000100135803223 C 0 6.343200206756592 1.34280002117157 5.000400066375732 2.99970006942749 5.000400066375732 L 5.000400066375732 5.000400066375732 L 5.000400066375732 2.99970006942749 C 5.000400066375732 1.34280002117157 6.343200206756592 0 8.000100135803223 0 C 9.657000541687012 0 10.99980068206787 1.34280002117157 10.99980068206787 2.99970006942749 L 10.99980068206787 5.000400066375732 L 12.99960041046143 5.000400066375732 C 14.65650081634521 5.000400066375732 16.00020027160645 6.343200206756592 16.00020027160645 8.000100135803223 C 16.00020027160645 9.657000541687012 14.65650081634521 10.99980068206787 12.99960041046143 10.99980068206787 L 10.99980068206787 10.99980068206787 L 10.99980068206787 12.99960041046143 C 10.99980068206787 14.65650081634521 9.657000541687012 16.00020027160645 8.000100135803223 16.00020027160645 C 6.343200206756592 16.00020027160645 5.000400066375732 14.65650081634521 5.000400066375732 12.99960041046143 Z" fill="#ffffff" stroke="none" stroke-width="1" stroke-miterlimit="4" stroke-linecap="butt" /></svg>';
const String _svg_3v354e =
    '<svg viewBox="81.4 0.0 16.0 16.0" ><path transform="translate(81.41, 0.0)" d="M 5.000400066375732 12.99960041046143 L 5.000400066375732 10.99980068206787 L 2.99970006942749 10.99980068206787 C 1.34280002117157 10.99980068206787 0 9.657000541687012 0 8.000100135803223 C 0 6.343200206756592 1.34280002117157 5.000400066375732 2.99970006942749 5.000400066375732 L 5.000400066375732 5.000400066375732 L 5.000400066375732 2.99970006942749 C 5.000400066375732 1.34280002117157 6.343200206756592 0 8.000100135803223 0 C 9.657000541687012 0 10.99980068206787 1.34280002117157 10.99980068206787 2.99970006942749 L 10.99980068206787 5.000400066375732 L 12.99960041046143 5.000400066375732 C 14.65650081634521 5.000400066375732 16.00020027160645 6.343200206756592 16.00020027160645 8.000100135803223 C 16.00020027160645 9.657000541687012 14.65650081634521 10.99980068206787 12.99960041046143 10.99980068206787 L 10.99980068206787 10.99980068206787 L 10.99980068206787 12.99960041046143 C 10.99980068206787 14.65650081634521 9.657000541687012 16.00020027160645 8.000100135803223 16.00020027160645 C 6.343200206756592 16.00020027160645 5.000400066375732 14.65650081634521 5.000400066375732 12.99960041046143 Z" fill="#ffffff" stroke="none" stroke-width="1" stroke-miterlimit="4" stroke-linecap="butt" /></svg>';
const String _svg_wvx5ws =
    '<svg viewBox="312.8 17.4 13.2 13.2" ><path transform="translate(312.83, 17.42)" d="M 4.114799976348877 10.69740009307861 L 4.114799976348877 9.052200317382813 L 2.468700170516968 9.052200317382813 C 1.105200052261353 9.052200317382813 0 7.947000026702881 0 6.583500385284424 C 0 5.220000267028809 1.105200052261353 4.114799976348877 2.468700170516968 4.114799976348877 L 4.114799976348877 4.114799976348877 L 4.114799976348877 2.468700170516968 C 4.114799976348877 1.105200052261353 5.220000267028809 0 6.583500385284424 0 C 7.947000026702881 0 9.052200317382813 1.105200052261353 9.052200317382813 2.468700170516968 L 9.052200317382813 4.114799976348877 L 10.69740009307861 4.114799976348877 C 12.06090068817139 4.114799976348877 13.16610050201416 5.220000267028809 13.16610050201416 6.583500385284424 C 13.16610050201416 7.947000026702881 12.06090068817139 9.052200317382813 10.69740009307861 9.052200317382813 L 9.052200317382813 9.052200317382813 L 9.052200317382813 10.69740009307861 C 9.052200317382813 12.06090068817139 7.947000026702881 13.16610050201416 6.583500385284424 13.16610050201416 C 5.220000267028809 13.16610050201416 4.114799976348877 12.06090068817139 4.114799976348877 10.69740009307861 Z" fill="#ffffff" stroke="none" stroke-width="1" stroke-miterlimit="4" stroke-linecap="butt" /></svg>';
const String _svg_iizdfm =
    '<svg viewBox="0.0 675.6 20.8 20.8" ><path transform="translate(0.0, 675.59)" d="M 6.507900238037109 16.92000007629395 L 6.507900238037109 14.31720066070557 L 3.905100107192993 14.31720066070557 C 1.74779999256134 14.31720066070557 0 12.5693998336792 0 10.41300010681152 C 0 8.25570011138916 1.74779999256134 6.507900238037109 3.905100107192993 6.507900238037109 L 6.507900238037109 6.507900238037109 L 6.507900238037109 3.905100107192993 C 6.507900238037109 1.74779999256134 8.25570011138916 0 10.41300010681152 0 C 12.5693998336792 0 14.31720066070557 1.74779999256134 14.31720066070557 3.905100107192993 L 14.31720066070557 6.507900238037109 L 16.92000007629395 6.507900238037109 C 19.07730102539063 6.507900238037109 20.82509994506836 8.25570011138916 20.82509994506836 10.41300010681152 C 20.82509994506836 12.5693998336792 19.07730102539063 14.31720066070557 16.92000007629395 14.31720066070557 L 14.31720066070557 14.31720066070557 L 14.31720066070557 16.92000007629395 C 14.31720066070557 19.07730102539063 12.5693998336792 20.82509994506836 10.41300010681152 20.82509994506836 C 8.25570011138916 20.82509994506836 6.507900238037109 19.07730102539063 6.507900238037109 16.92000007629395 Z" fill="#ffffff" fill-opacity="0.6" stroke="none" stroke-width="1" stroke-opacity="0.6" stroke-miterlimit="4" stroke-linecap="butt" /></svg>';
const String _svg_mpl7eu =
    '<svg viewBox="231.2 768.8 10.4 10.4" ><path transform="translate(231.23, 768.82)" d="M 3.237300157546997 8.417699813842773 L 3.237300157546997 7.122600078582764 L 1.942200064659119 7.122600078582764 C 0.8694000244140625 7.122600078582764 0 6.253200054168701 0 5.180399894714355 C 0 4.107600212097168 0.8694000244140625 3.237300157546997 1.942200064659119 3.237300157546997 L 3.237300157546997 3.237300157546997 L 3.237300157546997 1.942200064659119 C 3.237300157546997 0.8694000244140625 4.107600212097168 0 5.180399894714355 0 C 6.253200054168701 0 7.122600078582764 0.8694000244140625 7.122600078582764 1.942200064659119 L 7.122600078582764 3.237300157546997 L 8.417699813842773 3.237300157546997 C 9.490500450134277 3.237300157546997 10.35990047454834 4.107600212097168 10.35990047454834 5.180399894714355 C 10.35990047454834 6.253200054168701 9.490500450134277 7.122600078582764 8.417699813842773 7.122600078582764 L 7.122600078582764 7.122600078582764 L 7.122600078582764 8.417699813842773 C 7.122600078582764 9.490500450134277 6.253200054168701 10.35990047454834 5.180399894714355 10.35990047454834 C 4.107600212097168 10.35990047454834 3.237300157546997 9.490500450134277 3.237300157546997 8.417699813842773 Z" fill="#ffffff" fill-opacity="0.6" stroke="none" stroke-width="1" stroke-opacity="0.6" stroke-miterlimit="4" stroke-linecap="butt" /></svg>';
const String _svg_8fh4qi =
    '<svg viewBox="339.5 597.1 9.8 9.8" ><path transform="translate(339.51, 597.09)" d="M 3.0663001537323 7.97130012512207 L 3.0663001537323 6.745500087738037 L 1.839600086212158 6.745500087738037 C 0.8235000371932983 6.745500087738037 0 5.921999931335449 0 4.905900001525879 C 0 3.889800071716309 0.8235000371932983 3.0663001537323 1.839600086212158 3.0663001537323 L 3.0663001537323 3.0663001537323 L 3.0663001537323 1.839600086212158 C 3.0663001537323 0.8235000371932983 3.889800071716309 0 4.905900001525879 0 C 5.921999931335449 0 6.745500087738037 0.8235000371932983 6.745500087738037 1.839600086212158 L 6.745500087738037 3.0663001537323 L 7.97130012512207 3.0663001537323 C 8.987400054931641 3.0663001537323 9.810900688171387 3.889800071716309 9.810900688171387 4.905900001525879 C 9.810900688171387 5.921999931335449 8.987400054931641 6.745500087738037 7.97130012512207 6.745500087738037 L 6.745500087738037 6.745500087738037 L 6.745500087738037 7.97130012512207 C 6.745500087738037 8.987400054931641 5.921999931335449 9.810900688171387 4.905900001525879 9.810900688171387 C 3.889800071716309 9.810900688171387 3.0663001537323 8.987400054931641 3.0663001537323 7.97130012512207 Z" fill="#ffffff" stroke="none" stroke-width="1" stroke-miterlimit="4" stroke-linecap="butt" /></svg>';
const String _svg_u22uq8 =
    '<svg viewBox="255.5 299.2 9.8 9.8" ><path transform="translate(255.51, 299.21)" d="M 3.0663001537323 7.97130012512207 L 3.0663001537323 6.745500087738037 L 1.839600086212158 6.745500087738037 C 0.8235000371932983 6.745500087738037 0 5.921999931335449 0 4.905900001525879 C 0 3.889800071716309 0.8235000371932983 3.0663001537323 1.839600086212158 3.0663001537323 L 3.0663001537323 3.0663001537323 L 3.0663001537323 1.839600086212158 C 3.0663001537323 0.8235000371932983 3.889800071716309 0 4.905900001525879 0 C 5.921999931335449 0 6.745500087738037 0.8235000371932983 6.745500087738037 1.839600086212158 L 6.745500087738037 3.0663001537323 L 7.97130012512207 3.0663001537323 C 8.987400054931641 3.0663001537323 9.810900688171387 3.889800071716309 9.810900688171387 4.905900001525879 C 9.810900688171387 5.921999931335449 8.987400054931641 6.745500087738037 7.97130012512207 6.745500087738037 L 6.745500087738037 6.745500087738037 L 6.745500087738037 7.97130012512207 C 6.745500087738037 8.987400054931641 5.921999931335449 9.810900688171387 4.905900001525879 9.810900688171387 C 3.889800071716309 9.810900688171387 3.0663001537323 8.987400054931641 3.0663001537323 7.97130012512207 Z" fill="#ffffff" fill-opacity="0.6" stroke="none" stroke-width="1" stroke-opacity="0.6" stroke-miterlimit="4" stroke-linecap="butt" /></svg>';

flutter
adobe-xd

1 Answer

0

Wrap the scaffold with a MaterialApp

answered on Stack Overflow Aug 1, 2020 by Madhavam Shahi

User contributions licensed under CC BY-SA 3.0