No MaterialLocalizations found.

flutter 显示一个dialog的时候显示出这个log

E/flutter ( 3466): [ERROR:flutter/shell/common/shell.cc(181)] Dart Error: Unhandled exception:
E/flutter ( 3466): No MaterialLocalizations found.
E/flutter ( 3466): MyHomePage widgets require MaterialLocalizations to be provided by a Localizations widget ancestor.
E/flutter ( 3466): Localizations are used to generate many different messages, labels,and abbreviations which are used by the material library. 
E/flutter ( 3466): To introduce a MaterialLocalizations, either use a  MaterialApp at the root of your application to include them automatically, or add a Localization widget with a MaterialLocalizations delegate.
E/flutter ( 3466): The specific widget that could not find a MaterialLocalizations ancestor was:
E/flutter ( 3466):   MyHomePage
E/flutter ( 3466): The ancestors of this widget were:
E/flutter ( 3466):   [root]

 

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

  final String title;

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

class _MyHomePageState extends State<MyHomePage>
    with SingleTickerProviderStateMixin {
  int _counter = 0;
  AnimationController animationController;
  Animation animation;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    animationController = new AnimationController(
        vsync: this, duration: Duration(milliseconds: 3000));
    animation = Tween(begin: 1.0, end: 2.0).animate(CurvedAnimation(
        parent: animationController, curve: Curves.fastOutSlowIn))
      ..addStatusListener((status) {
        if (status == AnimationStatus.completed) {
          animationController.reverse();
        }
        if (status == AnimationStatus.dismissed) {
          animationController.forward();
        }
      })
      ..addListener(() {
        setState(() {});
      });
    animationController.repeat();
  }

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    Future.delayed(Duration.zero, () => showMyDialog(context));
    return new MaterialApp(
//        localizationsDelegates: [
//          // ... app-specific localization delegate[s] here
//          GlobalMaterialLocalizations.delegate,
//          GlobalWidgetsLocalizations.delegate,
//        ],
//        supportedLocales: [
//          const Locale('zh', 'CH'),
//        ],

        home: new Scaffold(
      body: new Center(
          child: new Stack(
        children: <Widget>[
          Transform.translate(
            offset: Offset(animation.value, animation.value),
            child: Image.asset(
              "assets/cute1.jpg",
              width: 21.0,
              height: 21.0,
              fit: BoxFit.fill,
            ),
          ),
          Transform.translate(
            offset: Offset(animation.value * 2, animation.value * 2),
            child: Image.asset(
              "assets/add.png",
              width: 21.0,
              height: 21.0,
              fit: BoxFit.fill,
            ),
          ),
//            new RaisedButton(
//                child: new Text('提交'),
//                onPressed: () {
//                  showMyDialog(context);
//                }
//            )
        ],
      )),
      floatingActionButton: new FloatingActionButton(
        onPressed: (){showMyDialog(context);},
        tooltip: 'Increment',
        child: new Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.


        ));
    // return
  }

  void showMyDialog(BuildContext context) {
    showDialog<bool>(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(

            content: const Text(
              'Message',
            ),
            actions: <Widget>[
              FlatButton(
                child: const Text('OK'),
                onPressed: () {
                  Navigator.of(context).pop(true);
                },
              ),
            ],


        );

//      return new SimpleDialog(
//        title: new Text('Test'),
//        children: <Widget>[
//          new RadioListTile(
//            title: new Text('Testing'), value: null, groupValue: null, onChanged: (value) {},
//          )
//        ],
//      );
       // return
      },
    );
  }
}

main函数直接运行的myHomepage,直接运行是没有问题的,但是只要显示一个dialog就会出错,最后外面有加了一层stateless,ok了

或者在外面加一个

Material
### 回答1: "No resources found" 是一个错误提示,表示在程序执行过程中找不到所需的资源。可能是因为文件路径或文件名有误,或者是需要的文件不存在或被损坏。具体应该根据程序上下文和错误提示来分析解决。 ### 回答2: "No resources found."是一种常见的错误消息,指的是在系统中没有找到所需的资源。这种错误通常发生在软件或应用程序试图访问或加载特定的资源时,无法找到资源文件或访问路径错误。 这个错误可能由以下几种原因引起: 1. 资源文件丢失或被删除:当软件或应用程序需要使用特定的资源文件时,如果这些文件不存在或被意外删除,就会导致"No resources found."错误。 2. 资源路径错误:如果软件或应用程序在访问资源文件时提供了错误的路径,或者资源文件的位置发生了变化但没有及时更新相应的路径,也会出现该错误。 3. 资源文件权限问题:某些情况下,当软件或应用程序没有足够的权限来访问资源文件时,也会出现错误消息"No resources found."。这可能是因为访问权限被设置为只读,或者是由于操作系统或防病毒软件的限制。 解决该错误的方法通常包括: 1. 检查资源文件是否存在并位于正确的位置。如果资源文件已经被删除或移到了其他位置,需要将其恢复或更新相应的路径。 2. 检查资源文件的读取权限。确保软件或应用程序具有足够的权限来访问所需的资源文件。 3. 如果是通过网络访问资源,可以检查网络连接是否正常,以及资源服务器是否可用。 总之,当出现"No resources found."错误时,需要仔细检查资源文件的存在、路径和权限,以确保软件或应用程序能够成功地访问所需的资源。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值