티스토리 뷰
import 'package:flutter/material.dart';
import 'a1.dart';
import 'a2.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.blue, // 앱에서 기본으로 사용할 색상 블루
),
home: MyHomePage(title: '코드 모음'), // 머터리얼앱 시작하면 홈은 필수로 필요함
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() {
return _MyHomePageState(); // createState()는 상태를 생성하는 함수 StatefulWidget를 상속받는 클래스는 반드시 호출해야 한다. _를 넣으면 내부에서만 사용할 수 있다
}
}
class _MyHomePageState extends State<MyHomePage> {
List<MainText> list = List(); // 리스트 선언
String x;
@override
void initState() {
// 위젯을 초기화하는 함수 주로 데이터 목록을 만들거나 처음 필요한 데이터를 주고받을 때 호출한다.
super.initState();
x = '1. 버튼 글자, 색상';
list.add(MainText(text: x, fun: a1(title: x,))); // 리스트 추가
x = '2. 화면 배치';
list.add(MainText(text: x, fun: a2(title: x,))); // 리스트 추가
}
@override
Widget build(BuildContext context) {
// 위젯을 화면에 렌더링한다.
return Scaffold(
// 머터리얼 디자인 적용
appBar: AppBar(
// 앱바 설정
title: Text(widget.title), // 앱바 텍스트
),
body: Container(
// 공간을 담당하는 함수
child: Center(
// 가운데로
child: ListView.builder(
itemBuilder: (context, position) {
return GestureDetector(
// 터치 이벤트를 처리하려면 사용
child: Card(
// 카트뷰
child: Row(
// 가로로 나타나게
children: <Widget>[
Text(
list[position].text,
style: TextStyle(fontSize: 30), // 폰트 사이즈
),
],
),
),
onTap: () {
// 터치 했을 때
Navigator.push(
// 네비게이터 눌렀을 때
context,
MaterialPageRoute(
builder: (context) => list[position].fun), // 페이지 이동
// MaterialPageRoute(builder: (context) => a1(main_text: list[position])), // 되는것
// MaterialPageRoute(builder: (context) => list[position].fun(main_text: list[position])),
);
},
);
},
itemCount: list.length), // 아이템 개수만큼만 스크롤 할 수 있게 제한
),
),
);
}
}
class MainText {
String text;
var fun;
MainText({@required this.text, @required this.fun});
}
import 'package:flutter/material.dart';
class a1 extends StatelessWidget {
final String title;
a1({Key key, this.title}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: _ful(title: title),
);
}
}
class _ful extends StatefulWidget {
final String title;
_ful({Key key, this.title}) : super(key: key);
@override
_sta createState() => _sta();
}
class _sta extends State<_ful> {
renderTextButton() {
return TextButton(
onPressed: () {},
child: Text('TextButton'),
);
}
renderOutlinedButton() {
return OutlinedButton(
onPressed: () {},
child: Text('OutlinedButton'),
);
}
renderElevatedButton() {
return ElevatedButton(
onPressed: () {},
child: Text('ElevatedButton'),
);
}
renderTextButton0() {
return TextButton(
onPressed: () {},
style: TextButton.styleFrom(
primary: Colors.red,
// 색상
backgroundColor: Colors.amber,
// 백그라운드 칼라 배경 색
shadowColor: Colors.orange,
// 그림자 색
elevation: 5,
// 그림자
textStyle: TextStyle(
// style랑 중복이 안되게
fontWeight: FontWeight.bold,
),
padding: EdgeInsets.all(15.0),
// 패딩 전부 16
minimumSize: Size(
// 최소 사이즈
200.0, // 가로
75.0, // 세로
),
side: BorderSide(
// 보더
color: Colors.blueAccent, // 보더 색
width: 2.0, // 보더 크기
),
shape: BeveledRectangleBorder(),
// 각진 보더
alignment: Alignment.topLeft // 글자 위치 변경
),
child: Text('TextButton'),
);
}
renderElevatedButton1() {
return ElevatedButton(
onPressed: null,
style: ElevatedButton.styleFrom(
onSurface: Colors.amber, // 온 프레시드가 없을때 색상
shape: StadiumBorder(), // 가장자리가 동그란 보더
),
child: Text('ElevatedButton'),
);
}
renderElevatedButton2() {
return ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
shape: CircleBorder(), // 완전 동그란 보더
),
child: Text('ElevatedButton'),
);
}
renderElevatedButton3() {
return ElevatedButton(
onPressed: () {},
style: ButtonStyle(
foregroundColor: MaterialStateProperty.all(
Colors.red, // 글자색
),
backgroundColor: MaterialStateProperty.resolveWith(
(states) {
if (states.contains(MaterialState.pressed)) {
return Colors.blue; // 눌렸을 때 배경색
} else {
return Colors.orange; // 안 눌렸을 때 배경색
}
},
),
textStyle: MaterialStateProperty.resolveWith((states) {
if (states.contains(MaterialState.pressed)) {
return TextStyle(
fontSize: 16.0, // 눌렸을 때 사이즈 16
);
} else {
return TextStyle(
fontSize: 10.0, // 안 눌렸을 때 사이즈 10
);
}
})),
child: Text('ElevatedButton'),
);
}
Color _back_color = Colors.blue;
Color _text_color = Colors.white;
String _test = '안녕'; // 버튼에 들어갈 텍스트 입력
renderElevatedButton4() {
return ElevatedButton(
style: TextButton.styleFrom(
primary: _text_color, // 버튼 색
backgroundColor: _back_color, // 배경 색
),
onPressed: () {
if (_back_color == Colors.blue) {
setState(() {
_test = '잘가';
_back_color = Colors.amber;
_text_color = Colors.black;
});
} else {
setState(() {
_test = '안녕';
_back_color = Colors.blue;
_text_color = Colors.white;
});
}
},
child: Text(_test),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
// 머터리얼 디자인 적용
appBar: AppBar(
// 앱 바
title: Text(widget.title),
),
body: Center(
// 가운데로
child: Column(children: [
renderTextButton(),
renderOutlinedButton(),
renderElevatedButton(),
renderTextButton0(),
renderElevatedButton1(),
renderElevatedButton2(),
renderElevatedButton3(),
renderElevatedButton4(),
]),
),
);
}
}
import 'package:flutter/material.dart';
class a2 extends StatelessWidget {
final String title;
a2({Key key, this.title}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: _ful(title: title),
);
}
}
class _ful extends StatefulWidget {
final String title;
_ful({Key key, this.title}) : super(key: key);
@override
_sta createState() => _sta();
}
class _sta extends State<_ful> {
renderTextButton0() {
return TextButton(
onPressed: () {},
style: TextButton.styleFrom(
minimumSize: Size(80.0, 50.0),
backgroundColor: Colors.red,
textStyle: TextStyle(
fontSize: 25.0,
),
),
child: Text('0'),
);
}
renderTextButton1() {
return TextButton(
onPressed: () {},
child: Text('1'),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
// 머터리얼 디자인 적용
appBar: AppBar(
// 앱 바
title: Text(widget.title),
),
body: Center(
// 가운데 정렬
child: Column(// 세로로 위젯 배치
children: [
renderTextButton0(),
Row(
// 가로로 위젯을 배치.
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
// 위젯끼리 같은 공간만큼 띄움
children: [
renderTextButton1(),
renderTextButton1(),
renderTextButton1(),
renderTextButton1(),
],
),
renderTextButton0(),
]),
),
);
}
}
'Flutter' 카테고리의 다른 글
Flutter(플러터) 조건문 반복문 함수 (0) | 2020.09.10 |
---|---|
Flutter(플러터) Dart의 자료형과 변수를 선언하고 사용하는 방법 (0) | 2020.09.10 |
Flutter(플러터) 윈도우에서 환경 구축하기 (0) | 2020.09.10 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 카카오봇
- inputbox
- 구구단어플
- 명언
- 안드로이드앱개발
- 노래
- 매크로
- Flutter
- JS
- 카카오톡
- loop
- 플러터
- 챗봇
- 안드로이드스튜디오
- 구구단공부
- 채팅
- 앱개발
- 자바스크립트
- 안드로이드
- 안드로이드앱
- 안드로이드클라이언트
- sendinput
- 오토핫키
- 구구단앱
- 안드로이드네이티브
- 코틀린
- 로또
- 자동답장
- 구구단
- MouseMove
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
글 보관함