Skip to content

Commit 6fb5de7

Browse files
committed
change content
1 parent 5302bab commit 6fb5de7

File tree

12 files changed

+226
-72
lines changed

12 files changed

+226
-72
lines changed

assets/icons/camera.png

1.15 KB
Loading

assets/icons/crown.png

639 Bytes
Loading

assets/icons/profile.png

1.62 MB
Loading

lib/models/stat_date_model.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ class statDateModel {
77

88
statDateModel(this.time, this.days, this.weeks,
99
this.months, this.dayWeek);
10+
11+
statDateModel.fromJson(Map<String, dynamic> json)
12+
: time = json['hourlyStatisticsResponse']['time'],
13+
days = json['dailyStatisticsResponse']['days'],
14+
weeks = json['weeklyStatisticsResponse']['weeks'],
15+
months = json['monthlyStatisticsResponse']['months'],
16+
dayWeek = json['dayOfWeekStatisticsResponse']['dayWeek'];
17+
1018
@override
1119
String toString() {
1220
return '$time, $days, $weeks, $months, $dayWeek';

lib/models/stat_region_model.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ class statRegionModel {
33
final List<dynamic> areaTop; //흡연구역 중 최고 순위
44

55
statRegionModel(this.allRegion, this.areaTop);
6+
7+
statRegionModel.fromJson(Map<String, dynamic> json)
8+
: allRegion = json['allRegionStatisticsResponse']['allRegion'],
9+
areaTop = json['areaTopResponse']['areaTop'];
10+
611
@override
712
String toString() {
813
return '$allRegion, $areaTop';
Lines changed: 160 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
import 'dart:io';
2+
3+
import 'package:damyo/style.dart';
14
import 'package:flutter/material.dart';
25
import 'package:flutter_screenutil/flutter_screenutil.dart';
6+
import 'package:damyo/services/profile_update_service.dart';
7+
import 'package:go_router/go_router.dart';
8+
import 'package:image_picker/image_picker.dart';
9+
10+
XFile? _profileImage;
11+
final ImagePicker picker = ImagePicker();
12+
bool _changedImage = false;
313

414
bool _isFieldEmpty(TextEditingController controller) {
515
return controller.text.trim().isEmpty;
@@ -15,6 +25,17 @@ class UpdateprofileScreen extends StatefulWidget {
1525
class _UpdateprofileState extends State<UpdateprofileScreen> {
1626
final TextEditingController _nameController = TextEditingController();
1727

28+
// 이미지를 가져오는 함수
29+
Future getImage(ImageSource imageSource) async {
30+
final XFile? pickedFile = await picker.pickImage(source: imageSource);
31+
if (pickedFile != null) {
32+
setState(() {
33+
_profileImage = XFile(pickedFile.path);
34+
_changedImage = true;
35+
});
36+
}
37+
}
38+
1839
@override
1940
void initState() {
2041
super.initState();
@@ -38,52 +59,107 @@ class _UpdateprofileState extends State<UpdateprofileScreen> {
3859
'프로필 수정',
3960
),
4061
centerTitle: true,
62+
actions: [
63+
TextButton(
64+
onPressed: () async {
65+
if (!_isFieldEmpty(_nameController)) {
66+
try {
67+
String? result =
68+
await putUserUpdateName(_nameController.text);
69+
context.pop();
70+
} catch (e) {
71+
_showErrorLog(context, '이름 변경에 실패하셨습니다.');
72+
}
73+
}
74+
},
75+
child: textFormat(
76+
text: '완료', fontSize: 13, fontWeight: FontWeight.w500)),
77+
],
4178
),
4279
body: Center(
4380
child: Column(
4481
children: [
4582
SizedBox(height: 10.h),
83+
Stack(children: [
84+
Container(
85+
width: 110,
86+
height: 110,
87+
padding: const EdgeInsets.only(bottom: 1),
88+
clipBehavior: Clip.antiAlias,
89+
decoration: ShapeDecoration(
90+
color: Color(0xFFDEDEDE),
91+
shape: RoundedRectangleBorder(
92+
borderRadius: BorderRadius.circular(56),
93+
),
94+
),
95+
child: _profileImage == null
96+
? Image.asset(
97+
'assets/icons/profile.png',
98+
fit: BoxFit.cover,
99+
)
100+
: Image.file(
101+
File(_profileImage!.path),
102+
),
103+
),
104+
Positioned(
105+
top: 65,
106+
left: 65,
107+
child: IconButton(
108+
onPressed: () async {
109+
await getImage(ImageSource.gallery);
110+
},
111+
icon: Image.asset(
112+
'assets/icons/camera.png',
113+
fit: BoxFit.fill,
114+
),
115+
),
116+
),
117+
]),
46118
Expanded(
47119
child: SingleChildScrollView(
48120
scrollDirection: Axis.vertical,
49-
child: Column(
50-
crossAxisAlignment: CrossAxisAlignment.start,
51-
children: [
52-
const Padding(
53-
padding: EdgeInsets.only(bottom: 12.0, left: 16.0),
54-
child: Text(
55-
'이름',
56-
style: TextStyle(
57-
color: Color(0xFF262B32),
58-
fontSize: 16,
59-
fontFamily: 'Pretendard',
60-
fontWeight: FontWeight.w700,
121+
child: Padding(
122+
padding: const EdgeInsets.symmetric(horizontal: 16.0),
123+
child: Column(
124+
crossAxisAlignment: CrossAxisAlignment.start,
125+
children: [
126+
const Padding(
127+
padding: EdgeInsets.only(bottom: 12.0),
128+
child: Text(
129+
'이름',
130+
style: TextStyle(
131+
color: Color(0xFF262B32),
132+
fontSize: 16,
133+
fontFamily: 'Pretendard',
134+
fontWeight: FontWeight.w700,
135+
),
61136
),
62137
),
63-
),
64-
Container(
65-
padding: const EdgeInsets.symmetric(
66-
horizontal: 13, vertical: 10),
67-
clipBehavior: Clip.antiAlias,
68-
decoration: ShapeDecoration(
69-
color: Colors.white,
70-
shape: RoundedRectangleBorder(
71-
side: const BorderSide(
72-
width: 1, color: Color(0xFFE4E7EA)),
73-
borderRadius: BorderRadius.circular(10),
138+
Container(
139+
padding: const EdgeInsets.symmetric(
140+
horizontal: 13,
74141
),
75-
),
76-
child: TextField(
77-
controller: _nameController,
78-
style: const TextStyle(
79-
fontSize: 16,
80-
fontWeight: FontWeight.w500,
142+
clipBehavior: Clip.antiAlias,
143+
decoration: ShapeDecoration(
144+
color: Colors.white,
145+
shape: RoundedRectangleBorder(
146+
side: const BorderSide(
147+
width: 1, color: Color(0xFFE4E7EA)),
148+
borderRadius: BorderRadius.circular(10),
149+
),
150+
),
151+
child: TextField(
152+
controller: _nameController,
153+
style: const TextStyle(
154+
fontSize: 16,
155+
fontWeight: FontWeight.w500,
156+
),
157+
decoration:
158+
const InputDecoration(border: InputBorder.none),
81159
),
82-
decoration:
83-
const InputDecoration(border: InputBorder.none),
84160
),
85-
),
86-
],
161+
],
162+
),
87163
),
88164
),
89165
),
@@ -94,3 +170,54 @@ class _UpdateprofileState extends State<UpdateprofileScreen> {
94170
);
95171
}
96172
}
173+
174+
// 애러 메시지 띄우기
175+
void _showErrorLog(BuildContext context, String log) {
176+
showDialog(
177+
context: context,
178+
builder: (BuildContext context) {
179+
return AlertDialog(
180+
contentPadding: EdgeInsets.zero,
181+
content: Container(
182+
// width: 300,
183+
height: 180,
184+
clipBehavior: Clip.antiAlias,
185+
decoration: ShapeDecoration(
186+
color: Colors.white,
187+
shape: RoundedRectangleBorder(
188+
borderRadius: BorderRadius.circular(20),
189+
),
190+
),
191+
child: Center(
192+
child: Column(
193+
crossAxisAlignment: CrossAxisAlignment.center,
194+
children: [
195+
Row(
196+
mainAxisAlignment: MainAxisAlignment.end,
197+
children: [
198+
IconButton(
199+
onPressed: () {
200+
context.pop();
201+
},
202+
icon: const Icon(Icons.close),
203+
),
204+
],
205+
),
206+
Padding(
207+
padding: const EdgeInsets.only(top: 30.0),
208+
child: Column(
209+
mainAxisAlignment: MainAxisAlignment.center,
210+
children: [
211+
textFormat(
212+
text: log, fontSize: 16, fontWeight: FontWeight.w600),
213+
],
214+
),
215+
),
216+
],
217+
),
218+
),
219+
),
220+
);
221+
},
222+
);
223+
}

lib/screens/home/statistics/statistics_screen.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_screenutil/flutter_screenutil.dart';
33
import 'package:damyo/screens/home/statistics/statistics_screen_utill.dart';
4-
import 'package:damyo/services/get_date_statics_service.dart';
5-
import 'package:damyo/services/get_region_statics_service.dart';
4+
import 'package:damyo/services/statics_service.dart';
65
import 'package:damyo/models/stat_date_model.dart';
76
import 'package:damyo/models/stat_region_model.dart';
87
import 'package:damyo/database/smoke_database_helper.dart';

lib/screens/login/login_screen.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,15 @@ class _LoginScreenState extends State<LoginScreen> {
5656

5757
void signInWithNaver() async {
5858
NaverLoginResult naverUser = await FlutterNaverLogin.logIn();
59-
// final NaverLoginResult User = await FlutterNaverLogin.logIn();
6059
NaverAccessToken naverToken = await FlutterNaverLogin.currentAccessToken;
6160

6261
// print(naverUser.accessToken);
6362
if (naverUser != null) {
63+
print(naverToken);
6464
print('name = ${naverUser.account.name}');
6565
print('email = ${naverUser.account.email}');
6666
print('id = ${naverUser.account.id}');
67+
// print(naverToken);
6768
await storage.write(key: 'userID', value: naverUser.account.email);
6869
await storage.write(key: 'sns', value: "naver");
6970
Provider.of<IsLoginProvider>(context, listen: false).login();

lib/services/get_region_statics_service.dart

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import 'dart:convert';
2+
import 'package:flutter_dotenv/flutter_dotenv.dart';
3+
import 'package:http/http.dart' as http;
4+
5+
Future<String?> putUserUpdateName(String name) async {
6+
final baseUrl = dotenv.get('BASE_URL');
7+
final token = dotenv.get('TEST_TOKEN');
8+
var url = Uri.parse('$baseUrl/user/update/name?name=$name');
9+
var headers = {
10+
"Authorization": 'Bearer $token',
11+
};
12+
var response = await http.put(
13+
url,
14+
headers: headers
15+
);
16+
17+
18+
19+
if (response.statusCode == 200) {
20+
return response.body;
21+
} else {
22+
final Map<String, dynamic> jsonMap =
23+
jsonDecode(utf8.decode(response.bodyBytes));
24+
print(utf8.decode(response.bodyBytes));
25+
throw Exception("Failed to update name");
26+
}
27+
}
Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import 'dart:convert';
2+
import 'package:damyo/models/stat_region_model.dart';
23
import 'package:damyo/models/stat_date_model.dart';
34
import 'package:flutter_dotenv/flutter_dotenv.dart';
45
import 'package:http/http.dart' as http;
56

6-
7-
87
Future<statDateModel> getDateStatics() async {
98
final baseUrl = dotenv.get('BASE_URL');
109
var url = Uri.parse('$baseUrl/data/dateStatics');
@@ -17,14 +16,26 @@ Future<statDateModel> getDateStatics() async {
1716

1817
if (response.statusCode == 200) {
1918
// print(jsonMap);
20-
return statDateModel(
21-
jsonMap['hourlyStatisticsResponse']['time'],
22-
jsonMap['dailyStatisticsResponse']['days'],
23-
jsonMap['weeklyStatisticsResponse']['weeks'],
24-
jsonMap['monthlyStatisticsResponse']['months'],
25-
jsonMap['dayOfWeekStatisticsResponse']['dayWeek']);
19+
return statDateModel.fromJson(jsonMap);
2620
} else {
2721
print(utf8.decode(response.bodyBytes));
2822
throw Exception("Failed to date statics");
2923
}
3024
}
25+
26+
Future<statRegionModel> getRegionStatics() async {
27+
final baseUrl = dotenv.get('BASE_URL');
28+
var url = Uri.parse('$baseUrl/data/regionStatics');
29+
var response = await http.get(
30+
url,
31+
);
32+
33+
final Map<String, dynamic> jsonMap =
34+
jsonDecode(utf8.decode(response.bodyBytes));
35+
36+
if (response.statusCode == 200) {
37+
return statRegionModel.fromJson(jsonMap);
38+
} else {
39+
throw Exception("Failed to region statics");
40+
}
41+
}

0 commit comments

Comments
 (0)