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
- swift 문법
- switch
- snackbar
- changenotifierprovider
- Swift
- permission
- consumer
- changenotifier
- controller
- user
- borderRadius
- Stream
- Navigator
- runTransaction
- Camera
- datetime
- platformexception
- signout
- setstate
- multiprovider
- globalkey
- transform
- Snapshot
- enum
- ListView.builder
- divider
- reference
- Firebase
- 문법
- provider
Archives
- Today
- Total
코딩하는 제리
[Flutter/Project](Instagram Clone) ListTile을 이용한 메뉴 만들기 본문
Flutter/Project_InstaClone(완)
[Flutter/Project](Instagram Clone) ListTile을 이용한 메뉴 만들기
JerryCho 2021. 1. 23. 13:11api.flutter.dev/flutter/material/ListTile-class.html
ListTile class - material library - Dart API
A single fixed-height row that typically contains some text as well as a leading or trailing icon. A list tile contains one to three lines of text optionally flanked by icons or other widgets, such as check boxes. The icons (or other widgets) for the tile
api.flutter.dev
- 각 파일에서 같은 애니메이션 속도를 정하기 위해 duration을 const 변수로 밖으로 빼냄.
- 메뉴 사이즈 변경.
소스코드
// widgets/profile_side_menu.dart
import 'package:flutter/material.dart';
class ProfileSideMenu extends StatelessWidget {
final double menuWidth;
const ProfileSideMenu(this.menuWidth, {Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return SafeArea(
child: SizedBox(
width: menuWidth,
child: Column(
children: [
ListTile(
title: Text(
'Setting',
style: TextStyle(fontWeight: FontWeight.bold),
),
),
ListTile(
leading: Icon(
Icons.exit_to_app,
color: Colors.black87,
),
title: Text('Sign Out'),
)
],
),
),
);
}
}
// profile_screen.dart
import 'package:flutter/material.dart';
import 'package:flutter_project_IJ/constants/screen_size.dart';
import 'package:flutter_project_IJ/widgets/profile_body.dart';
import 'package:flutter_project_IJ/widgets/profile_side_menu.dart';
enum MenuStatus { opened, closed }
// 클래스 바깥에서 선언한 변수는 다른 파일에서 접근이 가능한 static 변수.
const duration = Duration(milliseconds: 600);
class ProfileScreen extends StatefulWidget {
@override
_ProfileScreenState createState() => _ProfileScreenState();
}
class _ProfileScreenState extends State<ProfileScreen> {
final menuWidth = size.width / 3 * 2; //메뉴 사이즈
// 메뉴 상태 기본 값(closed)
MenuStatus _menuStatus = MenuStatus.closed;
// 메뉴를 열기 전 기본 값.
double bodyXPos = 0;
double menuXPos = size.width; //화면 사이즈만큼 우측 밖으로 나가있음
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[100],
body: Stack(
children: [
AnimatedContainer(
duration: duration,
transform: Matrix4.translationValues(bodyXPos, 0, 0),
child: ProfileBody(onMenuChanged: () {
setState(() {
// 메뉴 상태 토글
// profile_body.dart 파일의 _appbar 메서드에서 버튼이 선태될 때 실행.
// 메뉴 상태가 closed이면 opened, opend이면 closed로 변경.
_menuStatus = (_menuStatus == MenuStatus.closed)
? MenuStatus.opened
: MenuStatus.closed;
switch (_menuStatus) {
case MenuStatus.opened:
bodyXPos = -menuWidth;
menuXPos = size.width - menuWidth;
break;
case MenuStatus.closed:
bodyXPos = 0;
menuXPos = size.width;
break;
}
});
}),
),
AnimatedContainer(
duration: duration,
transform: Matrix4.translationValues(menuXPos, 0, 0),
child: Positioned(
top: 0,
bottom: 0,
width: menuWidth,
child: ProfileSideMenu(menuWidth),
),
),
],
),
);
}
}
'Flutter > Project_InstaClone(완)' 카테고리의 다른 글
[Flutter/Project](Instagram Clone) AnimatedIcon (0) | 2021.01.23 |
---|---|
[Flutter/Project](Instagram Clone) Positioned 위젯 (0) | 2021.01.23 |
[Flutter/Project](Instagram Clone) 프로필 메뉴 만들기 (0) | 2021.01.23 |
[Flutter/Project](Instagram Clone) Table, TableRow (0) | 2021.01.22 |
[Flutter/Project](Instagram Clone) switch~case 코드정리 (0) | 2021.01.22 |
Comments