diff --git a/lib/models/auth.dart b/lib/models/auth.dart index e93b7bb..3e29c04 100644 --- a/lib/models/auth.dart +++ b/lib/models/auth.dart @@ -287,14 +287,9 @@ class AuthModel with ChangeNotifier { return data['data']; } - Future getWithCredentials(String url, {String contentType}) async { - var headers = _headers; - if (contentType != null) { - // https://developer.github.com/v3/repos/contents/#custom-media-types - headers[HttpHeaders.contentTypeHeader] = contentType; - } + Future getWithCredentials(String url) async { final res = await http - .get(_apiPrefix + url, headers: headers) + .get(_apiPrefix + url, headers: _headers) .timeout(_timeoutDuration); final data = json.decode(res.body); if (res.statusCode >= 400) { @@ -303,6 +298,15 @@ class AuthModel with ChangeNotifier { return data; } + Future getRaw(String url) async { + final res = await http.get(_apiPrefix + url, headers: { + ..._headers, + // https://developer.github.com/v3/repos/contents/#custom-media-types + HttpHeaders.acceptHeader: 'application/vnd.github.v3.raw' + }).timeout(_timeoutDuration); + return res.body; + } + Future patchWithCredentials(String url) async { await http .patch(_apiPrefix + url, headers: _headers) diff --git a/lib/screens/repository.dart b/lib/screens/repository.dart index da00664..bb29b3a 100644 --- a/lib/screens/repository.dart +++ b/lib/screens/repository.dart @@ -1,4 +1,3 @@ -import 'dart:convert'; import 'package:filesize/filesize.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; @@ -46,12 +45,6 @@ class RepositoryScreen extends StatelessWidget { return res.data.repository; } - Future _fetchReadme(BuildContext context) async { - final data = await Provider.of(context) - .getWithCredentials('/repos/$owner/$name/readme'); - return (data['content'] as String)?.dropLineBreak?.base64ToUtf8; - } - Widget _buildLanguages(BuildContext context, GhRepoRepository repo) { final theme = Provider.of(context); return Container( @@ -106,7 +99,7 @@ class RepositoryScreen extends StatelessWidget { fetchData: () async { final rs = await Future.wait([ _query(context), - _fetchReadme(context), + Provider.of(context).getRaw('/repos/$owner/$name/readme'), ]); return Tuple2(rs[0] as GhRepoRepository, rs[1] as String); },