커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
22. 피드삭제 개발 진행중입니다. 삭제가 안되고 있습니다.
[왕초보] 플러터(Flutter)로 시작하는 앱개발 종합반
3주차
북마크
이*경
댓글
58
추천
0
조회수
50
조회수
50
답변 완료

* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.


마지막 feedid 전달까지 진행했습니다.

삭제 버튼을 눌러도 삭제가 안됩니다.

그래서 에뮬을 껐다키니, 새글 추가부터 피드 우측 버튼도 안됩니다.




스파르타 즉문즉답





import 'package:flutter/cupertino.dart';

import 'package:flutter/material.dart';

import 'package:get/get.dart';

import 'package:thread_app_sample/feed_model.dart';

import 'package:thread_app_sample/image_view.dart';

import 'package:thread_app_sample/main.dart';

import 'package:thread_app_sample/thread_feed_write.controller.dart';

import 'package:thread_app_sample/thread_write_page.dart';

import 'package:timeago/timeago.dart' as timeago;


class Home extends StatelessWidget {

 const Home({super.key});


 Widget _header() {

  return Row(

   mainAxisAlignment: MainAxisAlignment.spaceBetween,

   children: [

    SizedBox(width: 50),

    Image.asset('assets/images/thread_logo.png', width: 50),

    Image.asset('assets/images/more_icon.png', width: 50),

   ],

  );

 }


 Widget _quickFeedWriteView() {

  return GestureDetector(

   onTap: () async {

    var result = await Get.to<FeedModel?>(

     ThreadWritePage(),

     binding: BindingsBuilder(() {

      Get.put(ThreadFeedWriteController());

     }),

    );

    if (result != null) {

     Get.find<HomeFeedListcontroller>().addFeed(result);

    }

   },

   child: Column(

    children: [

     Row(

      children: [

       Image.asset('assets/images/profile_image.png', width: 50),

       SizedBox(width: 10),

       Expanded(

        child: Column(

         crossAxisAlignment: CrossAxisAlignment.stretch,

         children: [

          Text(

           'Kimsungduck',

           style: TextStyle(

            fontWeight: FontWeight.bold,

            color: Color(0xff262626),

           ),

          ),

          Text(

           '새로운 소식이 있나요?',

           style: TextStyle(color: Color(0xff9a9a9a), fontSize: 14),

          ),

         ],

        ),

       ),

      ],

     ),

     SizedBox(height: 15),

     Row(

      mainAxisAlignment: MainAxisAlignment.start,

      children: [

       SizedBox(width: 60),

       GestureDetector(

        child: Image.asset('assets/images/photo_icon.png', width: 30),

       ),

       SizedBox(width: 10),

       GestureDetector(

        child: Image.asset('assets/images/photo_icon.png', width: 30),

       ),

       SizedBox(width: 10),

       GestureDetector(

        child: Image.asset('assets/images/gif_icon.png', width: 30),

       ),

       SizedBox(width: 10),

       GestureDetector(

        child: Image.asset('assets/images/mic_icon.png', width: 30),

       ),

       SizedBox(width: 10),

       GestureDetector(

        child: Image.asset('assets/images/align_icon.png', width: 30),

       ),

      ],

     ),

    ],

   ),

  );

 }


 Widget _singleFeed(FeedModel model) {

  return Row(

   crossAxisAlignment: CrossAxisAlignment.start,

   children: [_leftProfileArea(), Expanded(child: _contentArea(model))],

  );

 }


 Widget _leftProfileArea() {

  return Column(

   children: [

    SizedBox(

     width: 60,

     height: 60,

     child: Stack(

      children: [

       Align(

        alignment: Alignment.centerLeft,

        child: ClipRRect(

         borderRadius: BorderRadius.circular(50),

         child: Image.network(

          'https://yt3.googleusercontent.com/XmYJ7m6JFlhA5BNLnQdnlew7g1E6YGSE4p8hl8ow_pOI6-cZkGdjo38oJhBG7NPrj9eawodgqA=s900-c-k-c0x00ffffff-no-rj',

          width: 50,

         ),

        ),

       ),

       Positioned(

        right: 5,

        bottom: 2,

        child: SizedBox(

         width: 20,

         height: 20,

         child: ClipRRect(

          borderRadius: BorderRadius.circular(20),

          child: Container(

           decoration: BoxDecoration(color: Colors.black),

           child: Icon(Icons.add, color: Colors.white, size: 17),

          ),

         ),

        ),

       ),

      ],

     ),

    ),

   ],

  );

 }


 void _showCupertinoActionSheet(String feedId) {

  showCupertinoModalPopup(

   context: Get.context!,

   builder:

     (BuildContext context) => CupertinoActionSheet(

      actions: <CupertinoActionSheetAction>[

       CupertinoActionSheetAction(

        onPressed: () {

         Navigator.pop(context);

         print('Edit Pressed');

        },

        child: Text('수정'),

       ),

       CupertinoActionSheetAction(

        onPressed: () {

         Navigator.pop(context);

         Get.find<HomeFeedListcontroller>().removeFeed(feedId);

        },

        isDestructiveAction: true,

        child: Text('삭제'),

       ),

      ],

      cancelButton: CupertinoActionSheetAction(

       onPressed: () {

        Navigator.pop(context);

       },

       child: Text('취소'),

      ),

     ),

  );

 }


 Widget _contentArea(FeedModel model) {

  return Column(

   crossAxisAlignment: CrossAxisAlignment.stretch,

   children: [

    SizedBox(

     height: 30,

     child: Row(

      mainAxisAlignment: MainAxisAlignment.spaceBetween,

      children: [

       Row(

        children: [

         Text(

          '개발하는남자',

          style: TextStyle(

           color: Colors.black,

           fontSize: 14,

           fontWeight: FontWeight.bold,

          ),

         ),

         SizedBox(width: 7),

         Text(

          timeago.format(

           DateTime.now().subtract(

            DateTime.now().difference(model.createdAt),

           ),

           locale: 'ko',

          ),

          style: TextStyle(color: Color(0xff999999), fontSize: 14),

         ),

        ],

       ),

       GestureDetector(

        onTap: () {

         _showCupertinoActionSheet(model.id);

        },

        child: Icon(Icons.more_horiz, color: Color(0xff999999)),

       ),

      ],

     ),

    ),

    Text(model.contents, style: TextStyle(color: Colors.black)),

    SizedBox(height: 10),

    if (model.images.isNotEmpty) ImageViewWidget(images: model.images),

    SizedBox(height: 10),

    Row(

     children: [

      GestureDetector(

       onTap: () {},

       child: SizedBox(

        width: 55,

        child: Row(

         children: [

          Image.asset('assets/images/icon_like.png', width: 30),

          Text('24'),

         ],

        ),

       ),

      ),

      GestureDetector(

       onTap: () {},

       child: SizedBox(

        width: 55,

        child: Row(

         children: [

          Image.asset('assets/images/icon_message.png', width: 30),

          Text('14'),

         ],

        ),

       ),

      ),

      GestureDetector(

       onTap: () {},

       child: SizedBox(

        width: 55,

        child: Row(

         children: [

          Image.asset('assets/images/icon_share.png', width: 30),

          Text('7'),

         ],

        ),

       ),

      ),

      GestureDetector(

       onTap: () {},

       child: Image.asset('assets/images/icon_send.png', width: 30),

      ),

     ],

    ),

   ],

  );

 }


 @override

 Widget build(BuildContext context) {

  return Scaffold(

   body: SafeArea(

    child: ListView(

     children: [

      _header(),

      SizedBox(height: 20),

      Padding(

       padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),

       child: _quickFeedWriteView(),

      ),

      Divider(),

      GetBuilder<HomeFeedListcontroller>(

       builder: (controller) {

        if (controller.feedList.isEmpty) {

         return Center(

          child: Padding(

           padding: const EdgeInsets.all(30.0),

           child: Text(

            '피드가 없습니다.',

            style: TextStyle(color: Colors.black),

           ),

          ),

         );

        }

        return Padding(

         padding: const EdgeInsets.symmetric(horizontal: 15),

         child: Column(

          children: List.generate(

           controller.feedList.length,

           (index) => _singleFeed(controller.feedList[index]),

          ),

         ),

        );

       },

      ),

     ],

    ),

   ),

  );

 }

}



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