1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-24 14:51:28 +01:00
git-touch-android-ios-app/lib/screens/gitlab_blob.dart

38 lines
1.2 KiB
Dart
Raw Normal View History

2019-12-11 16:58:25 +01:00
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:git_touch/models/auth.dart';
import 'package:git_touch/models/gitlab.dart';
import 'package:git_touch/scaffolds/refresh_stateful.dart';
2019-12-14 17:08:12 +01:00
import 'package:git_touch/utils/utils.dart';
2019-12-11 16:58:25 +01:00
import 'package:git_touch/widgets/app_bar_title.dart';
import 'package:git_touch/widgets/blob_view.dart';
import 'package:provider/provider.dart';
2019-12-14 17:08:12 +01:00
final gitlabBlobRouter = RouterScreen(
2020-01-01 09:51:10 +01:00
'/gitlab/projects/:id/tree',
2019-12-14 17:08:12 +01:00
(context, params) => GitlabBlobScreen(params['id'].first.toInt,
path: params['path']?.first?.urldecode));
2019-12-11 16:58:25 +01:00
class GitlabBlobScreen extends StatelessWidget {
final int id;
final String path;
2019-12-14 17:08:12 +01:00
GitlabBlobScreen(this.id, {this.path});
2019-12-11 16:58:25 +01:00
@override
Widget build(BuildContext context) {
return RefreshStatefulScaffold<GitlabBlob>(
title: AppBarTitle(path),
fetchData: () async {
2019-12-11 17:06:42 +01:00
final encodedPath = Uri.encodeComponent(path);
2019-12-11 16:58:25 +01:00
final res = await Provider.of<AuthModel>(context).fetchGitlab(
2019-12-11 17:06:42 +01:00
'/projects/$id/repository/files/$encodedPath?ref=master'); // TODO:
2019-12-11 16:58:25 +01:00
return GitlabBlob.fromJson(res);
},
bodyBuilder: (data, _) {
return BlobView(path, utf8.decode(base64.decode(data.content)));
},
);
}
}