Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter - added ICP info & fixed API address #14

Merged
merged 5 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions flutter_project/lib/contentPage/content_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class SilverContentList extends StatefulWidget {
State<SilverContentList> createState() => _SilverContentListState();
}

const String _defaultApiHost = "api.rsdaily.com";
const String _apiBase = "/v1/";

class _SilverContentListState extends State<SilverContentList> {
static const double listPaddingMedium = 280;
static const double listPaddingSmall = 0;
Expand All @@ -44,17 +47,13 @@ class _SilverContentListState extends State<SilverContentList> {

// 异步获取json字符串
Future<String> 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) {
Expand Down
33 changes: 20 additions & 13 deletions flutter_project/lib/jsonobject/issues_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Map<String, dynamic>> 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<int, SplayTreeMap<int, SplayTreeMap<DateTime, String>>>>(
SplayTreeMap(),
(SplayTreeMap<int, SplayTreeMap<int, SplayTreeMap<DateTime, String>>> map, MapEntry<DateTime, String> 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<int, SplayTreeMap<int, SplayTreeMap<DateTime, String>>>>(
SplayTreeMap(),
(SplayTreeMap<int, SplayTreeMap<int, SplayTreeMap<DateTime, String>>> map, MapEntry<DateTime, String> 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<int, Map<int, List<String>>> toJsonObject() => daily.map<int, Map<int, List<String>>>(
Expand Down
14 changes: 12 additions & 2 deletions flutter_project/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ void main() {
runApp(MyApp());
}

const String _defaultApiHost = "api.rsdaily.com";
const String _apiBase = "/v1/";

class IssuesListProvider extends ChangeNotifier {
IssuesList? _issuesList;

Expand All @@ -30,8 +33,15 @@ class IssuesListProvider extends ChangeNotifier {
}

Future<String> _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) {
Expand Down
17 changes: 12 additions & 5 deletions flutter_project/lib/mainPage/main_page_end.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down