import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const MaterialApp(
//빨간띠 삭제
debugShowCheckedModeBanner: false,
title: 'TestApp',
home: MyPage(),
);
}
}
class MyPage extends StatelessWidget {
const MyPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Snack Bar'),
centerTitle: true,
),
body: Builder(builder: (BuildContext ctx){
return Center(
child: FlatButton(
color: Colors.red,
child: const Text(
'Show me',
style: TextStyle(color: Colors.white),
),
onPressed: () {
Scaffold.of(ctx).showSnackBar(const SnackBar(
content: Text('data'),
));
},
),
);
})
);
}
}
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const MaterialApp(
//빨간띠 삭제
debugShowCheckedModeBanner: false,
title: 'TestApp',
home: MyPage(),
);
}
}
class MyPage extends StatelessWidget {
const MyPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Snack Bar'),
centerTitle: true,
),
body: MySnackBar(),
);
}
}
class MySnackBar extends StatelessWidget {
const MySnackBar({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Center(
child: RaisedButton(
child: Text('Show me'),
onPressed: (){
Scaffold.of(context).showSnackBar(SnackBar(content: Text('data')));
},
),
);
}
}