์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
- ํจ์คํธ์บ ํผ์ค
- BFS
- Flutter
- ๋ฐฑ์ค
- BOJ
- Swfit
- ios
- TCA
- Kuring
- rxcocoa
- Xcode
- arkit
- UIKit
- SwiftUI
- CollectionView
- RxSwift
- visionOS
- designpattern
- Lv2
- combine
- realm
- swift
- node.js
- ํ๋ก๊ทธ๋๋จธ์ค
- tableView
- MVVM
- SnapKit
- XCTest
- reactorkit
- raywenderlich
- Today
- Total
lgvv98
[flutter] 19๊ฐ | ๋น๋ ์์ ฏ ์์ด ์ค๋ต๋ฐ ๋ง๋ค๊ธฐ ๋ฐ ํ ์คํธ ๋ฉ์์ง ๋ณธ๋ฌธ
[flutter] 19๊ฐ | ๋น๋ ์์ ฏ ์์ด ์ค๋ต๋ฐ ๋ง๋ค๊ธฐ ๋ฐ ํ ์คํธ ๋ฉ์์ง
๐ฅ ์บ๋ฟ๋งจ 2021. 8. 13. 14:39โ ์ด๋ฒ ์๊ฐ์๋ ์ค๋ต๋ฐ์ ํ ์คํธ ๋ฉ์์ง์ ๋ํด์ ์์๋ณด์.
์ค๋ต๋ฐ์ ๊ฒฝ์ฐ์๋ ํจ์น๊ฐ์์์ ๋ณด์๋ค.
๊ทธ๋์ ScaffoldMessenger๋ฅผ ์ด์ฉํด์ ์ค์ค๋ก ๊ฐ์์ ์ค๋ฅ๋ฅผ ์์ ํ ์ ์์์ด
๊ฐ์์์๋ 2๊ฐ๋ก ๋๋ ์ ๊ฐ์๋ฅผ ์งํํ๋๋ฐ ScaffoldMessenger์ Toast๋ฉ์์ง๋ก ๋๋ ์ด์ ๋ฐํํ๋ค.
ํนํ, ํ ์คํธ ๋ฉ์์ง ์ชฝ์์ error๊ฐ ์์์ด์ error ํด๊ฒฐํ๋ ๊ฒ๊น์ง ์ ์ด๋์์ผ๋ ๊ผญ ๋ณด๊ธฐ
โ ScaffoldMessenger ์ฌ์ฉํ๊ธฐ
import 'package:flutter/material.dart'; // ๋ฐ์คํฌํ, ์ฑ ๋ฑ์ ๊ณ ๋ฃจ UI๋ฅผ ์ ์ฉํ ์ ์๊ฒ ํด์ฃผ๋ ๊ตฌ๊ธ์ด ์ ๊ณตํด์ฃผ๋ ํจํค
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
// ์ค์ง์ ์ผ๋ก ๋ชจ๋ ์ฑ์ ๊ฐ์ธ๊ณ ์๋ค.
title: 'Appbar', // ์ฑ์ ์ด์นญํ๋ ์ด๋ฆ -> ์ค๋งํธ ํฐ ์ฑ์์ ์ต๊ทผ ์ฌ์ฉํ ์ฑ ๋ณด์ฌ์ค ๋์ ์ด๋ฆ
theme:
ThemeData(primarySwatch: Colors.green // ํน์ ์์ ์์ฉ๋ค์ ๊ธฐ๋ณธ ์์์ผ๋ก ์ง์ ํด์ ์ฌ์ฉํ๊ฒ
),
home: MyPage(), // home์ ์ฑ์ด ์คํ๋ ๋ ๊ฐ์ฅ๋จผ์ ๋ณด์ฌ์ฃผ๋ ํ์ด
);
}
}
class MyPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Snack Bar'),
centerTitle: true,
),
body: MySnackBar(),
);
}
}
class MySnackBar extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: ElevatedButton(
child: Text('Show me'),
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
// ์ค์บํด๋๋ฉ์ ์ ๋ง๋ค๊ธฐ
// ๊ฐ์ฅ ๊ฐ๊น์ด ์ค์บํด๋ ์ฐพ์์ ๋ฐํํด
SnackBar(
// ์ค๋ต๋ฐ
content: Text(
'Hello',
textAlign: TextAlign.center, // ์ค์์ ๋ ฌ
style: TextStyle(color: Colors.white), // ํ
์คํธ
),
backgroundColor: Colors.teal,
duration: Duration(seconds: 1),
),
);
},
));
}
}
โ ํ ์คํธ ๋ฉ์์ง
์ด๊ฑด ์๊ฐ๋ณด๋ค ๋ณต์กํ๋ค .. ๋ฌผ๋ก ํ๊ฒฝ์ค์ ๋ถ๋ถ์ด...
ํ๊ฒฝ๊ณผ ๊ด๋ จํ์ฌ์ ์ค์ํ์ ๋ช๊ฐ์ง...!
1. pubspec.yaml ์ชฝ์
โ๏ธ ๋์ด์ฐ๊ธฐ ์ ๋ง์์ผํจ. โ๏ธ
์ดํ์๋ Pub Get์ ํตํด์ ์ ๋ฐ์ดํธ ํ๋ค.
โ๏ธ์๋ฌ ๋ด์ ๋ ํด๊ฒฐ ๋ฐฉ๋ฒโ๏ธ
[verbose-2:ui_dart_state.cc(199)] unhandled exception: missingpluginexception
(no implementation found for method showtoast on channel ponnamkarthik/fluttertoast)
#0 methodchannel._invokemethod (package:flutter/src/services/platform_channel.dart:156:7) <asynchronous suspension>
#1 fluttertoast.showtoast (package:fluttertoast/fluttertoast.dart:100:17) <asynchronous suspension>
1. ์ฐ์ pubspec.yaml์ชฝ์ ์ธ๋ฑ์ค๋ฅผ ์ ๋ง์ถฐ์ ์ ์๋์ง ํ์ธํ๋ค.
2. ๊ณต์ ์ฌ์ดํธ๋ฅผ ๊ฐ์ ๋ฒ์ ์ด ๋ง๋์ง ํ์ธํ๋ค.
https://pub.dev/packages/fluttertoast
3. ์ฑ์ ์์ ํ ๊ป๋ค๊ฐ ๋ค์ ํจ๋ค.
import 'package:flutter/material.dart'; // ๋ฐ์คํฌํ, ์ฑ ๋ฑ์ ๊ณ ๋ฃจ UI๋ฅผ ์ ์ฉํ ์ ์๊ฒ ํด์ฃผ๋ ๊ตฌ๊ธ์ด ์ ๊ณตํด์ฃผ๋ ํจํค
import 'package:fluttertoast/fluttertoast.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
// ์ค์ง์ ์ผ๋ก ๋ชจ๋ ์ฑ์ ๊ฐ์ธ๊ณ ์๋ค.
title: 'Appbar', // ์ฑ์ ์ด์นญํ๋ ์ด๋ฆ -> ์ค๋งํธ ํฐ ์ฑ์์ ์ต๊ทผ ์ฌ์ฉํ ์ฑ ๋ณด์ฌ์ค ๋์ ์ด๋ฆ
theme:
ThemeData(primarySwatch: Colors.green // ํน์ ์์ ์์ฉ๋ค์ ๊ธฐ๋ณธ ์์์ผ๋ก ์ง์ ํด์ ์ฌ์ฉํ๊ฒ
),
home: MyPage(), // home์ ์ฑ์ด ์คํ๋ ๋ ๊ฐ์ฅ๋จผ์ ๋ณด์ฌ์ฃผ๋ ํ์ด
);
}
}
class MyPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Toast Bar'),
centerTitle: true,
),
body: Center(
child: TextButton(
onPressed: () {
print('TextButton is clicked');
flutterToast(); // ํจ์ ํธ์ถ
},
child: Text('Toast'),
//color: Colors.blue
),
),
);
}
}
void flutterToast() {
Fluttertoast.showToast(
msg: "This is Center Short Toast", // ๋ฉ์์ง ๋ด์ฉ
toastLength: Toast.LENGTH_SHORT, // ๋ฉ์์ง ์๊ฐ - ์๋๋ก์ด๋
gravity: ToastGravity.BOTTOM, // ๋ฉ์์ง ์์น
timeInSecForIosWeb: 1, // ๋ฉ์์ง ์๊ฐ - iOS ๋ฐ ์น
backgroundColor: Colors.red, // ๋ฐฐ๊ฒฝ
textColor: Colors.white, // ๊ธ์
fontSize: 16.0); // ๊ธ์ ํฌ๊ธฐ
}
ํจ์๋ก ๊ตฌํํ ๋ถ๋ถ ๋ง๊ณ ๋ ํฌ๊ฒ ์ด๋ ค์ด๊ฒ ์์๋ค.
๋ค๋ง, ํ ์คํธ ๋ฉ์์ง ๋ถ๋ถ์์ ์ฃผ์์ ํ๋ฒ ๊ผผ๊ผผํ๊ฒ ๋ณด๊ธฐ๋ก !
'flutter > ์ํ๋ง(๊ธฐ์ด)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[flutter] 21๊ฐ | Column, Row ์์ ฏ (0) | 2021.08.16 |
---|---|
[flutter] 20๊ฐ | ์ปจํ ์ด๋ ์์ ฏ (container widget) ๋์ง์ด ๋ณด๊ธฐ. (0) | 2021.08.13 |
[flutter] 27๊ฐ(ํจ์น๊ฐ์ข) | ํ๋ฌํฐ 2.0 ๋ฒํผ (0) | 2021.08.13 |
[flutter] 18(26)๊ฐ | ํ๋ฌํฐ 2.0 SnackBar ์ ScaffoldMessenger (0) | 2021.08.12 |
[flutter] 17๊ฐ | BuildContext ์ดํดํ๊ธฐ (0) | 2021.08.11 |