Skip to content

Commit

Permalink
change content
Browse files Browse the repository at this point in the history
  • Loading branch information
choichangyeon committed Jun 5, 2024
1 parent 5302bab commit 6fb5de7
Show file tree
Hide file tree
Showing 12 changed files with 226 additions and 72 deletions.
Binary file added assets/icons/camera.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/crown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/profile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions lib/models/stat_date_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ class statDateModel {

statDateModel(this.time, this.days, this.weeks,
this.months, this.dayWeek);

statDateModel.fromJson(Map<String, dynamic> json)
: time = json['hourlyStatisticsResponse']['time'],
days = json['dailyStatisticsResponse']['days'],
weeks = json['weeklyStatisticsResponse']['weeks'],
months = json['monthlyStatisticsResponse']['months'],
dayWeek = json['dayOfWeekStatisticsResponse']['dayWeek'];

@override
String toString() {
return '$time, $days, $weeks, $months, $dayWeek';
Expand Down
5 changes: 5 additions & 0 deletions lib/models/stat_region_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ class statRegionModel {
final List<dynamic> areaTop; //흡연구역 중 최고 순위

statRegionModel(this.allRegion, this.areaTop);

statRegionModel.fromJson(Map<String, dynamic> json)
: allRegion = json['allRegionStatisticsResponse']['allRegion'],
areaTop = json['areaTopResponse']['areaTop'];

@override
String toString() {
return '$allRegion, $areaTop';
Expand Down
193 changes: 160 additions & 33 deletions lib/screens/home/mypage/in_mypage/updateprofile_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import 'dart:io';

import 'package:damyo/style.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:damyo/services/profile_update_service.dart';
import 'package:go_router/go_router.dart';
import 'package:image_picker/image_picker.dart';

XFile? _profileImage;
final ImagePicker picker = ImagePicker();
bool _changedImage = false;

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

// 이미지를 가져오는 함수
Future getImage(ImageSource imageSource) async {
final XFile? pickedFile = await picker.pickImage(source: imageSource);
if (pickedFile != null) {
setState(() {
_profileImage = XFile(pickedFile.path);
_changedImage = true;
});
}
}

@override
void initState() {
super.initState();
Expand All @@ -38,52 +59,107 @@ class _UpdateprofileState extends State<UpdateprofileScreen> {
'프로필 수정',
),
centerTitle: true,
actions: [
TextButton(
onPressed: () async {
if (!_isFieldEmpty(_nameController)) {
try {
String? result =
await putUserUpdateName(_nameController.text);
context.pop();
} catch (e) {
_showErrorLog(context, '이름 변경에 실패하셨습니다.');
}
}
},
child: textFormat(
text: '완료', fontSize: 13, fontWeight: FontWeight.w500)),
],
),
body: Center(
child: Column(
children: [
SizedBox(height: 10.h),
Stack(children: [
Container(
width: 110,
height: 110,
padding: const EdgeInsets.only(bottom: 1),
clipBehavior: Clip.antiAlias,
decoration: ShapeDecoration(
color: Color(0xFFDEDEDE),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(56),
),
),
child: _profileImage == null
? Image.asset(
'assets/icons/profile.png',
fit: BoxFit.cover,
)
: Image.file(
File(_profileImage!.path),
),
),
Positioned(
top: 65,
left: 65,
child: IconButton(
onPressed: () async {
await getImage(ImageSource.gallery);
},
icon: Image.asset(
'assets/icons/camera.png',
fit: BoxFit.fill,
),
),
),
]),
Expanded(
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Padding(
padding: EdgeInsets.only(bottom: 12.0, left: 16.0),
child: Text(
'이름',
style: TextStyle(
color: Color(0xFF262B32),
fontSize: 16,
fontFamily: 'Pretendard',
fontWeight: FontWeight.w700,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Padding(
padding: EdgeInsets.only(bottom: 12.0),
child: Text(
'이름',
style: TextStyle(
color: Color(0xFF262B32),
fontSize: 16,
fontFamily: 'Pretendard',
fontWeight: FontWeight.w700,
),
),
),
),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 13, vertical: 10),
clipBehavior: Clip.antiAlias,
decoration: ShapeDecoration(
color: Colors.white,
shape: RoundedRectangleBorder(
side: const BorderSide(
width: 1, color: Color(0xFFE4E7EA)),
borderRadius: BorderRadius.circular(10),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 13,
),
),
child: TextField(
controller: _nameController,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
clipBehavior: Clip.antiAlias,
decoration: ShapeDecoration(
color: Colors.white,
shape: RoundedRectangleBorder(
side: const BorderSide(
width: 1, color: Color(0xFFE4E7EA)),
borderRadius: BorderRadius.circular(10),
),
),
child: TextField(
controller: _nameController,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
),
decoration:
const InputDecoration(border: InputBorder.none),
),
decoration:
const InputDecoration(border: InputBorder.none),
),
),
],
],
),
),
),
),
Expand All @@ -94,3 +170,54 @@ class _UpdateprofileState extends State<UpdateprofileScreen> {
);
}
}

// 애러 메시지 띄우기
void _showErrorLog(BuildContext context, String log) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
contentPadding: EdgeInsets.zero,
content: Container(
// width: 300,
height: 180,
clipBehavior: Clip.antiAlias,
decoration: ShapeDecoration(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
),
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
IconButton(
onPressed: () {
context.pop();
},
icon: const Icon(Icons.close),
),
],
),
Padding(
padding: const EdgeInsets.only(top: 30.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
textFormat(
text: log, fontSize: 16, fontWeight: FontWeight.w600),
],
),
),
],
),
),
),
);
},
);
}
3 changes: 1 addition & 2 deletions lib/screens/home/statistics/statistics_screen.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:damyo/screens/home/statistics/statistics_screen_utill.dart';
import 'package:damyo/services/get_date_statics_service.dart';
import 'package:damyo/services/get_region_statics_service.dart';
import 'package:damyo/services/statics_service.dart';
import 'package:damyo/models/stat_date_model.dart';
import 'package:damyo/models/stat_region_model.dart';
import 'package:damyo/database/smoke_database_helper.dart';
Expand Down
3 changes: 2 additions & 1 deletion lib/screens/login/login_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ class _LoginScreenState extends State<LoginScreen> {

void signInWithNaver() async {
NaverLoginResult naverUser = await FlutterNaverLogin.logIn();
// final NaverLoginResult User = await FlutterNaverLogin.logIn();
NaverAccessToken naverToken = await FlutterNaverLogin.currentAccessToken;

// print(naverUser.accessToken);
if (naverUser != null) {
print(naverToken);
print('name = ${naverUser.account.name}');
print('email = ${naverUser.account.email}');
print('id = ${naverUser.account.id}');
// print(naverToken);
await storage.write(key: 'userID', value: naverUser.account.email);
await storage.write(key: 'sns', value: "naver");
Provider.of<IsLoginProvider>(context, listen: false).login();
Expand Down
24 changes: 0 additions & 24 deletions lib/services/get_region_statics_service.dart

This file was deleted.

27 changes: 27 additions & 0 deletions lib/services/profile_update_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'dart:convert';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:http/http.dart' as http;

Future<String?> putUserUpdateName(String name) async {
final baseUrl = dotenv.get('BASE_URL');
final token = dotenv.get('TEST_TOKEN');
var url = Uri.parse('$baseUrl/user/update/name?name=$name');
var headers = {
"Authorization": 'Bearer $token',
};
var response = await http.put(
url,
headers: headers
);



if (response.statusCode == 200) {
return response.body;
} else {
final Map<String, dynamic> jsonMap =
jsonDecode(utf8.decode(response.bodyBytes));
print(utf8.decode(response.bodyBytes));
throw Exception("Failed to update name");
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import 'dart:convert';
import 'package:damyo/models/stat_region_model.dart';
import 'package:damyo/models/stat_date_model.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:http/http.dart' as http;

// [email protected]

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

if (response.statusCode == 200) {
// print(jsonMap);
return statDateModel(
jsonMap['hourlyStatisticsResponse']['time'],
jsonMap['dailyStatisticsResponse']['days'],
jsonMap['weeklyStatisticsResponse']['weeks'],
jsonMap['monthlyStatisticsResponse']['months'],
jsonMap['dayOfWeekStatisticsResponse']['dayWeek']);
return statDateModel.fromJson(jsonMap);
} else {
print(utf8.decode(response.bodyBytes));
throw Exception("Failed to date statics");
}
}

Future<statRegionModel> getRegionStatics() async {
final baseUrl = dotenv.get('BASE_URL');
var url = Uri.parse('$baseUrl/data/regionStatics');
var response = await http.get(
url,
);

final Map<String, dynamic> jsonMap =
jsonDecode(utf8.decode(response.bodyBytes));

if (response.statusCode == 200) {
return statRegionModel.fromJson(jsonMap);
} else {
throw Exception("Failed to region statics");
}
}
Loading

0 comments on commit 6fb5de7

Please sign in to comment.