[Flutter] Instagram๐Ÿคณ ํ”„๋กœํ•„ ๋ ˆ์ด์•„์›ƒ ๊ทธ๋ฆฌ๊ธฐ

Soyun Joยท2022๋…„ 7์›” 10์ผ
0

Flutter๐Ÿ“ฑ์•ฑ ๊ฐœ๋ฐœ

๋ชฉ๋ก ๋ณด๊ธฐ
5/5
post-thumbnail
post-custom-banner

๐ŸŒŽ Instagram ํ”„๋กœํ•„ ๋ ˆ์ด์•„์›ƒ ๊ทธ๋ฆฌ๊ธฐ

์šฐ์„  ์œ„์™€ ๊ฐ™์€ ํ™”๋ฉด์„ ๊ทธ๋ฆฌ๊ธฐ ์œ„ํ•ด์„œ Scaffold ๋‚ด์—์„œ ๋‘๊ฐ€์ง€๋กœ ๋‚˜๋ˆˆ๋‹ค.
1. AppBar
2. Body

๊ทธ๋ฆฌ๊ณ  Body - Column ๋‚ด์—์„œ ํฌ๊ฒŒ ๋„ค๊ฐ€์ง€ ์˜์—ญ์œผ๋กœ ๋‚˜๋ˆ„์—ˆ๋‹ค.
1. ํ”„๋กœํ•„ ์˜์—ญ
2. Text ์˜์—ญ
3. ๋ฒ„ํŠผ ์˜์—ญ
4. Tab ์˜์—ญ


๐Ÿ“ App Bar

appBar: AppBar(
        backgroundColor: Colors.white,
        title: Text(widget.title, style: TextStyle(color: Colors.black)),
        leading: IconButton(icon: Icon(Icons.arrow_back_ios, color: Colors.blue), onPressed: () {}),
        actions: [
          IconButton(onPressed: () {}, icon: Icon(Icons.menu, color: Colors.blue))
        ],
      ),



๐Ÿ“ ํ”„๋กœํ•„ ์˜์—ญ

Expanded(child: Row(
            children: [
              Expanded(child: CircleAvatar(
                radius: 70,
                backgroundImage: AssetImage("images/img1.jpeg"),
              ),flex: 1,),
              Expanded(
                child: SizedBox(
                  height: 100,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: [
                      Text(_name, style : TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
                      Text(_job, style : TextStyle(fontSize: 18)),
                      Text(_detail, style : TextStyle(fontSize: 15)),
                    ],
                  ),
                ),
                flex: 1,
              )
            ],
          ),
            flex: 2,
          ),



๐Ÿ“ Post, Likes, Shares ์˜์—ญ

Expanded(
            child: Row(
              children: [
                Expanded(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text("50"),
                      Text("Posts")
                    ],
                  ),
                ),
                Container(height: 50, width: 2, color: Colors.grey),
                Expanded(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text("10"),
                      Text("Likes")
                    ],
                  ),
                ),
                Container(height: 50, width: 2, color: Colors.grey),
                Expanded(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text("3"),
                      Text("Shares")
                    ],
                  ),
                )
              ],
            ),
            flex: 1,
          ),



๐Ÿ“ ๋ฒ„ํŠผ ์˜์—ญ

Expanded(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                InkWell(
                  child: Container(
                    height: 50,
                    width: 180,
                    child: Text("Follow",
                    style: Theme.of(context).textTheme.caption?.copyWith(
                      color: Colors.white,
                      fontWeight: FontWeight.w500
                    ),),
                    padding: EdgeInsets.all(10),
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                      color: Colors.blueAccent,
                      borderRadius: BorderRadius.circular(10),
                    ),
                  ),
                  onTap: () {},
                ),
                InkWell(
                  child: Container(
                    height: 50,
                    width: 180,
                    child: Text("Message",
                      style: Theme.of(context).textTheme.caption?.copyWith(
                          color: Colors.black,
                          fontWeight: FontWeight.w500
                      ),),
                    padding: EdgeInsets.all(10),
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                      color: Colors.white,
                      border: Border.all(),
                      borderRadius: BorderRadius.circular(10),
                    ),
                  ),
                  onTap: () {},
                ),
              ],
            ),
            flex: 1,
          ),



๐Ÿ“ Tab ์˜์—ญ

์˜ค๋ž˜๊ฑธ๋ ธ๋˜ ๋ถ€๋ถ„.. Tab์˜์—ญ!
Tabbar์™€ TabBarView๋ฅผ ๊ฐ๊ฐ Expanded๋กœ ๋ฌถ์–ด DefaultTabController๋กœ ๊ฐ์‹ธ์ฃผ์—ˆ๋‹ค.

Expanded(child: DefaultTabController(
                length: 2,
                initialIndex: 0,
                child: Column(
                  children: <Widget> [
                    Expanded(child: TabBar())
                    Expanded(child: TabBarView())
                    ...

์š”๋Ÿฐ์‹์œผ๋กœ!

๐Ÿ‘‰๐Ÿผ TabBar

Expanded(
                      child: TabBar(
                        tabs: <Widget> [
                          new Tab(
                            icon: const Icon(Icons.directions_car, color: Colors.black),
                          ),
                          new Tab(
                            icon: const Icon(Icons.train, color: Colors.black),
                          )
                        ]
                      ),flex: 1,
                    ),

๐Ÿ‘‰๐Ÿผ TabBarView

Expanded(
                      child: TabBarView(
                        children: <Widget>[
                          new Container(
                            child: GridView.count(
                              padding: const EdgeInsets.all(20),
                              crossAxisSpacing: 10,
                              mainAxisSpacing: 10,
                              crossAxisCount: 3,
                              children: <Widget> [
                                Expanded(
                                  child: Ink.image(image: AssetImage("images/img1.jpeg")),
                                ),
                                Expanded(
                                  child: Ink.image(image: AssetImage("images/img1.jpeg")),
                                ),
                                Expanded(
                                  child: Ink.image(image: AssetImage("images/img1.jpeg")),
                                ),
                                Expanded(
                                  child: Ink.image(image: AssetImage("images/img1.jpeg")),
                                ),
                                Expanded(
                                  child: Ink.image(image: AssetImage("images/img1.jpeg")),
                                ),
                                Expanded(
                                  child: Ink.image(image: AssetImage("images/img1.jpeg")),
                                ),
                                Expanded(
                                  child: Ink.image(image: AssetImage("images/img1.jpeg")),
                                ),
                                Expanded(
                                  child: Ink.image(image: AssetImage("images/img1.jpeg")),
                                ),
                                Expanded(
                                  child: Ink.image(image: AssetImage("images/img1.jpeg")),
                                ),
                              ],
                            ),
                          ),
                          new Container(
                            child: GridView.count(
                              padding: const EdgeInsets.all(20),
                              crossAxisSpacing: 10,
                              mainAxisSpacing: 10,
                              crossAxisCount: 3,
                              children: <Widget> [
                                Expanded(
                                  child: Ink.image(image: AssetImage("images/img1.jpeg")),
                                ),
                                Expanded(
                                  child: Ink.image(image: AssetImage("images/img1.jpeg")),
                                ),
                              ],
                            ),
                          )
                        ]
                      ),flex: 5,
                    )



๊ทธ๋ฆฌ๊ณ  ์ „์ฒด ์ฝ”๋“œ ๐Ÿฅ ๐ŸŽท ๐ŸŽป ๐ŸŽธ

import 'package:flutter/material.dart';
import 'package:flutter/src/material/colors.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primaryColor: Colors.black
      ),
      home: const MyHomePage(title: 'Profile'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);
  final String title;

  
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  String _name = "Soyun Jo";
  String _job = "Engineer";
  String _detail = "Flutter Developing";


  
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        backgroundColor: Colors.white,
        title: Text(widget.title, style: TextStyle(color: Colors.black)),
        leading: IconButton(icon: Icon(Icons.arrow_back_ios, color: Colors.blue), onPressed: () {}),
        actions: [
          IconButton(onPressed: () {}, icon: Icon(Icons.menu, color: Colors.blue))
        ],
      ),
      body:
      Column(
        children: [
          Expanded(child: Row(
            children: [
              Expanded(child: CircleAvatar(
                radius: 70,
                backgroundImage: AssetImage("images/img1.jpeg"),
              ),flex: 1,),
              Expanded(
                child: SizedBox(
                  height: 100,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: [
                      Text(_name, style : TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
                      Text(_job, style : TextStyle(fontSize: 18)),
                      Text(_detail, style : TextStyle(fontSize: 15)),
                    ],
                  ),
                ),
                flex: 1,
              )
            ],
          ), flex: 2,
          ),
          Expanded(
            child: Row(
              children: [
                Expanded(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text("50"),
                      Text("Posts")
                    ],
                  ),
                ),
                Container(height: 50, width: 2, color: Colors.grey),
                Expanded(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text("10"),
                      Text("Likes")
                    ],
                  ),
                ),
                Container(height: 50, width: 2, color: Colors.grey),
                Expanded(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text("3"),
                      Text("Shares")
                    ],
                  ),
                )
              ],
            ),
            flex: 1,
          ),
          Expanded(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                InkWell(
                  child: Container(
                    height: 50,
                    width: 180,
                    child: Text("Follow",
                    style: Theme.of(context).textTheme.caption?.copyWith(
                      color: Colors.white,
                      fontWeight: FontWeight.w500
                    ),),
                    padding: EdgeInsets.all(10),
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                      color: Colors.blueAccent,
                      borderRadius: BorderRadius.circular(10),
                    ),
                  ),
                  onTap: () {},
                ),
                InkWell(
                  child: Container(
                    height: 50,
                    width: 180,
                    child: Text("Message",
                      style: Theme.of(context).textTheme.caption?.copyWith(
                          color: Colors.black,
                          fontWeight: FontWeight.w500
                      ),),
                    padding: EdgeInsets.all(10),
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                      color: Colors.white,
                      border: Border.all(),
                      borderRadius: BorderRadius.circular(10),
                    ),
                  ),
                  onTap: () {},
                ),
              ],
            ),
            flex: 1,
          ),
          Expanded(
              child: DefaultTabController(
                length: 2,
                initialIndex: 0,
                child: Column(
                  children: <Widget> [
                    Expanded(
                      child: TabBar(
                        tabs: <Widget> [
                          new Tab(
                            icon: const Icon(Icons.directions_car, color: Colors.black),
                          ),
                          new Tab(
                            icon: const Icon(Icons.train, color: Colors.black),
                          )
                        ]
                      ),flex: 1,
                    ),
                    Expanded(
                      child: TabBarView(
                        children: <Widget>[
                          new Container(
                            child: GridView.count(
                              padding: const EdgeInsets.all(20),
                              crossAxisSpacing: 10,
                              mainAxisSpacing: 10,
                              crossAxisCount: 3,
                              children: <Widget> [
                                Expanded(
                                  child: Ink.image(image: AssetImage("images/img1.jpeg")),
                                ),
                                Expanded(
                                  child: Ink.image(image: AssetImage("images/img1.jpeg")),
                                ),
                                Expanded(
                                  child: Ink.image(image: AssetImage("images/img1.jpeg")),
                                ),
                                Expanded(
                                  child: Ink.image(image: AssetImage("images/img1.jpeg")),
                                ),
                                Expanded(
                                  child: Ink.image(image: AssetImage("images/img1.jpeg")),
                                ),
                                Expanded(
                                  child: Ink.image(image: AssetImage("images/img1.jpeg")),
                                ),
                                Expanded(
                                  child: Ink.image(image: AssetImage("images/img1.jpeg")),
                                ),
                                Expanded(
                                  child: Ink.image(image: AssetImage("images/img1.jpeg")),
                                ),
                                Expanded(
                                  child: Ink.image(image: AssetImage("images/img1.jpeg")),
                                ),
                              ],
                            ),
                          ),
                          new Container(
                            child: GridView.count(
                              padding: const EdgeInsets.all(20),
                              crossAxisSpacing: 10,
                              mainAxisSpacing: 10,
                              crossAxisCount: 3,
                              children: <Widget> [
                                Expanded(
                                  child: Ink.image(image: AssetImage("images/img1.jpeg")),
                                ),
                                Expanded(
                                  child: Ink.image(image: AssetImage("images/img1.jpeg")),
                                ),
                              ],
                            ),
                          )
                        ]
                      ),flex: 5,
                    )
                  ],
                ),
              ),
              flex: 5,
          ),
        ],
      )
    );
  }
}

์•„์ง์€ Flutter๋กœ ํ™”๋ฉด์„ ๊ทธ๋ฆฐ์ง€ ์–ผ๋งˆ ๋˜์ง€ ์•Š์•„
๊ฐ€๋…์„ฑ ์žˆ๋Š” ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ธฐ ๋ณด๋‹ค๋Š”
์šฐ์„  ์žฅํ™ฉํ•˜๋”๋ผ๋„ ํ•˜๋“œ์ฝ”๋”ฉ + ๋น ๋ฅด๊ฒŒ ํ™”๋ฉด ๊ทธ๋ฆฌ๊ธฐ์— ์ค‘์ ์„ ๋‘๊ณ  ์žˆ๋‹ค.

ํ™”๋ฉด์„ ๋‹ค ๊ทธ๋ฆฐ ์™€์ค‘์—๋„ ์˜ค๋ฅ˜๊ฐ€....ใ…Ž ๋„˜์ณ๋ฒ„๋ ค


ํ›„์—, ๋ณด๋‹ค ๋” ๋ณต์žกํ•œ ๊ทธ๋ฆผ์„ ์ œ๋Œ€๋กœ ๊ทธ๋ฆฌ๊ฒŒ ๋œ๋‹ค๋ฉด, ์žฌ์‚ฌ์šฉ์„ฑ, ๊ฐ€๋…์„ฑ ์žˆ๋Š” ์ฝ”๋“œ๋ฅผ ์งœ๋Š” ๋ฐฉ๋ฒ•๋„ ์ ์ฐจ ์ตํ˜€ ๋‚˜๊ฐ€์•ผ๊ฒ ๋‹ค. ๐Ÿ˜ญ
profile
์ƒ๊ฐ 10,000 ๋งŽ์€ infp ๐Ÿค”๐Ÿ’ญ
post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€