Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 警报对话框在我的Flatter torch项目中不起作用_Flutter_Dart_Flutter Dependencies - Fatal编程技术网

Flutter 警报对话框在我的Flatter torch项目中不起作用

Flutter 警报对话框在我的Flatter torch项目中不起作用,flutter,dart,flutter-dependencies,Flutter,Dart,Flutter Dependencies,AlertDialog在我的项目中不起作用,添加了代码链接 以下是完整的工作代码 void main() => runApp(MaterialApp(home: new MyApp())); // this is what you need class MyApp extends StatefulWidget { @override _MyAppState createState() => new _MyAppState(); } class _MyAppState ex

AlertDialog
在我的项目中不起作用,添加了代码链接
以下是完整的工作代码

void main() => runApp(MaterialApp(home: new MyApp())); // this is what you need

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

class _MyAppState extends State<MyApp> {
  bool _hasFlash = false;
  bool _isOn = false;
  double _intensity = 1.0;

  @override
  initState() {
    super.initState();
    initPlatformState();
  }

  initPlatformState() async {
    bool hasFlash = await Lamp.hasLamp;
    print("Device has flash ? $hasFlash");
    setState(() { _hasFlash = hasFlash; });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
          image: DecorationImage(
              image: AssetImage("assets/images/chocolate_pic.png"), fit: BoxFit.cover)),
      child: Scaffold(
        backgroundColor: Colors.transparent,
        appBar: AppBar(
          elevation:  10 ,
          backgroundColor: Colors.transparent,
          title: Text('Flutter Torch'),
          centerTitle: true,
          leading: IconButton(
              icon: Icon(
                Icons.info,
                color: Colors.white,
              ),
              onPressed: () {
                showinfo(context);
              }
          ),
        ),
        body: new Center(
          child: new Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                ButtonTheme(
                  minWidth: 150.0,
                  height: 40.0,
                  child  : new RaisedButton(
                      child: Text('Flash is on: $_isOn'),
                      color: Theme.of(context).accentColor,
                      elevation: 10.0,
                      splashColor: Colors.blueGrey,
                      onPressed:  _turnFlash,
                      textColor: Colors.yellowAccent,
                      padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
                      shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
                  ),
                ),
                new Text('Device has flash: $_hasFlash',),
              ]),
        ),
      ),
    );
  }
  void showinfo(BuildContext context){
    var alertDialog = AlertDialog(
      title: Text('About Flutter Torch'),
      content: Text('app made by alik kumar ghosh'),
    );
    showDialog(
        context: context,
        builder: (BuildContext context){
          return alertDialog;
        }
    );
  }
  Future _turnFlash() async {
    _isOn ? Lamp.turnOff() : Lamp.turnOn(intensity: _intensity);
    var f = await Lamp.hasLamp;
    setState((){
      _hasFlash = f;
      _isOn = !_isOn;
    });
  }
}
void main()=>runApp(MaterialApp(主页:new MyApp());//这就是你需要的
类MyApp扩展了StatefulWidget{
@凌驾
_MyAppState createState()=>new_MyAppState();
}
类MyAppState扩展了状态{
bool\u hasFlash=假;
bool _isOn=false;
双倍强度=1.0;
@凌驾
initState(){
super.initState();
initPlatformState();
}
initPlatformState()异步{
bool hasplash=等待灯。hasplasm;
打印(“设备有闪存?$hasFlash”);
设置状态((){u hasFlash=hasFlash;});
}
@凌驾
小部件构建(构建上下文){
返回容器(
装饰:盒子装饰(
图像:装饰图像(
图片:AssetImage(“assets/images/chocolate_pic.png”)、fit:BoxFit.cover、,
孩子:脚手架(
背景颜色:颜色。透明,
appBar:appBar(
标高:10,
背景颜色:颜色。透明,
标题:文本(“颤振火炬”),
标题:对,
领先:IconButton(
图标:图标(
Icons.info,
颜色:颜色,白色,
),
已按下:(){
showinfo(上下文);
}
),
),
正文:新中心(
子:新列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
钮扣(
最小宽度:150.0,
身高:40.0,
孩子:新升起的按钮(
子项:文本('Flash已打开:$\u isOn'),
颜色:主题。背景。强调颜色,
标高:10.0,
颜色:颜色。蓝灰色,
按下按钮:_闪光灯,
textColor:Colors.yellowAccent,
填充:从LTRB(10,10,10,10)开始的边缘设置,
形状:新圆角矩形边框(边框半径:新边框半径。圆形(30.0))
),
),
新文本('设备有闪存:$\u hasFlash',),
]),
),
),
);
}
void showinfo(构建上下文){
var-alertDialog=alertDialog(
标题:文本(“关于颤振火炬”),
内容:文本(“alik kumar ghosh制作的应用程序”),
);
显示对话框(
上下文:上下文,
生成器:(BuildContext上下文){
返回警报对话框;
}
);
}
Future\u turnFlash()异步{
_isOn?灯。关闭():灯。打开(强度:_强度);
var f=等待灯。hasLamp;
设置状态(){
_hasFlash=f;
_伊森=!\u伊森;
});
}
}

以下是完整的工作代码

void main() => runApp(MaterialApp(home: new MyApp())); // this is what you need

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

class _MyAppState extends State<MyApp> {
  bool _hasFlash = false;
  bool _isOn = false;
  double _intensity = 1.0;

  @override
  initState() {
    super.initState();
    initPlatformState();
  }

  initPlatformState() async {
    bool hasFlash = await Lamp.hasLamp;
    print("Device has flash ? $hasFlash");
    setState(() { _hasFlash = hasFlash; });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
          image: DecorationImage(
              image: AssetImage("assets/images/chocolate_pic.png"), fit: BoxFit.cover)),
      child: Scaffold(
        backgroundColor: Colors.transparent,
        appBar: AppBar(
          elevation:  10 ,
          backgroundColor: Colors.transparent,
          title: Text('Flutter Torch'),
          centerTitle: true,
          leading: IconButton(
              icon: Icon(
                Icons.info,
                color: Colors.white,
              ),
              onPressed: () {
                showinfo(context);
              }
          ),
        ),
        body: new Center(
          child: new Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                ButtonTheme(
                  minWidth: 150.0,
                  height: 40.0,
                  child  : new RaisedButton(
                      child: Text('Flash is on: $_isOn'),
                      color: Theme.of(context).accentColor,
                      elevation: 10.0,
                      splashColor: Colors.blueGrey,
                      onPressed:  _turnFlash,
                      textColor: Colors.yellowAccent,
                      padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
                      shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
                  ),
                ),
                new Text('Device has flash: $_hasFlash',),
              ]),
        ),
      ),
    );
  }
  void showinfo(BuildContext context){
    var alertDialog = AlertDialog(
      title: Text('About Flutter Torch'),
      content: Text('app made by alik kumar ghosh'),
    );
    showDialog(
        context: context,
        builder: (BuildContext context){
          return alertDialog;
        }
    );
  }
  Future _turnFlash() async {
    _isOn ? Lamp.turnOff() : Lamp.turnOn(intensity: _intensity);
    var f = await Lamp.hasLamp;
    setState((){
      _hasFlash = f;
      _isOn = !_isOn;
    });
  }
}
void main()=>runApp(MaterialApp(主页:new MyApp());//这就是你需要的
类MyApp扩展了StatefulWidget{
@凌驾
_MyAppState createState()=>new_MyAppState();
}
类MyAppState扩展了状态{
bool\u hasFlash=假;
bool _isOn=false;
双倍强度=1.0;
@凌驾
initState(){
super.initState();
initPlatformState();
}
initPlatformState()异步{
bool hasplash=等待灯。hasplasm;
打印(“设备有闪存?$hasFlash”);
设置状态((){u hasFlash=hasFlash;});
}
@凌驾
小部件构建(构建上下文){
返回容器(
装饰:盒子装饰(
图像:装饰图像(
图片:AssetImage(“assets/images/chocolate_pic.png”)、fit:BoxFit.cover、,
孩子:脚手架(
背景颜色:颜色。透明,
appBar:appBar(
标高:10,
背景颜色:颜色。透明,
标题:文本(“颤振火炬”),
标题:对,
领先:IconButton(
图标:图标(
Icons.info,
颜色:颜色,白色,
),
已按下:(){
showinfo(上下文);
}
),
),
正文:新中心(
子:新列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
钮扣(
最小宽度:150.0,
身高:40.0,
孩子:新升起的按钮(
子项:文本('Flash已打开:$\u isOn'),
颜色:主题。背景。强调颜色,
标高:10.0,
颜色:颜色。蓝灰色,
按下按钮:_闪光灯,
textColor:Colors.yellowAccent,
填充:从LTRB(10,10,10,10)开始的边缘设置,
形状:新圆角矩形边框(边框半径:新边框半径。圆形(30.0))
),
),
新文本('设备有闪存:$\u hasFlash',),
]),
),
),
);
}
void showinfo(构建上下文){
var-alertDialog=alertDialog(
标题:文本(“关于颤振火炬”),
内容:文本(“alik kumar ghosh制作的应用程序”),
);
显示对话框(
上下文:上下文,
生成器:(BuildContext上下文){
返回警报对话框;
}
);
}
Future\u turnFlash()异步{
_isOn?灯。关闭():灯。打开(强度:_强度);
var f=等待灯。hasLamp;
设置状态(){
_hasFlash=f;
_伊森=!\u伊森;
});
}
}

您所需要的只是根目录下的
MaterialApp
小部件,因此我的答案的第一行解决了您的问题。欢迎使用so!我建议您通过添加更多详细信息来更新您的问题。它可以帮助您更加关注您的问题。您所需要的只是根目录下的
MaterialApp
小部件,因此我的答案的第一行解决了您的问题。欢迎使用so!我建议您通过添加更多详细信息来更新您的问题。我