flutter_dashboard/lib/services/github_service.dart
jdysya bfedef58f4 feat(platform): 添加 GitHub 平台支持
- 在 HomeScreen 中添加 GitHub 卡片组件
- 在 SettingsScreen 中添加 GitHub 设置选项
- 在 AuthService 中添加 GitHub 用户名和 token 的存储和读取逻辑
- 删除未使用的 TimeUtils 类
2025-06-09 20:39:11 +08:00

25 lines
765 B
Dart

import 'dart:convert';
import 'package:http/http.dart' as http;
import '../models/github_event.dart';
class GithubService {
static const String _baseUrl = 'https://api.github.com';
Future<List<GithubEvent>> getUserEvents(String username, String token) async {
final response = await http.get(
Uri.parse('$_baseUrl/users/$username/events'),
headers: {
'Authorization': 'Bearer $token',
'Accept': 'application/vnd.github.v3+json',
},
);
if (response.statusCode == 200) {
final List<dynamic> jsonList = json.decode(response.body);
return jsonList.map((json) => GithubEvent.fromJson(json)).toList();
} else {
throw Exception('Failed to load GitHub events: ${response.statusCode}');
}
}
}