2019-12-11 16:58:25 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:git_touch/models/auth.dart';
|
|
|
|
import 'package:git_touch/models/gitlab.dart';
|
2020-01-30 07:51:22 +01:00
|
|
|
import 'package:git_touch/models/theme.dart';
|
2019-12-11 16:58:25 +01:00
|
|
|
import 'package:git_touch/scaffolds/refresh_stateful.dart';
|
2019-12-14 17:08:12 +01:00
|
|
|
import 'package:git_touch/utils/utils.dart';
|
2020-01-30 07:51:22 +01:00
|
|
|
import 'package:git_touch/widgets/action_entry.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-29 05:42:36 +01:00
|
|
|
'/gitlab/projects/:id/blob',
|
2019-12-14 17:08:12 +01:00
|
|
|
(context, params) => GitlabBlobScreen(params['id'].first.toInt,
|
2020-01-31 04:25:23 +01:00
|
|
|
path: params['path']?.first));
|
2019-12-14 17:08:12 +01:00
|
|
|
|
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>(
|
2020-01-29 05:42:36 +01:00
|
|
|
title: AppBarTitle(path ?? ''),
|
2019-12-11 16:58:25 +01:00
|
|
|
fetchData: () async {
|
|
|
|
final res = await Provider.of<AuthModel>(context).fetchGitlab(
|
2020-01-31 04:50:41 +01:00
|
|
|
'/projects/$id/repository/files/${path.urlencode}?ref=master'); // TODO:
|
2019-12-11 16:58:25 +01:00
|
|
|
return GitlabBlob.fromJson(res);
|
|
|
|
},
|
2020-01-30 07:51:22 +01:00
|
|
|
action: ActionEntry(
|
|
|
|
iconData: Icons.settings,
|
|
|
|
onTap: () {
|
|
|
|
final theme = Provider.of<ThemeModel>(context);
|
|
|
|
theme.push(context, '/choose-code-theme');
|
|
|
|
},
|
|
|
|
),
|
2019-12-11 16:58:25 +01:00
|
|
|
bodyBuilder: (data, _) {
|
2020-01-30 07:06:25 +01:00
|
|
|
return BlobView(path, base64Text: data.content);
|
2019-12-11 16:58:25 +01:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|