2020-02-29 10:06:47 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2020-04-06 09:10:15 +02:00
|
|
|
import 'package:flutter_highlight/flutter_highlight.dart';
|
|
|
|
import 'package:flutter_highlight/theme_map.dart';
|
2020-02-29 10:06:47 +01:00
|
|
|
import 'package:git_touch/models/auth.dart';
|
2020-04-06 09:10:15 +02:00
|
|
|
import 'package:git_touch/models/code.dart';
|
2020-02-29 10:06:47 +01:00
|
|
|
import 'package:git_touch/models/gitlab.dart';
|
2020-04-06 09:10:15 +02:00
|
|
|
import 'package:git_touch/models/theme.dart';
|
2020-02-29 10:06:47 +01:00
|
|
|
import 'package:git_touch/scaffolds/refresh_stateful.dart';
|
2020-04-06 09:10:15 +02:00
|
|
|
import 'package:git_touch/utils/utils.dart';
|
2020-02-29 10:06:47 +01:00
|
|
|
import 'package:git_touch/widgets/app_bar_title.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
2021-01-05 10:25:19 +01:00
|
|
|
import '../generated/l10n.dart';
|
2020-02-29 10:06:47 +01:00
|
|
|
|
2020-04-06 09:10:15 +02:00
|
|
|
// TODO:
|
2020-02-29 10:06:47 +01:00
|
|
|
class GlCommitScreen extends StatelessWidget {
|
|
|
|
final String id;
|
|
|
|
final String sha;
|
|
|
|
GlCommitScreen(this.id, {this.sha});
|
|
|
|
|
|
|
|
Future<List<GitlabDiff>> _query(BuildContext context, [int page = 1]) async {
|
2020-10-04 14:37:23 +02:00
|
|
|
final auth = context.read<AuthModel>();
|
2020-02-29 10:06:47 +01:00
|
|
|
final res = await auth
|
|
|
|
.fetchGitlabWithPage('/projects/$id/repository/commits/$sha/diff');
|
|
|
|
return (res.data as List).map((v) => GitlabDiff.fromJson(v)).toList();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-04-06 09:10:15 +02:00
|
|
|
final codeProvider = Provider.of<CodeModel>(context);
|
|
|
|
final theme = Provider.of<ThemeModel>(context);
|
|
|
|
|
2020-02-29 10:06:47 +01:00
|
|
|
return RefreshStatefulScaffold<List<GitlabDiff>>(
|
2021-01-05 10:25:19 +01:00
|
|
|
title: AppBarTitle(S.of(context).commits),
|
2020-10-06 14:52:40 +02:00
|
|
|
fetch: () => _query(context),
|
2020-02-29 10:06:47 +01:00
|
|
|
bodyBuilder: (items, _) {
|
|
|
|
return Column(
|
2020-02-29 10:36:12 +01:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2020-02-29 10:06:47 +01:00
|
|
|
children: <Widget>[
|
2020-04-06 09:10:15 +02:00
|
|
|
for (var item in items)
|
|
|
|
SingleChildScrollView(
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
child: HighlightView(
|
|
|
|
item.diff,
|
|
|
|
language: 'diff',
|
|
|
|
theme: themeMap[theme.brightness == Brightness.dark
|
|
|
|
? codeProvider.themeDark
|
|
|
|
: codeProvider.theme],
|
|
|
|
padding: CommonStyle.padding,
|
|
|
|
textStyle: TextStyle(
|
|
|
|
fontSize: codeProvider.fontSize.toDouble(),
|
|
|
|
fontFamily: codeProvider.fontFamilyUsed),
|
|
|
|
),
|
|
|
|
),
|
2020-02-29 10:06:47 +01:00
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|