250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 희망적금전환
- 도약전환
- 조립 후 재부팅
- 청년도약계좌환승
- Flutter #Stream #dart
- Flutter #Stream
- flutter #dart #stream
- 도약연계
- 플러터 #안드로이드 #플레이콘솔 #앱내리기
- 희망적금연계
- 도약계좌전환
- 안드로이드 #코틀린 #코루틴 #콜백 #채널
Archives
- Today
- Total
Flutter 개발 상자
이주의 위젯 - Wrap 본문
728x90
위와 같은 해시태그를 만들기위해서 wrap 이라는 위젯을 사용한다.
속성
spacing : 아이템간의 간격, 음수값도 집어넣어짐
runSpacing : 한줄의 간격
direction : 가로, 세로 방향 결정, 기본값 가로 ex) Axis.vertical
clipBehavior : 튀어나온부분을 잘라내는 속성?... 정확히 어떻게 쓰이는지는 모르겠다
textDirection : 아이템이 생성되는 방향을 바꿔준다. 기본값 ltr ex) TextDirection.ltr
verticalDirection : 아이템이 생성되는 줄 방향을 바꿔준다. textDirection와 수직으로 반대되는 개념
alignment : 아이템 정렬 방식 ex) Wrapalignment.center
runAlignment : 아이템 줄 정렬 방식
crossAxisAlignment : 아이템의 교차축 길이가 제각각일때 교차축에 대한 정렬방식
https://terry1213.github.io/flutter/flutter-widget-of-the-week-wrap/
[Flutter/Widget of the Week] Wrap
Widget of the Week 유튜브 영상
terry1213.github.io
여기보면 이해가 쉬운듯
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 MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
List<User> userList = [
User(initials: "AB", name: "Aaron Burr"),
User(initials: "AH", name: "Alexander Hamilton"),
User(initials: "EH", name: "Eliza Hamilton"),
User(initials: "JM", name: "James Madison"),
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("wrap"),
),
body: SizedBox(
width: double.infinity,
child: Wrap(
clipBehavior: Clip.antiAlias,
direction: Axis.horizontal,
spacing: 8.0,
// gap between adjacent chips
runSpacing: 4.0,
// gap between lines
alignment: WrapAlignment.center,
children: createWrapList(),
),
),
floatingActionButton: FloatingActionButton(
child: const Icon(
Icons.add,
),
onPressed: () {
showAddDialog();
},
),
);
}
void showAddDialog() {
TextEditingController controller = TextEditingController();
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text("아이템 추가"),
content: TextField(
autofocus: true,
controller: controller,
),
actions: [
TextButton(
onPressed: () {
String initials = "";
controller.text.split(" ").forEach((element) {
initials += element.substring(0, 1);
});
setState(() {
userList.add(
User(initials: initials, name: controller.text,)
);
});
Navigator.of(context).pop();
},
child: const Text(
"확인"
),
),
],
);
},
);
}
List<Widget> createWrapList() {
List<Widget> widgetList = [];
for (var element in userList) {
Widget widget = Chip(
avatar: CircleAvatar(backgroundColor: Colors.blue.shade900, child: Text(element.initials)),
label: Text(element.name),
onDeleted: () {
setState(() {
userList.removeWhere((item) => item.name == element.name);
});
},
);
widgetList.add(widget);
}
return widgetList;
}
}
class User {
String initials;
String name;
User({
required this.initials,
required this.name,
});
}
x를 누르면 사라지고, 플로팅 버튼으로 아이디를 추가하는 UI를 만들어 보았다.
728x90
'Flutter' 카테고리의 다른 글
[Flutter Stream④] StreamController 활용 (2) | 2023.11.12 |
---|---|
[Flutter Stream③] StreamSubscription 활용 (0) | 2023.11.12 |
[Flutter Stream②] Stream 기본 사용법 (1) | 2023.11.12 |
[Flutter Stream①] Rective Programing과 Stream (2) | 2023.11.11 |
[Flutter] 플러터 중수로 거듭나기 위한 학습 목표는 무엇이 있는가? (0) | 2023.11.11 |