반응형
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)
),
),
)
],
),
),
);
}
}
결과화면
아이콘
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
반응형
'프로그램 개발해서 돈벌기 > flutter' 카테고리의 다른 글
10. 클래스 (class) - 완전 초보 Dart 언어 기초 문법 : flutter (0) | 2022.12.31 |
---|---|
flutter에서 Named route 화면 전환을 이용하여 첫(시작) 로딩 화면( Splash Screen ) 만들기 (0) | 2022.12.30 |
flutter upgrade와 zsh: command not found: flutter (0) | 2022.12.30 |
9. typedef - 완전 초보 Dart 언어 기초 문법 : flutter (0) | 2022.12.23 |
8. 함수(function) 만드는 과정 - 완전 초보 Dart 언어 기초 문법 : flutter (0) | 2022.12.23 |
댓글