0

I can't use RaisedButton in flutter because I use Cupertino library. The error is :

lib/main.dart:24:15: Error: The method 'RaisedButton' isn't defined for the class 'MyApp'.
 - 'MyApp' is from 'package:myflutter/main.dart' ('lib/main.dart').
Try correcting the name to the name of an existing method, or defining a method named 'RaisedButton'.
              RaisedButton(

if I use CupertinoButton, it is ok but I want to use RaisedButton. I add

*import 'package:flutter/cupertino.dart';*

but it doesn't work.

Simon
  • 1
  • 1

1 Answers1

0

RaisedButton has been replaced with ElevatedButton. You can override the style to get the same effect.

Snippet from doc.

final ButtonStyle raisedButtonStyle = ElevatedButton.styleFrom(
  onPrimary: Colors.black87,
  primary: Colors.grey[300],
  minimumSize: Size(88, 36),
  padding: EdgeInsets.symmetric(horizontal: 16),
  shape: const RoundedRectangleBorder(
    borderRadius: BorderRadius.all(Radius.circular(2)),
  ),
);
ElevatedButton(
  style: raisedButtonStyle,
  onPressed: () { },
  child: Text('Looks like a RaisedButton'),
)

enter image description here

Find more about restoring-the-original-button-visuals

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56