我该如何使AlertDialog完全执行我想要的操作?

时间:2019-04-01 23:42:14

标签: if-statement dart flutter dialog alertdialog

如果我将Slider设置为其他值并且onPressRaisedButton,我希望AlerDialog打印不同的String

到目前为止,这是我的代码,但我被卡住了:

import 'package:flutter/material.dart';

void main() {
  runApp(new MaterialApp(
    home: new MyApp(),
  ));
}

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


class _State extends State<MyApp> {




  var sFokozat = 'Nem nagy szám..';
  var sValue = (0.0);
  var sValasz = '';
  @override
  Widget build(BuildContext context) {
    return new Scaffold(

      appBar: new AppBar(
        centerTitle: true,
        backgroundColor: Colors.orange,
          title: new Text(
              'HáVéGé',
              textAlign: TextAlign.center,
              style: TextStyle(
                fontSize: 25,
                fontWeight: FontWeight.bold,
              )
          )

      ),
      body: new Center(
        child: Column(
          children: <Widget>[
            new Container(
              child: new Text(
                'Mekkora maszta már a Naszta?',
                style: TextStyle(
                  color: Colors.orange,
                  fontSize: 22,
                  fontWeight: FontWeight.bold,

                ),
              ),
              margin: EdgeInsets.all(20),
            ),
            new Container(
              child: new Slider(
                  min: 0.0,
                  max: 10.0,
                  divisions: 100,
                  value: (sValue),
                  activeColor: Colors.orange,
                  inactiveColor: Colors.orangeAccent,
                  onChanged: (newValue){
                    setState(() {
                      sValue=newValue;

                      sValue=newValue;
                      if (sValue >= 0.0 && sValue <= 1.0) {
                        sFokozat = 'Nem nagy szám..';
                      }
                      if (sValue >= 1.1 && sValue <= 3.0) {
                        sFokozat = 'Menő arc';
                      }
                      if (sValue >= 3.1 && sValue <= 5.0) {
                        sFokozat = 'Kurva menő arc';
                      }
                      if (sValue >= 5.1 && sValue <= 8.0) {
                        sFokozat = 'Elég sokat keres';
                      }
                      if (sValue >= 8.1 && sValue <= 10.0 ) {
                        sFokozat = 'Egy nappal előre kap HVG-t';
                      }

                    });
                  }
              ),
              height: 50,
              width: 350,
            ),
            new Container(
              child: new Text(
                      sFokozat,
                      style: TextStyle(
                        color: Colors.orange,
                        fontWeight: FontWeight.bold,
                        fontSize: 30
                      ),
              ),
              height: 80,
            ),
            new Container(
              child: new RaisedButton(
                child: new Text(
                    'Ekkora',
                    style: TextStyle(
                      color: Colors.white
                    ),
                ),

                onPressed: () => sDialog(context),
                shape: StadiumBorder(
                  side: BorderSide(
                      color: Colors.white,
                  )
                ),
                color: Colors.orange,
                elevation: 10,
              ),
            )
          ],
        ),
      )
    );
  }
  void sDialog (BuildContext context) {
    var alertDialog = AlertDialog(
      content: new Text(I want to put the IF condition here),
    );

    showDialog(
        context: context,
        builder: (BuildContext context) => alertDialog);
  }

}

如果sValue在0.0 && 1.0、1.1 && 3.0、3.1 && 5.0、5.1 && 8.0、8.1 && 10.0之间,我希望它在对话框的内容中打印不同的文本

0 个答案:

没有答案