方法“RaishedButton”未定义

Ala*_*aya 17 android ios flutter

我创建了一个新项目并在 Visual Studio Code 中编写了一些代码。

这是我的源代码:

import 'package:flutter/material.dart';
    
    class Raisedbutton extends StatelessWidget {
      Widget build(BuildContext context) {
        return MaterialApp(
          title: "Raised Button",
          home: Scaffold(
            appBar: AppBar(
                title: Text("Latihan membuat Raised button"),
                backgroundColor: Colors.green),
            body: Center(
              child: Column(
                children: <Widget>[
                  Expanded(
                    child: Row(
                      children: <Widget>[
                        Text("1. Pizza"),
                        Text("2. Satay"),
                        Text("3. Spagethi"),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          ),
        );
      }
    }
    
    class Raised extends StatelessWidget {
      Widget build(BuildContext context) {
        var button = Container(
          margin: EdgeInsets.only(top: 50.0),
          child: RaisedButton(
              child: Text("Click here"),
              color: Colors.blue,
              elevation: 5.0,
              onPressed: () {
                order(context);
              }),
        );
      }


  void order(BuildContext context) {
    var alert = AlertDialog(title:Text("CONGRATULATION", style: TextStyle(color: Colors.white, fontSize: 25.0),),content: Text("You got ZONK!!!"),);
  }
}
Run Code Online (Sandbox Code Playgroud)

是的,我的源代码有RaisedButton错误。

我该如何解决这个问题?感谢您的帮助!

Mαπ*_*π.0 50

RaisingButton现已弃用并由ElevatedButton取代。根据文档:

FlatButton、RaishedButton 和 OutlineButton 已分别替换为 TextButtonElevatedButtonOutlinedButton 。ButtonTheme 已替换为 TextButtonThemeElevatedButtonThemeOutlinedButtonTheme。原始类最终将被删除,请迁移使用它们的代码。flutter.dev/go/material-button-migration-guide中有新按钮和按钮主题类的详细迁移指南 。


Ram*_*ali 12

RaisingButton 现已弃用。

使用 ElevatedButton 代替 RaisingButton