커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
2주차 과제 이미지 정렬에 관한 질문 입니다.
[왕초보] 플러터(Flutter)로 시작하는 앱개발 종합반 v0
0주차
북마크
조*준
댓글
11
추천
0
조회수
11
조회수
11
답변 완료
  1. 첫 번째 페이지를 만드는 과정에서 중간에 shazam 이미지를 배치하는 과정에서 이미지가 가운데에 배치가 되지 않고 약간 왼쪽 위로 배치가 되는 현상이 발생하였습니다.
  2. 첫 번째 페이지에서 맨 위에 appbar에 아이콘이랑 라이브러리랑 떨어져서 나오는 현상이 있는데 왜 그런지 알고 싶습니다.


alignmet와 centerSlice를 사용을 해보았지만 제가 잘못 작성을 못한 건지 해결을 못하였습니다.

shazam 이미지를 원 가운데에 배치를 하고 싶습니다.



스파르타 즉문즉답





작성한 코드 및 에러 메세지

import 'package:flutter/material.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.

  @override

  Widget build(BuildContext context) {

    return MaterialApp(

      title: 'Shazam',

      theme: ThemeData(

        primarySwatch: Colors.blue,

      ),

      home: HomePage(),

    );

  }

}


class HomePage extends StatefulWidget {

  const HomePage({Key? key}) : super(key: key);


  @override

  State<HomePage> createState() => _HomePageState();

}


class _HomePageState extends State<HomePage> {

  @override

  Widget build(BuildContext context) {

    return DefaultTabController(

      initialIndex: 1,

      length: 3,

      child: Builder(builder: (context) {

        DefaultTabController.of(context).addListener(() {

          setState(() {});

        });


        return Scaffold(

          body: Stack(

            children: [

              TabBarView(

                children: [

                  FirstTab(),

                  SecondTab(),

                  ThirdTab(),

                ],

              ),

              SafeArea(

                child: Padding(

                  padding:

                      const EdgeInsets.symmetric(vertical: 20, horizontal: 16),

                  child: Column(

                    children: [

                      Container(

                        alignment: Alignment.topCenter,

                        child: TabPageSelector(

                          color: DefaultTabController.of(context).index == 1

                              ? Colors.blue[300]

                              : Colors.grey[400],

                          selectedColor:

                              DefaultTabController.of(context).index == 1

                                  ? Colors.white

                                  : Colors.blue,

                          indicatorSize: 8,

                        ),

                      ),

                    ],

                  ),

                ),

              ),

            ],

          ),

        );

      }),

    );

  }

}


// 첫번째 페이지

class FirstTab extends StatelessWidget {

  const FirstTab({Key? key}) : super(key: key);


  @override

  Widget build(BuildContext context) {

    const songs = [

      {

        'imageUrl': 'https://i.ytimg.com/vi/jAO0KXRdz_4/hqdefault.jpg',

        'title': '가을밤에 든 생각',

        'artist': '잔나비',

      },

      {

        'imageUrl': 'https://i.ytimg.com/vi/jAO0KXRdz_4/hqdefault.jpg',

        'title': '가을밤에 든 생각',

        'artist': '잔나비',

      },

      {

        'imageUrl': 'https://i.ytimg.com/vi/jAO0KXRdz_4/hqdefault.jpg',

        'title': '가을밤에 든 생각',

        'artist': '잔나비',

      },

      {

        'imageUrl': 'https://i.ytimg.com/vi/jAO0KXRdz_4/hqdefault.jpg',

        'title': '가을밤에 든 생각',

        'artist': '잔나비',

      },

      {

        'imageUrl': 'https://i.ytimg.com/vi/jAO0KXRdz_4/hqdefault.jpg',

        'title': '가을밤에 든 생각',

        'artist': '잔나비',

      },

      {

        'imageUrl': 'https://i.ytimg.com/vi/jAO0KXRdz_4/hqdefault.jpg',

        'title': '가을밤에 든 생각',

        'artist': '잔나비',

      },

    ];


    return Center(child: Text('첫번째 페이지'));

  }

}


// 두번째 페이지

class SecondTab extends StatelessWidget {

  const SecondTab({Key? key}) : super(key: key);


  @override

  Widget build(BuildContext context) {

    return Container(

      decoration: BoxDecoration(

          gradient: LinearGradient(

              begin: Alignment.topCenter,

              end: Alignment.bottomCenter,

              colors: [

            Colors.blue[300]!,

            Colors.blue[900]!,

          ])),

      child: SafeArea(

        child: Column(

          children: [

            Row(

              children: [

                Column(

                  children: [

                    IconButton(

                      onPressed: () {},

                      icon: Icon(

                        Icons.person,

                        color: Colors.white,

                      ),

                    ),

                    Text(

                      '라이브러리',

                      style: TextStyle(

                        color: Colors.white,

                      ),

                    ),

                  ],

                ),

                Spacer(),

                Column(

                  children: [

                    IconButton(

                      onPressed: () {},

                      icon: Icon(

                        Icons.show_chart,

                        color: Colors.white,

                      ),

                    ),

                    Text(

                      '차트',

                      style: TextStyle(

                        color: Colors.white,

                      ),

                    ),

                  ],

                ),

              ],

            ),

            Padding(

              padding: EdgeInsets.only(top: 80),

              child: Text(

                'Shazam하려면 탭하세요',

                style: TextStyle(

                  fontSize: 30,

                  color: Colors.white,

                ),

              ),

            ),

            Padding(

              padding: EdgeInsets.only(top: 30),

            ),

            Stack(

              children: [

                Container(

                  width: 200,

                  height: 200,

                  decoration: BoxDecoration(

                    shape: BoxShape.circle,

                    color: Colors.lightBlue,

                  ),

                ),

                Image.network(

                  "https://i.ibb.co/hxNbZ8p/shazam.png",

                  color: Colors.white,

                  width: 130,

                  height: 130,

                ),

              ],

            ),

          ],

        ),

      ),

    );

  }

}


// 세번째 페이지

class ThirdTab extends StatelessWidget {

  const ThirdTab({Key? key}) : super(key: key);


  @override

  Widget build(BuildContext context) {

    const chartData = {

      'korea': [

        {

          'imageUrl': 'https://i.ibb.co/xf2HpfG/dynamite.jpg',

          'name': 'Dynamite',

          'artist': 'BTS',

        },

        {

          'imageUrl': 'https://i.ibb.co/xf2HpfG/dynamite.jpg',

          'name': 'Dynamite',

          'artist': 'BTS',

        },

        {

          'imageUrl': 'https://i.ibb.co/xf2HpfG/dynamite.jpg',

          'name': 'Dynamite',

          'artist': 'BTS',

        },

      ],

      'global': [

        {

          'imageUrl': 'https://i.ibb.co/xf2HpfG/dynamite.jpg',

          'name': 'Dynamite',

          'artist': 'BTS',

        },

        {

          'imageUrl': 'https://i.ibb.co/xf2HpfG/dynamite.jpg',

          'name': 'Dynamite',

          'artist': 'BTS',

        },

        {

          'imageUrl': 'https://i.ibb.co/xf2HpfG/dynamite.jpg',

          'name': 'Dynamite',

          'artist': 'BTS',

        },

      ],

      'newyork': [

        {

          'imageUrl': 'https://i.ibb.co/xf2HpfG/dynamite.jpg',

          'name': 'Dynamite',

          'artist': 'BTS',

        },

        {

          'imageUrl': 'https://i.ibb.co/xf2HpfG/dynamite.jpg',

          'name': 'Dynamite',

          'artist': 'BTS',

        },

        {

          'imageUrl': 'https://i.ibb.co/xf2HpfG/dynamite.jpg',

          'name': 'Dynamite',

          'artist': 'BTS',

        },

      ],

    };


    return Center(child: Text('세번째 페이지'));

  }

}





취소
 공유
취소
댓글 0
댓글 알림
나의얼굴