
1.theme
[ 일반 컬러랑 메티리얼 컬러의 차이점 ]
메터리얼 컬러 -> 좀 더 연한 빨강, 좀 더 진한 빨강 막 이런... 더 여러가지 색 사용 가능 색상을 하나만 표현하지 않는다!


메테리얼 컬러만 지원. 테마로 적용하면 모든게 다 적용되니까... 테마에 적용한 것임 테마 설정하면 위젯을 만들때 스코필드의 뼈대 테마들을 한방 적용 가능! -> 편해서 씀! 일단 우린 앱의 메인 색상과(primarySwatch)와 appBarTheme 적용 가능하다는 것만 알자 나중에 하나하나씩 적용해보자
- primary switch : app의 메인 컬러

- 색깔 진하게 하기

- 내가 만든 메터리얼 컬러


- 테마로 적용 → 모든 페이지에 적용됨
2.
- endDrawer :

- drawer


leading이 나와야 드로우(저 파란거)가 나옴
3.

위젯이 자기 속성으로 사이즈를 안들고 있으면 SizedBox를 사용해서 크기를 주면 된다. 그러나 이렇게 사이즈를 딱 박아버리면 재사용 불가능! 재사용할 수 있게 적어야함

재사용 위해 빼주기

디폴트값 100을 넣어줌. 디폴트값을 설정해줬기에 required 필요없음!

이것이 재사용 가능한 컴퍼넌트 컴퍼넌트가 엄청나게 많겠죠? -> 페이지 별로 컴퍼넌트를 관리함. 공통 컴퍼넌트도 있겠고...



- 일급 객체라 가능함

- 버튼 크기를 사이즈 박스로 감싸서 조절함

import 'package:flutter/material.dart'; import 'package:profile_app/theme.dart'; import 'components/profile_buttons.dart'; import 'components/profile_count_info.dart'; import 'components/profile_drawer.dart'; import 'components/profile_header.dart'; import 'components/profile_tab.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return MaterialApp( theme: theme(), home: ProfilePage(), ); } } class ProfilePage extends StatelessWidget { const ProfilePage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return Scaffold( endDrawer: ProfileDrawer(), appBar: _buildProfileAppBar(), body: Column( children: [ SizedBox(height: 20), ProfileHeader(), SizedBox(height: 20), ProfileCountInfo(), SizedBox(height: 20), ProfileButtons(), Expanded(child: ProfileTab()), ], ), ); } AppBar _buildProfileAppBar() { return AppBar(); } }
import 'package:flutter/material.dart'; import 'package:profile_app/theme.dart'; import 'components/profile_buttons.dart'; import 'components/profile_count_info.dart'; import 'components/profile_drawer.dart'; import 'components/profile_header.dart'; import 'components/profile_tab.dart'; import 'components/profile_tap2.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( theme: theme(), home: ProfilePage(), ); } } class ProfilePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( endDrawer: ProfileDrawer(), appBar: _buildProfileAppBar(), body: Column( children: [ SizedBox(height: 20), ProfileHeader(), SizedBox(height: 20), ProfileCountInfo(), SizedBox(height: 20), ProfileButtons(), // 남아있는 세로 공간을 모두 차지하기 위해 Expanded를 준다 Expanded(child: profile_tab2(), ), ], ), ); } AppBar _buildProfileAppBar() { return AppBar( leading: Icon(Icons.arrow_back_ios), title: Text("Profile"), centerTitle: true, ); } }
import 'package:flutter/material.dart'; class profile_tab2 extends StatelessWidget { const profile_tab2({ super.key, }); @override Widget build(BuildContext context) { return DefaultTabController( length: 2, initialIndex: 0, child: Column( children: [ TabBar( tabs: [ Tab(icon: Icon(Icons.car_crash)), Tab(icon: Icon(Icons.car_rental)), ], ), Expanded( child: TabBarView( children: [ GridView.builder( gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 3, ), itemBuilder: (context, index) { return Image.network( "https://picsum.photos/id/${index + 1}/200/200"); }, ), Container( color: Colors.red, ), ], ), ), ], ), ); } }

30개를 new해서 띄우면 비효율적
화면에는 5개밖에 못 띄우니까 앱은 프로세스 1개로 관리
윈도우는 켜진게 모두 다 프로세스지만 앱은 아님
폰은 컴퓨터만큼 퍼포먼스가 좋지 않음
이 앱이 여러가지의 프로세스를 가지고 좋은 퍼포먼스를 내야하는데
앱마다 프로세스를 다 만들어내면 너무 빡셈
→ 안드로이드나 ios들은 프로세스를, 하나로 관리
하나의 프로세스로 관리 함.
카톡이랑 브라우저가 여러개로 동시에 안 켜짐
카카오톡이라는 앱이 하나 켜지잖아? 카톡이 화면에 떳겠죠?
카카오톡 프로세스 번호 1 -> 그럼 프로세스가 1을 관리한다.
그럼 휴대폰 화면을 밑으로 내려버리잖아? (홈화면이나...)
컴퓨터는 밑으로 내린다고 해서 메모리가 잡고있는게 사라지지 않는다. 꺼진게 아니다.
그러나 폰은 애가 관리하는 이 프로세스, 데이터들을 현재 그 상태를 물리적인 저장 장소에
저장해놓고, 메모리에선 지워짐.
즉, 애가 메모리로 관리하고 있진 않음!!
이 상태에서 인스타를 켰다고 하자.
그럼 인스타 프로세스 번호 2
그럼 프로세스는 1이 아니라 2를 관리. (번호로 관리한다) 인스타가 메모리에 뜸!
쓰다가 인스타를 내리잖아? 또 인스타를 물리적으로 그 상태를 (포크 떠버림) 저장해버림.
다시 열 때, 그 상태를 복원 시키면서 메모리가 활성화 됨!
앱은 원 프로세스!
컴퓨터는 내려도 다 떠있음~~
그렇게 메모리가 중요한 애들이 30개를 모두 다 띄우진 않겠죠?
어떻게 하는걸까?
컬렉션을 하나 만들어서 arrayList를 하나 만든다.
이 화면이 build 될 때, 화면의 높이를 계산한다. 500이네?
내가 지금 그려야할 객체의 높이도 계산한다. 100이네?
화면에 보일 수 있는건 5개밖에 없네? 연산이 가능
객체를 5개만 만들잖아? 스크롤 하는 순간 6번째 애가 엄청 늦게 올라올 것
5개가 아니라 30% 정도를 메모리에 더 띄움
즉, 객체를 5개 만들더라도 띄우는건 7개가 띄워지는 것
viewHolder 같은 곳에 순수한 디자인
데이터가 바인딩 되어있지 않은 디자인을(껍데기만) 객체로 만들어서 띄워놓음
통신을 해서 그리잔항?
빠져나가면서 올라올 것
30%를 더 그려야 순수해짐
3개를 더 그려야 함
화면에서 보이지 않는 애들도 2~30%는 더 만들어야 스크롤리 스무스해짐
어떻게 해야 메모리를 효율적으로 쓸 수 있을까?
올라간 디자인 안의 데이터만 빼고 8,9 번 데이터를 바인딩해서 집어넣는것
그럼 7개만 가지고 놀 수 있음
30개는 만들지 않아도 됨
이게 뷰 홀더 패턴

리쿼스트 관리 기술 = 풀링 기술
이게 가장 효과적
만들어놓고 재사용하기
빌드 : 데이터를 폴딩해서 바꿔 끼워 사용하는 것
Share article