diff --git a/flutter_project/lib/contentPage/content_list.dart b/flutter_project/lib/contentPage/content_list.dart index 201d16c..47fd29a 100644 --- a/flutter_project/lib/contentPage/content_list.dart +++ b/flutter_project/lib/contentPage/content_list.dart @@ -32,6 +32,9 @@ class SilverContentList extends StatefulWidget { State createState() => _SilverContentListState(); } +const String _defaultApiHost = "api.rsdaily.com"; +const String _apiBase = "/v1/"; + class _SilverContentListState extends State { static const double listPaddingMedium = 280; static const double listPaddingSmall = 0; @@ -44,17 +47,13 @@ class _SilverContentListState extends State { // 异步获取json字符串 Future fetchJson(BuildContext context) async { - // return DefaultAssetBundle.of(context).loadString("assets/demo.json"); + // fetch data from url api - const String apiHost = String.fromEnvironment('API_HOST', defaultValue: ''); - Uri uri = apiHost != '' - ? Uri.https(apiHost, '/api/daily', { - 'yy': widget.year, - 'mm': widget.month, - 'dd': widget.day, - }) - : Uri.parse('/api/daily?yy=${widget.year}&mm=${widget.month}&dd=${widget.day}'); + const String apiHost = String.fromEnvironment('API_HOST', defaultValue: _defaultApiHost); + const String apiDailyPath = "daily/get"; + Uri uri = Uri.https(apiHost, "$_apiBase$apiDailyPath/${widget.year}/${widget.month}/${widget.day}"); + try { final response = await http.get(uri); if (response.statusCode == 200) { diff --git a/flutter_project/lib/jsonobject/issues_list.dart b/flutter_project/lib/jsonobject/issues_list.dart index 7b04add..ae913fb 100644 --- a/flutter_project/lib/jsonobject/issues_list.dart +++ b/flutter_project/lib/jsonobject/issues_list.dart @@ -22,19 +22,26 @@ class IssuesList { late final dailyFlattened = memo0(() => daily.values.expand((e) => e.values).expand((e) => e.entries).toList()); factory IssuesList.fromJson(List> jsonObject) => IssuesList( - daily: (jsonObject.map((e) => MapEntry(DateFormat("yyyy-MM-dd").parse(e["date"]!), e["title"]! as String)).toList() - ..sort((a, b) => a.key.compareTo(b.key))) - .fold>>>( - SplayTreeMap(), - (SplayTreeMap>> map, MapEntry item) { - final year = item.key.year; - final month = item.key.month; - map.putIfAbsent(year, () => SplayTreeMap()); - map[year]!.putIfAbsent(month, () => SplayTreeMap()); - map[year]![month]!.putIfAbsent(item.key, () => item.value); - return map; - }, - ), + daily: ( + jsonObject.map( + (e) => MapEntry( + DateFormat("yyyy-MM-dd").parse(e["date"]!), + e["title"]! as String, + ), + ) + .toList() + ..sort((a, b) => a.key.compareTo(b.key))) + .fold>>>( + SplayTreeMap(), + (SplayTreeMap>> map, MapEntry item) { + final year = item.key.year; + final month = item.key.month; + map.putIfAbsent(year, () => SplayTreeMap()); + map[year]!.putIfAbsent(month, () => SplayTreeMap()); + map[year]![month]!.putIfAbsent(item.key, () => item.value); + return map; + }, + ), ); // Map>> toJsonObject() => daily.map>>( diff --git a/flutter_project/lib/main.dart b/flutter_project/lib/main.dart index 793045c..2094649 100644 --- a/flutter_project/lib/main.dart +++ b/flutter_project/lib/main.dart @@ -18,6 +18,9 @@ void main() { runApp(MyApp()); } +const String _defaultApiHost = "api.rsdaily.com"; +const String _apiBase = "/v1/"; + class IssuesListProvider extends ChangeNotifier { IssuesList? _issuesList; @@ -30,8 +33,15 @@ class IssuesListProvider extends ChangeNotifier { } Future _fetchData() async { - const String apiHost = String.fromEnvironment('API_HOST', defaultValue: ''); - Uri uri = apiHost != '' ? Uri.https(apiHost, '/api/list') : Uri.parse('/api/list'); + + const String apiHost = String.fromEnvironment('API_HOST', defaultValue: _defaultApiHost); + const String apiListPath = "daily/query"; + + Uri uri = Uri.https(apiHost, _apiBase + apiListPath, { + 'start_date': '2024-05-01', + 'end_date': DateFormat("yyyy-MM-dd").format(DateTime.now()), + }); + try { final response = await http.get(uri); if (response.statusCode == 200) { diff --git a/flutter_project/lib/mainPage/main_page_end.dart b/flutter_project/lib/mainPage/main_page_end.dart index 8f5e818..35c982a 100644 --- a/flutter_project/lib/mainPage/main_page_end.dart +++ b/flutter_project/lib/mainPage/main_page_end.dart @@ -157,11 +157,18 @@ class MainPageEnd extends StatelessWidget { left: 0, right: 0, bottom: 0.015 * height, - child: Text( - "非 MINECRAFT 官方产品服务。未经 MOJANG 或 MICROSOFT 批准,也不与 MOJANG 或 MICROSOFT 关联", - textAlign: TextAlign.center, - style: textStyles.zh_p.copyWith(color: RDColors.white.onBackground), - )), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + "非 MINECRAFT 官方产品服务。未经 MOJANG 或 MICROSOFT 批准,也不与 MOJANG 或 MICROSOFT 关联\n" + "ICP备案号:闽ICP备2024058720号-2", + textAlign: TextAlign.center, + style: textStyles.zh_p.copyWith(color: RDColors.white.onBackground), + ), + ], + ), + ), // Debug Reference Image // Positioned(