import 'package:flutter/material.dart';
/// Flutter code sample for [TabBar].
void main() => runApp(const TabBarApp());
class TabBarApp extends StatelessWidget {
const TabBarApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
double screenWidth = MediaQuery.of(context).size.width;
return Scaffold(
endDrawer: Container(
width: screenWidth / 2,
color: Colors.lightBlueAccent,
),
appBar: AppBar(
leading: IconButton(
icon: Icon(Icons.arrow_back_ios),
onPressed: () {
print("클릭됨");
},
),
),
body: NestedScrollView(
headerSliverBuilder: (context, innerBoxIsScrolled) {
return [
SliverList(
delegate: SliverChildListDelegate([
Padding(
padding: const EdgeInsets.all(16.0),
child: ProfileHeader(),
),
Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_info("50", "Posts"),
_line(),
_info("10", "Likes"),
_line(),
_info("3", "Share"),
],
),
),
]),
),
];
},
body: ProfileTab(),
),
);
}
Container _line() {
return Container(
width: 1,
height: 60,
color: Colors.black,
);
}
Column _info(String count, String title) {
return Column(
children: [
Text("$count", style: TextStyle(fontSize: 15)),
SizedBox(height: 2),
Text("$title", style: TextStyle(fontSize: 15)),
],
);
}
}
class ProfileTab extends StatelessWidget {
const ProfileTab({
super.key,
});
@override
Widget build(BuildContext context) {
return Expanded(
child: DefaultTabController(
length: 2,
child: Column(
children: [
TabBar(
tabs: [
Tab(icon: Icon(Icons.car_crash)),
Tab(icon: Icon(Icons.car_repair)),
],
),
Expanded(
child: TabBarView(
children: [
GridView.builder(
itemCount: 50,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
),
itemBuilder: (context, index) {
print("인덱스 번호 : $index");
return Image.network(
"<https://picsum.photos/id/$>{151 + index}/200/200");
},
),
Container(color: Colors.blue),
],
),
),
],
),
),
);
}
}
class ProfileHeader extends StatelessWidget {
const ProfileHeader({
super.key,
});
@override
Widget build(BuildContext context) {
return Row(
children: [
SizedBox(
width: 100,
height: 100,
child: CircleAvatar(
backgroundImage:
NetworkImage("<https://picsum.photos/id/200/200/200>"),
),
),
SizedBox(width: 10),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [Text("삼성중공업"), Text("IT 프로그래머"), Text("프로그래머/직원/연구원")],
)
],
);
}
}