1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-21 12:34:51 +01:00
git-touch-android-ios-app/lib/screens/gitlab_blob.dart
2020-01-30 14:51:22 +08:00

46 lines
1.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:git_touch/models/auth.dart';
import 'package:git_touch/models/gitlab.dart';
import 'package:git_touch/models/theme.dart';
import 'package:git_touch/scaffolds/refresh_stateful.dart';
import 'package:git_touch/utils/utils.dart';
import 'package:git_touch/widgets/action_entry.dart';
import 'package:git_touch/widgets/app_bar_title.dart';
import 'package:git_touch/widgets/blob_view.dart';
import 'package:provider/provider.dart';
final gitlabBlobRouter = RouterScreen(
'/gitlab/projects/:id/blob',
(context, params) => GitlabBlobScreen(params['id'].first.toInt,
path: params['path']?.first?.urldecode));
class GitlabBlobScreen extends StatelessWidget {
final int id;
final String path;
GitlabBlobScreen(this.id, {this.path});
@override
Widget build(BuildContext context) {
return RefreshStatefulScaffold<GitlabBlob>(
title: AppBarTitle(path ?? ''),
fetchData: () async {
final encodedPath = Uri.encodeComponent(path);
final res = await Provider.of<AuthModel>(context).fetchGitlab(
'/projects/$id/repository/files/$encodedPath?ref=master'); // TODO:
return GitlabBlob.fromJson(res);
},
action: ActionEntry(
iconData: Icons.settings,
onTap: () {
final theme = Provider.of<ThemeModel>(context);
theme.push(context, '/choose-code-theme');
},
),
bodyBuilder: (data, _) {
return BlobView(path, base64Text: data.content);
},
);
}
}