SurveyThemeData.fromJson constructor
SurveyThemeData.fromJson(
{ - Map<String, dynamic> json = const {},
})
Implementation
factory SurveyThemeData.fromJson({Map<String, dynamic> json = const {}}) {
convertRgbStringToColor(String colorToConvert, opacity) {
print("112 color to convert called is ${colorToConvert} ssdf");
if (colorToConvert.contains("#")) {
print("called inside has one ssd");
String color = colorToConvert.replaceAll('#', '0xff');
print("color returned is ${color}");
return Color(int.parse(color));
}
print("called inside not has one ssd");
var convertedString = colorToConvert
.substring(4, colorToConvert.length - 1)
.replaceAll(RegExp(' +'), ' ')
.split(',');
print("converted string is ${convertedString}");
if (convertedString.length < 3) {
return Color.fromRGBO(255, 255, 255, opacity);
}
print("testing converted to double prob 110");
return Color.fromRGBO(
int.parse(convertedString[0]),
int.parse(convertedString[1]),
int.parse(convertedString[2]),
opacity);
}
getBackgroundImageOpacity(brightness) {
int absoluteNumber = brightness.abs();
if (absoluteNumber == 0) {
return 1.0;
} else {
int numberToConvert = (absoluteNumber - 100).abs();
double doubleVar = numberToConvert / 100;
print("sso9 ${doubleVar}");
return doubleVar;
}
}
getBackgroundImageColor(brightness) {
print("decode brightness cc90 ${brightness} ");
if (brightness < 0) {
return Colors.black;
}
return Colors.white;
}
var backGroundImage = json['properties'] != null &&
json['properties']['backgroundImage'] != null &&
json['properties']['backgroundImage']['url'] != null
? json['properties']['backgroundImage']['url']
: 'noImage';
// Question Color Settings
var decodedQuestionColor = json['properties'] != null &&
json['properties']['colors'] != null &&
json['properties']['colors']['overrides'] != null &&
json['properties']['colors']['overrides']['questions'] != null
? convertRgbStringToColor(
json['properties']['colors']['overrides']['questions'], 1.0)
: Color.fromRGBO(57, 57, 57, 1.0);
var decodedQuestionDescriptionColor = json['properties'] != null &&
json['properties']['colors'] != null &&
json['properties']['colors']['overrides'] != null &&
json['properties']['colors']['overrides']['questions'] != null
? convertRgbStringToColor(
json['properties']['colors']['overrides']['questions'], 0.7)
: Color.fromRGBO(57, 57, 57, 0.7);
var decodedQuestionNumberColor = json['properties'] != null &&
json['properties']['colors'] != null &&
json['properties']['colors']['overrides'] != null &&
json['properties']['colors']['overrides']['questions'] != null
? convertRgbStringToColor(
json['properties']['colors']['overrides']['questions'], 0.5)
: Color.fromRGBO(57, 57, 57, 0.5);
// Answer Theme
var decodedAnswerColor = json['properties'] != null &&
json['properties']['colors'] != null &&
json['properties']['colors']['overrides'] != null &&
json['properties']['colors']['overrides']['answers'] != null
? convertRgbStringToColor(
json['properties']['colors']['overrides']['answers'], 1.0)
: Color.fromRGBO(63, 63, 63, 1.0);
// Opnion Scale Theme
var decodedOpnionBackgroundColorSelected = json['properties'] != null &&
json['properties']['colors'] != null &&
json['properties']['colors']['overrides'] != null &&
json['properties']['colors']['overrides']['answers'] != null
? convertRgbStringToColor(
json['properties']['colors']['overrides']['answers'], 0.8)
: Color.fromRGBO(63, 63, 63, 0.8);
var decodedOpnionBackgroundColorUnSelected = json['properties'] != null &&
json['properties']['colors'] != null &&
json['properties']['colors']['overrides'] != null &&
json['properties']['colors']['overrides']['answers'] != null
? convertRgbStringToColor(
json['properties']['colors']['overrides']['answers'], 0.1)
: Color.fromRGBO(63, 63, 63, 0.1);
var decodedOpnionBorderColor = json['properties'] != null &&
json['properties']['colors'] != null &&
json['properties']['colors']['overrides'] != null &&
json['properties']['colors']['overrides']['answers'] != null
? convertRgbStringToColor(
json['properties']['colors']['overrides']['answers'], 0.5)
: Color.fromRGBO(63, 63, 63, 0.5);
var decodedOpnionLabelColor = json['properties'] != null &&
json['properties']['colors'] != null &&
json['properties']['colors']['overrides'] != null &&
json['properties']['colors']['overrides']['answers'] != null
? convertRgbStringToColor(
json['properties']['colors']['overrides']['answers'], 0.8)
: Color.fromRGBO(63, 63, 63, 0.8);
var decodedBackgroundColor = json['properties'] != null &&
json['properties']['colors'] != null &&
json['properties']['colors']['overrides'] != null &&
json['properties']['colors']['overrides']['backgroundColor'] != null
? convertRgbStringToColor(
json['properties']['colors']['overrides']['backgroundColor'], 1.0)
: Color.fromRGBO(255, 255, 255, 1.0);
// print(' decoded background color is ${decodedBackgroundColor}');
// print("color detection cc90 ${json['properties']['backgroundImage']} ");
var decodedBackgroundImageColor = json['properties'] != null &&
json['properties']['backgroundImage'] != null &&
json['properties']['backgroundImage']['brightness'] != null
? getBackgroundImageColor(
json['properties']['backgroundImage']['brightness'])
: Color.fromRGBO(255, 255, 255, 1.0);
// var decodedBackgroundImageColor = Color.fromRGBO(255,255,255,1.0);
var decodedBackgroundImageColorOpacity = json['properties'] != null &&
json['properties']['backgroundImage'] != null &&
json['properties']['backgroundImage']['brightness'] != null
? getBackgroundImageOpacity(
json['properties']['backgroundImage']['brightness'])
: 1.0;
var ctaButtonDecodedColor = json['properties'] != null &&
json['properties']['colors'] != null &&
json['properties']['colors']['overrides'] != null &&
json['properties']['colors']['overrides']['ctaButton'] != null
? convertRgbStringToColor(
json['properties']['colors']['overrides']['ctaButton'], 1.0)
: Color.fromRGBO(4, 191, 116, 1);
// print(
// "cta button color override ${json['properties']['colors']['overrides']}");
return SurveyThemeData(
decodedQuestionColor,
decodedQuestionDescriptionColor,
decodedQuestionNumberColor,
decodedAnswerColor,
decodedBackgroundColor,
backGroundImage,
decodedOpnionBackgroundColorSelected,
decodedOpnionBackgroundColorUnSelected,
decodedOpnionBorderColor,
decodedOpnionLabelColor,
decodedBackgroundImageColor,
decodedBackgroundImageColorOpacity,
ctaButtonDecodedColor,
);
}