Fakultas Ilmu Komputer UI

Verified Commit a88251ea authored by Muhammad Ariq Basyar's avatar Muhammad Ariq Basyar
Browse files

[GREEN] implemented new attribute for DetailUserModel

parent fb48439a
Pipeline #81213 passed with stages
in 13 minutes and 57 seconds
import 'dart:ui';
import 'package:json_annotation/json_annotation.dart';
part 'user.g.dart';
......@@ -103,11 +105,21 @@ class DetailUserModel extends BaseUserModel {
bool seen;
@JsonKey(name: 'hidden_fields')
List<String> hiddenFields;
@JsonKey(name: 'hidden_fields_verbose')
List<String> hiddenFieldsVerbose;
@JsonKey(name: 'can_see_hidden_fields')
bool canSeeHiddenFields;
@JsonKey(name: 'hidden_fields_color')
String hiddenFieldsColor;
DetailUserModel({
this.username,
this.email,
this.seen,
this.hiddenFields,
this.hiddenFieldsVerbose,
this.canSeeHiddenFields,
this.hiddenFieldsColor,
name,
tanggalLahir,
phoneNumber,
......@@ -130,11 +142,15 @@ class DetailUserModel extends BaseUserModel {
UpdateUserModel toUpdateUserModel() {
var thisData = toJson();
thisData.remove('username');
thisData.remove('email');
return UpdateUserModel.fromJson(thisData);
}
Color getHiddenFieldsColor() {
final strColor = hiddenFieldsColor.replaceAll('#', '0xff');
final hexColor = int.parse(strColor);
return Color(hexColor);
}
factory DetailUserModel.fromJson(Map<String, dynamic> json) =>
_$DetailUserModelFromJson(json);
......
......@@ -71,6 +71,13 @@ DetailUserModel _$DetailUserModelFromJson(Map<String, dynamic> json) {
username: json['username'] as String,
email: json['email'] as String,
seen: json['seen'] as bool,
hiddenFields:
(json['hidden_fields'] as List)?.map((e) => e as String)?.toList(),
hiddenFieldsVerbose: (json['hidden_fields_verbose'] as List)
?.map((e) => e as String)
?.toList(),
canSeeHiddenFields: json['can_see_hidden_fields'] as bool,
hiddenFieldsColor: json['hidden_fields_color'] as String,
name: json['name'],
tanggalLahir: json['tanggal_lahir'],
phoneNumber: json['phone_number'],
......@@ -80,8 +87,7 @@ DetailUserModel _$DetailUserModelFromJson(Map<String, dynamic> json) {
alamat: json['alamat'],
foto: json['foto'],
organisasiKomunitas: json['organisasi_komunitas'],
)..hiddenFields =
(json['hidden_fields'] as List)?.map((e) => e as String)?.toList();
);
}
Map<String, dynamic> _$DetailUserModelToJson(DetailUserModel instance) =>
......@@ -99,4 +105,7 @@ Map<String, dynamic> _$DetailUserModelToJson(DetailUserModel instance) =>
'email': instance.email,
'seen': instance.seen,
'hidden_fields': instance.hiddenFields,
'hidden_fields_verbose': instance.hiddenFieldsVerbose,
'can_see_hidden_fields': instance.canSeeHiddenFields,
'hidden_fields_color': instance.hiddenFieldsColor,
};
......@@ -199,7 +199,7 @@ class _EditProfileState extends State<EditProfile> {
),
Center(
child: Text(
'Data yang akan dirahasiakan adalah: ${widget.user.hiddenFields.join(', ')}',
'Data yang akan dirahasiakan adalah: ${widget.user.hiddenFieldsVerbose.join(', ')}',
style: TextStyle(
fontSize: 10.0,
),
......
......@@ -6,12 +6,11 @@ import 'package:bisaGo/network/data/network_model.dart';
import 'package:bisaGo/page/profile/edit_profile.dart';
import 'package:bisaGo/page/profile/profile_picture.dart';
import 'package:bisaGo/utils/datetime_utils.dart';
import 'package:bisaGo/utils/profile_utils.dart';
import 'package:flutter/material.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
const rahasia = Color(0xFF585858);
class Profile extends StatefulWidget {
final String email;
final bool isPublic;
......@@ -28,6 +27,7 @@ class Profile extends StatefulWidget {
class _ProfileState extends State<Profile> {
DetailUserModel user;
DetailUserModel viewUser;
String email;
UserBloc _bloc;
bool fetched;
......@@ -128,21 +128,22 @@ class _ProfileState extends State<Profile> {
if (!widget.isPublic)
Text(
'Halo, ${user.name.split(' ')[0]}!',
style: const TextStyle(
style: TextStyle(
fontSize: 26,
fontWeight: FontWeight.w900,
color: Colors.white,
fontFamily: 'Comfortaa',
color:
_getFontColor('name', seenColor: Colors.white),
fontFamily: 'Muli',
),
textAlign: TextAlign.center,
),
Text(
user.email,
style: const TextStyle(
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
color: rahasia,
fontFamily: 'Comfortaa',
color: _getFontColor('email', seenColor: Colors.white),
fontFamily: 'Muli',
),
textAlign: TextAlign.center,
),
......@@ -183,11 +184,11 @@ class _ProfileState extends State<Profile> {
),
title: Text(
user.name,
style: const TextStyle(
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w500,
color: Colors.black,
fontFamily: 'Comfortaa',
color: _getFontColor('name'),
fontFamily: 'Muli',
),
textAlign: TextAlign.left,
),
......@@ -200,11 +201,11 @@ class _ProfileState extends State<Profile> {
),
title: Text(
tanggalLahir,
style: const TextStyle(
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w500,
color: rahasia,
fontFamily: 'Comfortaa',
color: _getFontColor('tanggal_lahir'),
fontFamily: 'Muli',
),
textAlign: TextAlign.left,
),
......@@ -217,11 +218,11 @@ class _ProfileState extends State<Profile> {
),
title: Text(
user.phoneNumber,
style: const TextStyle(
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w500,
color: rahasia,
fontFamily: 'Comfortaa',
color: _getFontColor('phone_number'),
fontFamily: 'Muli',
),
textAlign: TextAlign.left,
),
......@@ -237,11 +238,11 @@ class _ProfileState extends State<Profile> {
user.jenisKelamin == null
? '-'
: user.jenisKelamin,
style: const TextStyle(
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w500,
color: Colors.black,
fontFamily: 'Comfortaa',
color: _getFontColor('jenis_kelamin'),
fontFamily: 'Muli',
),
textAlign: TextAlign.left,
),
......@@ -256,11 +257,11 @@ class _ProfileState extends State<Profile> {
user.disabilitas == '' || user.disabilitas == null
? 'Belum memilih'
: user.disabilitas,
style: const TextStyle(
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w500,
color: Colors.black,
fontFamily: 'Comfortaa',
color: _getFontColor('disabilitas'),
fontFamily: 'Muli',
),
textAlign: TextAlign.left,
),
......@@ -275,11 +276,11 @@ class _ProfileState extends State<Profile> {
user.pekerjaan == '' || user.pekerjaan == null
? '-'
: user.pekerjaan,
style: const TextStyle(
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w500,
color: Colors.black,
fontFamily: 'Comfortaa',
color: _getFontColor('pekerjaan'),
fontFamily: 'Muli',
),
textAlign: TextAlign.left,
),
......@@ -294,11 +295,11 @@ class _ProfileState extends State<Profile> {
user.alamat == '' || user.alamat == null
? '-'
: user.alamat,
style: const TextStyle(
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w500,
color: rahasia,
fontFamily: 'Comfortaa',
color: _getFontColor('alamat'),
fontFamily: 'Muli',
),
textAlign: TextAlign.left,
),
......@@ -314,11 +315,11 @@ class _ProfileState extends State<Profile> {
user.organisasiKomunitas == null
? '-'
: user.organisasiKomunitas,
style: const TextStyle(
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w500,
color: Colors.black,
fontFamily: 'Comfortaa',
color: _getFontColor('organisasi_komunitas'),
fontFamily: 'Muli',
),
textAlign: TextAlign.left,
),
......@@ -336,6 +337,15 @@ class _ProfileState extends State<Profile> {
);
}
Color _getFontColor(String fieldName, {Color seenColor = seenColor}) {
if (user.canSeeHiddenFields) return seenColor;
final hiddenFields = user.hiddenFields;
if (hiddenFields.contains(fieldName)) {
return user.getHiddenFieldsColor();
}
return seenColor;
}
void _navigateToEditProfile(BuildContext context) {
final route = MaterialPageRoute(builder: (_) => EditProfile(user: user));
Navigator.of(context).push(route);
......
import 'package:flutter/material.dart';
const seenColor = Colors.black;
String getNameInitials(String name) {
if (name.isEmpty) return '';
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment