Tweak Twitch API & settings slider
This commit is contained in:
parent
dcff42b902
commit
e8d3804ae9
2 changed files with 46 additions and 8 deletions
|
|
@ -201,12 +201,9 @@ class Twitch {
|
|||
required String? cursor,
|
||||
}) async {
|
||||
final Uri uri;
|
||||
|
||||
if (cursor == null) {
|
||||
uri = Uri.parse('https://api.twitch.tv/helix/streams?game_id=$gameId');
|
||||
} else {
|
||||
uri = Uri.parse('https://api.twitch.tv/helix/streams?game_id=$gameId&after=$cursor');
|
||||
}
|
||||
cursor == null
|
||||
? uri = Uri.parse('https://api.twitch.tv/helix/streams?game_id=$gameId')
|
||||
: uri = Uri.parse('https://api.twitch.tv/helix/streams?game_id=$gameId&after=$cursor');
|
||||
|
||||
final response = await http.get(uri, headers: headers);
|
||||
|
||||
|
|
@ -219,6 +216,39 @@ class Twitch {
|
|||
}
|
||||
}
|
||||
|
||||
static Future<int> getTotalViewersForGame({
|
||||
required String gameId,
|
||||
required Map<String, String>? headers,
|
||||
}) async {
|
||||
String? currentCursor;
|
||||
var totalViewers = 0;
|
||||
|
||||
for (var i = 0; i < 20; i++) {
|
||||
final Uri uri;
|
||||
currentCursor == null
|
||||
? uri = Uri.parse('https://api.twitch.tv/helix/streams?first=100&game_id=$gameId')
|
||||
: uri = Uri.parse('https://api.twitch.tv/helix/streams?first=100&game_id=$gameId&after=$currentCursor');
|
||||
|
||||
final response = await http.get(uri, headers: headers);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final decoded = jsonDecode(response.body);
|
||||
|
||||
final streams = StreamsTwitch.fromJson(decoded);
|
||||
for (final stream in streams.data) {
|
||||
totalViewers += stream.viewerCount;
|
||||
}
|
||||
|
||||
currentCursor = streams.pagination['cursor'];
|
||||
if (currentCursor == null) break;
|
||||
} else {
|
||||
debugPrint('Failed to update game streams');
|
||||
}
|
||||
}
|
||||
debugPrint(totalViewers.toString());
|
||||
return totalViewers;
|
||||
}
|
||||
|
||||
/// Returns the stream info given the user login.
|
||||
static Future<StreamTwitch?> getStream({required String userLogin, required Map<String, String>? headers}) async {
|
||||
final uri = Uri.parse('https://api.twitch.tv/helix/streams?user_login=$userLogin');
|
||||
|
|
|
|||
|
|
@ -27,14 +27,22 @@ class Settings extends StatelessWidget {
|
|||
onChanged: (newValue) => settingsStore.videoEnabled = newValue,
|
||||
),
|
||||
ListTile(
|
||||
title: Text('Chat Message Limit: ${settingsStore.messageLimit}'),
|
||||
title: Row(
|
||||
children: [
|
||||
const Text('Chat Message Limit '),
|
||||
const Spacer(),
|
||||
Text(
|
||||
settingsStore.messageLimit == 1000 ? 'Unlimited' : '${settingsStore.messageLimit.toInt()}',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
subtitle: Slider.adaptive(
|
||||
value: settingsStore.messageLimit,
|
||||
onChanged: (newValue) => settingsStore.messageLimit = newValue,
|
||||
min: 200,
|
||||
max: 1000,
|
||||
divisions: 4,
|
||||
label: settingsStore.messageLimit == 1000 ? 'Unlimited' : '${settingsStore.messageLimit}',
|
||||
),
|
||||
)
|
||||
],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue