git-touch-android-ios-app/lib/screens/gl_commit.dart

58 lines
2.0 KiB
Dart
Raw Normal View History

import 'package:flutter/foundation.dart';
2022-09-17 14:35:45 +02:00
import 'package:flutter/widgets.dart';
import 'package:flutter_gen/gen_l10n/S.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:provider/provider.dart';
2020-04-06 09:10:15 +02:00
// TODO:
2020-02-29 10:06:47 +01:00
class GlCommitScreen extends StatelessWidget {
2022-09-21 18:28:21 +02:00
const GlCommitScreen(this.id, {this.sha});
2020-02-29 10:06:47 +01:00
final String id;
2021-05-16 09:16:35 +02:00
final String? sha;
2020-02-29 10:06:47 +01:00
2021-01-30 08:42:02 +01:00
Future<List<GitlabDiff>> _query(BuildContext context) 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>>(
2022-10-07 19:06:03 +02:00
title: Text(AppLocalizations.of(context)!.commits),
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(
2021-05-16 09:16:35 +02:00
item.diff!,
2020-04-06 09:10:15 +02:00
language: 'diff',
theme: themeMap[theme.brightness == Brightness.dark
? codeProvider.themeDark
2021-05-16 09:16:35 +02:00
: codeProvider.theme]!,
2020-04-06 09:10:15 +02:00
padding: CommonStyle.padding,
2021-07-20 08:33:34 +02:00
textStyle: codeProvider.fontStyle,
2020-04-06 09:10:15 +02:00
),
),
2020-02-29 10:06:47 +01:00
],
);
},
);
}
}