Skip to content

Commit

Permalink
Merge pull request #53 from 2024-Saphy/feat/integrate-selling-api
Browse files Browse the repository at this point in the history
[FEAT] selling screen
  • Loading branch information
boroboro01 authored Oct 16, 2024
2 parents 26758b9 + 88a9a36 commit 6b7a73b
Show file tree
Hide file tree
Showing 17 changed files with 779 additions and 214 deletions.
Binary file added assets/images/shop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 10 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:saphy/screens/selling/splash_selling_screen.dart';
import 'package:saphy/screens/welcome/otp_screen.dart';
import 'package:saphy/screens/welcome/signup_screen.dart';
import 'package:saphy/screens/welcome/welcome_screen.dart';
import 'package:provider/provider.dart';
import 'package:kakao_flutter_sdk_common/kakao_flutter_sdk_common.dart';
import 'package:saphy/utils/colors.dart';
import 'package:saphy/provider/image_provider.dart';
import 'package:saphy/screens/screen_controller.dart';

void main() async {
Expand All @@ -17,7 +14,14 @@ void main() async {
KakaoSdk.init(
nativeAppKey: kakaoNativeAppKey,
);
runApp(const MyApp());
runApp(
MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => ImageProviderModel()),
],
child: const MyApp(),
),
);
}

class MyApp extends StatelessWidget {
Expand Down
23 changes: 23 additions & 0 deletions lib/provider/image_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';

class ImageProviderModel with ChangeNotifier {
final List<XFile> _images = [];

List<XFile> get images => _images;

Future<void> addImage(XFile image) async {
_images.add(image);
notifyListeners(); // 상태가 변경되었음을 알림
}

void removeImage(int index) {
_images.removeAt(index);
notifyListeners();
}

void clearImages() {
_images.clear();
notifyListeners();
}
}
2 changes: 1 addition & 1 deletion lib/screens/selling/end_selling_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class _EndSellingScreenState extends State<EndSellingScreen> {
textAlign: TextAlign.center,
),
const Text(
'기기 수거를 위한 절차를 확인해볼까요?',
'기기 접수가 완료되면 알려드릴게요!',
style: TextStyle(
fontFamily: 'Pretendard',
fontSize: 20.0,
Expand Down
125 changes: 86 additions & 39 deletions lib/screens/selling/flaw_screen.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:saphy/screens/selling/rule_screen.dart';
import 'package:logger/logger.dart';
import 'package:provider/provider.dart';
import 'package:saphy/provider/image_provider.dart';
import 'package:saphy/screens/selling/end_selling_screen.dart';
import 'package:saphy/service/selling_service.dart';
import 'package:saphy/utils/colors.dart';
import 'package:saphy/widgets/normal_button.dart';
import 'package:toggle_list/toggle_list.dart';
Expand All @@ -14,6 +20,7 @@ class FlawScreen extends StatefulWidget {

class _FlawScreenState extends State<FlawScreen> {
final _listSize = 6;
final Logger logger = Logger();

List<String> titles = [
'판매하는 제품의 이름',
Expand All @@ -25,8 +32,28 @@ class _FlawScreenState extends State<FlawScreen> {
'수리 여부',
];

// 각 TextFormField의 입력값을 제어하기 위한 컨트롤러 리스트
List<TextEditingController> controllers = [];

@override
void initState() {
super.initState();
// _listSize만큼 컨트롤러 생성
controllers = List.generate(_listSize, (index) => TextEditingController());
}

@override
void dispose() {
// 사용이 끝난 후 컨트롤러 해제
for (var controller in controllers) {
controller.dispose();
}
super.dispose();
}

@override
Widget build(BuildContext context) {
final imageProvider = Provider.of<ImageProviderModel>(context);
return Scaffold(
resizeToAvoidBottomInset: false,
body: Column(
Expand Down Expand Up @@ -77,49 +104,51 @@ class _FlawScreenState extends State<FlawScreen> {
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 40.0),
child: ToggleList(
trailing: const Padding(
padding:
EdgeInsets.symmetric(horizontal: 20.0, vertical: 15.0),
child: Icon(FontAwesomeIcons.arrowDown),
),
children: List.generate(
_listSize,
(index) => ToggleListItem(
leading: const Padding(
padding: EdgeInsets.all(10.0),
),
itemDecoration: BoxDecoration(
color: gray100,
borderRadius: BorderRadius.circular(10.0),
trailing: const Padding(
padding:
EdgeInsets.symmetric(horizontal: 20.0, vertical: 15.0),
child: Icon(FontAwesomeIcons.arrowDown),
),
children: List.generate(
_listSize,
(index) => ToggleListItem(
leading: const Padding(
padding: EdgeInsets.all(10.0),
),
itemDecoration: BoxDecoration(
color: gray100,
borderRadius: BorderRadius.circular(10.0),
),
title: Text(
titles[index],
style: const TextStyle(
fontFamily: 'Pretendard',
fontSize: 20.0,
color: black,
fontWeight: FontWeight.w500,
),
title: Text(
titles[index],
),
divider: const Divider(
color: white,
),
content: Padding(
padding: const EdgeInsets.only(left: 20.0),
child: TextFormField(
controller: controllers[index],
decoration: const InputDecoration(
border: InputBorder.none,
),
style: const TextStyle(
fontFamily: 'Pretendard',
fontSize: 20.0,
color: black,
fontWeight: FontWeight.w500,
),
),
divider: const Divider(
color: white,
),
content: Padding(
padding: const EdgeInsets.only(left: 20.0),
child: TextFormField(
decoration: const InputDecoration(
border: InputBorder.none,
),
style: const TextStyle(
fontFamily: 'Pretendard',
fontSize: 20.0,
color: black,
fontWeight: FontWeight.w500,
),
),
),
),
)),
),
),
),
),
),
Padding(
Expand All @@ -129,10 +158,28 @@ class _FlawScreenState extends State<FlawScreen> {
title: '제출할게요',
bgColor: black,
txtColor: white,
onTap: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => const RuleScreen(),
));
onTap: () async {
List<File> imageFiles = imageProvider.images
.map((xfile) => File(xfile.path))
.toList();
Map<String, dynamic> requestObject = {
"itemId": 1, // 판매하는 제품의 고유 아이디, 동적으로 처리할 수 있음
"defect": {
"display": controllers[0].text, // 액정 스크래치 혹은 파손
"appearance": controllers[1].text, // 외관 스크래치 혹은 파손
"batteryEfficiency": controllers[2].text, // 배터리 효율
"function": controllers[3].text, // 기능 파손
"purchaseDate": controllers[4].text, // 구매 시기
"isRepaired": controllers[5].text, // 수리 여부
}
};
final statecode =
await createSellingItem(imageFiles, requestObject);
if (statecode == 200) {
Navigator.of(context).pushReplacement(MaterialPageRoute(
builder: (context) => const EndSellingScreen(),
));
}
},
flag: true,
),
Expand Down
Loading

0 comments on commit 6b7a73b

Please sign in to comment.