Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
YJunSuk committed Nov 30, 2023
2 parents c9529db + 48dda6b commit 9d0e521
Show file tree
Hide file tree
Showing 13 changed files with 236 additions and 115 deletions.
1 change: 1 addition & 0 deletions devtools_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extensions:
30 changes: 19 additions & 11 deletions lib/models/goods.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,29 @@ import 'package:cloud_firestore/cloud_firestore.dart';
class Goods {
String? id;
List<String>? photoList;
String username;
String? saler;
String? buyer;
String title;
String? content;
String price;
String? loc;
String? likeCnt;
String? readCnt;
String? chatCnt;
Timestamp? uploadTime;
Timestamp? updateTime;
String category;

Goods(
{required this.photoList,
required this.username,
{required this.id,
required this.photoList,
required this.saler,
required this.buyer,
required this.title,
required this.content,
required this.price,
required this.loc,
required this.likeCnt,
required this.readCnt,
required this.chatCnt,
required this.uploadTime,
required this.updateTime,
required this.category});
Expand All @@ -31,27 +34,30 @@ class Goods {
Goods.fromJson(dynamic json)
: id = json['id'],
photoList = json['photoList'].cast<String>() ?? "",
username = json['username'],
saler = json['saler'],
buyer = json['buyer'],
title = json['title'],
content = json['content'],
loc = json['location'],
price = json['price'], // 또는 json['price'].toInt() 등으로 수정
likeCnt = json['likeCnt'],
readCnt = json['readCnt'],
chatCnt = json['chatCnt'],
uploadTime = json['uploadTime'],
updateTime = json['updateTime'],
category = json['category'];

// firebase에 저장할 때
Map<String, dynamic> toJson() => {
'id': id,
'photoList': photoList,
'username': username,
'buyer': buyer,
'saler': saler,
'title': title,
'content': content,
'price': price,
'loc': loc,
'likeCnt': likeCnt,
'readCnt': readCnt,
'chatCnt': chatCnt,
'uploadTime': uploadTime,
'updateTime': updateTime,
'category': category,
Expand All @@ -64,14 +70,16 @@ class Goods {

factory Goods.fromDocumentSnapshot(DocumentSnapshot doc) {
return Goods(
id: doc['id'],
photoList: doc['photoList'].cast<String>(),
username: doc['username'],
saler: doc['saler'],
buyer: doc['buyer'],
title: doc['title'],
content: doc['content'],
price: doc['price'], // 또는 json['price'].toInt() 등으로 수정
loc: doc['loc'],
likeCnt: doc['likeCnt'],
readCnt: doc['readCnt'],
chatCnt: doc['chatcnt'],
uploadTime: doc['uploadTime'],
updateTime: doc['updateTime'],
category: doc['category']);
Expand Down
4 changes: 4 additions & 0 deletions lib/models/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ class UserModel {
final String nickName;
final String schoolName;
final double mannerTemperature;
final List<String>? likeList;

UserModel({
required this.id,
required this.phoneNum,
required this.nickName,
required this.schoolName,
required this.mannerTemperature,
this.likeList,
});

Map<String, dynamic> toMap() {
Expand All @@ -21,6 +23,7 @@ class UserModel {
'nickname': nickName,
'schoolName': schoolName,
'mannerTemperature': mannerTemperature,
'likeList': likeList,
};
}

Expand All @@ -32,6 +35,7 @@ class UserModel {
nickName: data['nickname'] ?? '이름없음',
schoolName: data['schoolName'] ?? '정보없음',
mannerTemperature: (data['mannerTemperature'] ?? 0).toDouble(),
likeList: data['likeList'] ?? [],
);
}
}
1 change: 1 addition & 0 deletions lib/pages/AuthPage/regist_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class _RegistScreenState extends State<RegistScreen> {
nickName: _nicknameController.text,
schoolName: selectedSchool!,
mannerTemperature: 36.5,
likeList: [],
);

// UserService 인스턴스 생성
Expand Down
10 changes: 7 additions & 3 deletions lib/pages/Goods/add_goods.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:math';

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -79,20 +81,22 @@ class _AddGoodsFormState extends State<AddGoodsForm> {

void register() async {
final goodsService = GoodsService();
final userService = UserService();

String number = FirebaseFirestore.instance.collection('goods').doc().id;
final userProvider = Provider.of<UserProvider>(context, listen: false);
final user = userProvider.user;

final goods = Goods(
id: number,
photoList: [],
username: user!.nickName,
saler: user!.nickName,
buyer: null,
title: _itemNameController.text,
content: _itemDescriptionController.text,
price: _priceController.text,
loc: _location,
likeCnt: "0",
readCnt: "0",
chatCnt: "0",
uploadTime: Timestamp.now(),
updateTime: Timestamp.now(),
category: firstCate);
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/Goods/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class _HomeState extends State<Home> {
width: 1,
),
Text(
goods.readCnt ?? '0',
goods.chatCnt ?? '0',
style: TextStyle(fontSize: 14),
),
SvgPicture.asset(
Expand Down
122 changes: 91 additions & 31 deletions lib/pages/MyPage/profile_screen.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// ignore_for_file: non_constant_identifier_names
// ignore_for_file: non_constant_identifier_names, use_build_context_synchronously

import 'package:flutter/material.dart';
import 'package:hakgeun_market/models/goods.dart';
import 'package:hakgeun_market/models/user.dart';
import 'package:hakgeun_market/pages/AuthPage/login_screen.dart';
import 'package:hakgeun_market/pages/AuthPage/regist_screen.dart';
import 'package:hakgeun_market/pages/Goods/home.dart';
import 'package:hakgeun_market/provider/navigation_provider.dart';
import 'package:hakgeun_market/provider/user_provider.dart';
import 'package:hakgeun_market/service/goodsService.dart';
import 'package:hakgeun_market/service/userService.dart';
import 'package:provider/provider.dart';

Expand All @@ -21,7 +25,8 @@ class ProfilePage extends State<ProfileScreen> {
final userProvider = Provider.of<UserProvider>(context);
final navProvider = Provider.of<NavigationProvider>(context);
final user = userProvider.user;

List<Goods>? searchData;
final GoodsService goodsService = GoodsService();
if (user != null) {

return Scaffold(
Expand All @@ -31,37 +36,42 @@ class ProfilePage extends State<ProfileScreen> {
ListTile(
leading: const Icon(Icons.account_circle, size: 50),
title: Text(user.nickName),
subtitle: Text('${user.schoolName} #${user.phoneNum}'),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('${user.schoolName} #${user.phoneNum}'),
],
),
),
_buildMannerTemperature(user.mannerTemperature),
const Divider(),
_buildButton(context, Icons.list, '판매목록', Colors.green, () {
_buildMannerTemperature(context, user.mannerTemperature),
const Divider(),
_buildButton(context, Icons.list, '판매목록', Colors.green, () async {
// Filter goods for Sales List
List<Goods> salesList =
await goodsService.getFilterSaleGoods(user.nickName);

Navigator.push(
context,
MaterialPageRoute(builder: (context) => Container()),
MaterialPageRoute(
builder: (context) => Home(
SearchData: salesList,
),
),
);
}),
_buildButton(context, Icons.shopping_cart, '구매목록', Colors.green,
() {
// Navigator push to 구매목록 screen
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Container()),
);
}),
_buildButton(context, Icons.favorite, '관심목록', Colors.green, () {
// Navigator push to 관심목록 screen
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Container()),
);
}),
_buildButton(context, Icons.notifications, '알림목록', Colors.green,
() {
// Navigator push to 알림목록 screen
() async {
List<Goods> buyList =
await goodsService.getFilterBuyGoods(user.nickName);

Navigator.push(
context,
MaterialPageRoute(builder: (context) => Container()),
MaterialPageRoute(
builder: (context) => Home(
SearchData: buyList,
),
),
);
}),
const Divider(),
Expand Down Expand Up @@ -197,24 +207,74 @@ class ProfilePage extends State<ProfileScreen> {
);
}

Widget _buildMannerTemperature(double temperature) {
Widget _buildMannerTemperature(BuildContext context, double temperature) {
Color color;
String emoji;

if (temperature < 35) {
color = Colors.blue;
emoji = '😊'; // Emoji for lower temperatures
} else if (temperature < 37) {
color = Colors.green;
emoji = '😐'; // Emoji for moderate temperatures
} else {
color = Colors.red;
emoji = '😷'; // Emoji for higher temperatures
}

return ListTile(
title: const Text('매너 온도'),
subtitle: LinearProgressIndicator(
value: temperature / 100,
valueColor: AlwaysStoppedAnimation<Color>(color),
backgroundColor: Colors.grey[300],
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
const Text("학근 점수"),
const SizedBox(
width:
8.0), // Adjust the spacing between title and temperature
Text('${temperature.toStringAsFixed(1)}°C'),
const SizedBox(
width:
8.0), // Adjust the spacing between temperature and emoji
Text(emoji),
],
),
GestureDetector(
onTap: () {
_showMannerTemperatureInfo(context);
},
child: const Icon(Icons.info_outline,
color: Colors.blue), // Adjust the color as needed
),
],
),
subtitle: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: LinearProgressIndicator(
value: temperature / 100,
valueColor: AlwaysStoppedAnimation<Color>(color),
backgroundColor: Colors.grey[300],
),
),
trailing: Text('${temperature.toStringAsFixed(1)}°C'),
);
}

void _showMannerTemperatureInfo(BuildContext context) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('학근점수란?'),
content: const Text(
'학근점수는 사용자의 활동에 기반한 평판 점수입니다.\n긍정적인 활동으로 학점이 상승하며, 부정적인 행동으로 하락합니다.'),
actions: <Widget>[
TextButton(
child: const Text('닫기'),
onPressed: () => Navigator.of(context).pop(),
),
],
);
},
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/pages/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class _AppState extends State<App> {
'assets/svg/text-box.svg',
width: 30,
),
label: '게시판?'),
label: '관심목록'),
BottomNavigationBarItem(
icon: SvgPicture.asset(
'assets/svg/chat-outline.svg',
Expand Down
Loading

0 comments on commit 9d0e521

Please sign in to comment.