Commit 9f4cb968 authored by DatHV's avatar DatHV
Browse files

update build config

parent 956c501c
import 'dart:convert';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'dart:io'; import 'dart:io';
......
import 'dart:convert'; import 'dart:convert';
import 'dart:typed_data';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
...@@ -28,15 +29,52 @@ class RequestInterceptor extends Interceptor { ...@@ -28,15 +29,52 @@ class RequestInterceptor extends Interceptor {
options.headers.addAll(headers); options.headers.addAll(headers);
// On web, ensure request payload is JSON encoded to avoid FormData fallback. if (kIsWeb) {
if (kIsWeb && options.data is Map) { _normalizeWebBody(options);
try {
options.data = jsonEncode(options.data);
} catch (_) {
// If encoding fails, keep original data.
}
} }
handler.next(options); handler.next(options);
} }
void _normalizeWebBody(RequestOptions options) {
final body = options.data;
if (body == null) return;
final contentType = (options.headers[Headers.contentTypeHeader] ?? options.contentType ?? '')
.toString()
.toLowerCase();
if (!contentType.contains('application/json')) {
return;
}
try {
if (body is Uint8List) {
options.data = utf8.decode(body);
return;
}
if (body is ByteBuffer) {
options.data = utf8.decode(body.asUint8List());
return;
}
if (body is ByteData) {
options.data = utf8.decode(body.buffer.asUint8List());
return;
}
if (body is List<int>) {
options.data = utf8.decode(body);
return;
}
if (body is Map || body is List) {
options.data = jsonEncode(body);
return;
}
if (body is String) {
return;
}
options.data = jsonEncode(body);
} catch (e) {
if (kDebugMode) {
print('⚠️ RequestInterceptor: failed to normalize JSON body - $e');
}
}
}
} }
...@@ -27,16 +27,7 @@ class MonthlyPointsChart extends StatelessWidget { ...@@ -27,16 +27,7 @@ class MonthlyPointsChart extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
print('🔍 MonthlyPointsChart Debug:');
print(' - items.length: ${items.length}');
print(' - date: $date');
print(' - monthSummary: $monthSummary');
for (int i = 0; i < items.length; i++) {
print(' - items[$i]: ${items[i].summaryDate} -> reward: ${items[i].rewardDayTotal}');
}
final parsed = _parseToDayMap(items, date); final parsed = _parseToDayMap(items, date);
print(' - parsed map: $parsed');
final daysInMonth = DateUtils.getDaysInMonth(date.year, date.month); final daysInMonth = DateUtils.getDaysInMonth(date.year, date.month);
final maxVal = parsed.values.isEmpty ? 0 : parsed.values.reduce((a, b) => a > b ? a : b); final maxVal = parsed.values.isEmpty ? 0 : parsed.values.reduce((a, b) => a > b ? a : b);
final yMax = _niceMax(maxVal.abs().toDouble()); final yMax = _niceMax(maxVal.abs().toDouble());
...@@ -52,13 +43,6 @@ class MonthlyPointsChart extends StatelessWidget { ...@@ -52,13 +43,6 @@ class MonthlyPointsChart extends StatelessWidget {
barRods: [BarChartRodData(toY: v, width: 8, borderRadius: BorderRadius.circular(2), color: color)], barRods: [BarChartRodData(toY: v, width: 8, borderRadius: BorderRadius.circular(2), color: color)],
); );
}); });
print(' - daysInMonth: $daysInMonth');
print(' - maxVal: $maxVal');
print(' - yMax: $yMax');
print(' - yStep: $yStep');
print(' - barGroups.length: ${barGroups.length}');
return Container( return Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Colors.white,
......
...@@ -85,6 +85,150 @@ ...@@ -85,6 +85,150 @@
try { mo.observe(document.documentElement, { subtree: true, childList: true, attributes: true, attributeFilter: ['src'] }); } catch (e) {} try { mo.observe(document.documentElement, { subtree: true, childList: true, attributes: true, attributeFilter: ['src'] }); } catch (e) {}
})(); })();
</script> </script>
<script>
(function () {
var textDecoder = typeof TextDecoder === 'function' ? new TextDecoder('utf-8') : null;
function headersContainJson(headersLike) {
try {
if (!headersLike) return false;
if (headersLike instanceof Headers) {
var ct = headersLike.get('content-type') || headersLike.get('Content-Type');
return typeof ct === 'string' && ct.toLowerCase().indexOf('application/json') !== -1;
}
if (Array.isArray(headersLike)) {
for (var i = 0; i < headersLike.length; i++) {
var item = headersLike[i];
if (Array.isArray(item) && item.length >= 2) {
var name = String(item[0] || '').toLowerCase();
if (name === 'content-type' && String(item[1] || '').toLowerCase().indexOf('application/json') !== -1) {
return true;
}
}
}
return false;
}
var lowerCaseKey = Object.keys(headersLike).find(function (k) {
return String(k).toLowerCase() === 'content-type';
});
if (!lowerCaseKey) return false;
var value = headersLike[lowerCaseKey];
return typeof value === 'string' && value.toLowerCase().indexOf('application/json') !== -1;
} catch (_) {
return false;
}
}
function numericArrayToUint8(arr) {
if (!Array.isArray(arr)) return null;
var len = arr.length >>> 0;
var u8 = new Uint8Array(len);
for (var i = 0; i < len; i++) {
var v = arr[i];
if (typeof v !== 'number') return null;
u8[i] = v & 255;
}
return u8;
}
function toUtf8String(body) {
if (body == null) return null;
if (typeof body === 'string') return body;
if (!textDecoder) return null;
if (body instanceof Uint8Array) return textDecoder.decode(body);
if (body instanceof ArrayBuffer) return textDecoder.decode(new Uint8Array(body));
if (ArrayBuffer.isView(body) && body.buffer instanceof ArrayBuffer) {
var offset = body.byteOffset || 0;
var length = body.byteLength != null ? body.byteLength : body.length;
return textDecoder.decode(new Uint8Array(body.buffer, offset, length));
}
var fromArray = numericArrayToUint8(body);
if (fromArray) return textDecoder.decode(fromArray);
return null;
}
function cloneInitWithNewBody(init, newBody) {
if (!init) return { body: newBody };
var cloned = Object.assign({}, init);
cloned.body = newBody;
return cloned;
}
if (typeof window.fetch === 'function') {
var originalFetch = window.fetch;
window.fetch = function patchedFetch(input, init) {
try {
var candidateHeaders = init && init.headers;
var candidateBody = init && init.body;
if (!candidateBody && input && typeof input === 'object') {
try {
candidateHeaders = candidateHeaders || (input.headers instanceof Headers ? input.headers : null);
} catch (_) {}
}
if (candidateBody && headersContainJson(candidateHeaders)) {
var converted = toUtf8String(candidateBody);
if (converted != null) {
init = cloneInitWithNewBody(init, converted);
}
}
} catch (_) {}
return originalFetch.call(this, input, init);
};
}
if (typeof window.Request === 'function') {
var OriginalRequest = window.Request;
window.Request = function PatchedRequest(input, init) {
if (init && init.body && headersContainJson(init.headers)) {
var converted = toUtf8String(init.body);
if (converted != null) {
init = cloneInitWithNewBody(init, converted);
}
}
var request = new OriginalRequest(input, init);
return request;
};
window.Request.prototype = OriginalRequest.prototype;
}
if (typeof XMLHttpRequest !== 'undefined') {
var originalOpen = XMLHttpRequest.prototype.open;
var originalSend = XMLHttpRequest.prototype.send;
var originalSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader;
XMLHttpRequest.prototype.open = function patchedOpen() {
this.__jsonHeaders = {};
return originalOpen.apply(this, arguments);
};
XMLHttpRequest.prototype.setRequestHeader = function patchedSetRequestHeader(header, value) {
if (header) {
this.__jsonHeaders[header.toLowerCase()] = value;
}
return originalSetRequestHeader.apply(this, arguments);
};
XMLHttpRequest.prototype.send = function patchedSend(body) {
try {
var ct = this.__jsonHeaders && this.__jsonHeaders['content-type'];
if ((!ct || typeof ct !== 'string') && this.__jsonHeaders) {
var alt = Object.keys(this.__jsonHeaders).find(function (k) { return k.toLowerCase() === 'content-type'; });
if (alt) ct = this.__jsonHeaders[alt];
}
if (ct && typeof ct === 'string' && ct.toLowerCase().indexOf('application/json') !== -1 && body) {
var converted = toUtf8String(body);
if (converted != null) {
body = converted;
}
}
} catch (_) {}
return originalSend.call(this, body);
};
}
})();
</script>
</head> </head>
<body> <body>
<script src="flutter_bootstrap.js" async></script> <script src="flutter_bootstrap.js" async></script>
......
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