본문 바로가기
프로그램 개발해서 돈벌기/flutter

flutter material button - The method 'FlatButton' isn't defined

by ubmuhan 2022. 12. 30.
반응형

flutter로 작성한 프로젝트에서 flutter 3.0.0에서 3.3.0으로 upgrade를 했습니다. 정상적으로 업그레이드를 마친 후 프로젝트를 여니 FlatButton에서 에러가 발생하고 있었습니다. "The method 'FlatButton' isn't defined ....."

구글링을 해 보니 "flutter flatbutton is deprecated" 였습니다.

 

기존 Material Buttons (Deprecated) 신규 Material Buttons
FlatButton TextButton
RaisedButton ElevatedButton
OutlineButton OutlinedButton

 

신규 Material Buttons 사용법

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  final String title;

  const MyHomePage({
    Key? key,
    required this.title,
  }) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final mnSpace = 10.0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            MaterialButton(
                onPressed: () {
                  
                },
                child: Text("MaterialButton")),
            SizedBox(
              height: mnSpace,
            ),
            TextButton(
                onPressed: () {
                  
                },
                child: Text("TextButton")),
            SizedBox(
              height: mnSpace,
            ),
            ElevatedButton(
                onPressed: () {
                  
                },
                child: Text("ElevatedButton")),
            SizedBox(
              height: mnSpace,
            ),
            OutlinedButton(
                onPressed: () {
                  
                },
                child: Text("OutlinedButton")),
            SizedBox(
              height: mnSpace,
            ),
            ElevatedButton(
                onPressed: () {
                  
                },
                style: ElevatedButton.styleFrom(
                  primary: Colors.green,
                  padding: EdgeInsets.symmetric(vertical: 15, horizontal: 50)
                ),
                child: Text("ElevatedButton Style")),
            SizedBox(
              height: mnSpace,
            ),
            ClipRRect(borderRadius: BorderRadius.circular(30),
              child: ElevatedButton(
                onPressed: () {  },
                child: Icon(
                  Icons.airplay,
                  color: Colors.white
                ),
                style: ElevatedButton.styleFrom(
                  primary: Colors.green,
                  padding: EdgeInsets.symmetric(vertical: 15, horizontal: 50)
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}
미국∙영국
[ˈelɪveɪt]
1. 승진[승격]시키다 (=raise, promote)
2. (들어)올리다
3. (정도를) 높이다[증가시키다]
 
 
 

 

결과화면

그림 1. 결과 화면

 

 

아이콘

https://api.flutter.dev/flutter/material/Icons-class.html

 

Icons class - material library - Dart API

Identifiers for the supported Material Icons. Use with the Icon class to show specific icons. Icons are identified by their name as listed below, e.g. Icons.airplanemode_on. Search and find the perfect icon on the Google Fonts website. To use this class, m

api.flutter.dev

 

 
반응형

댓글