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

53 lines
1.8 KiB
Dart
Raw Normal View History

2020-05-12 15:03:13 +02:00
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:git_touch/models/github.dart';
import 'package:git_touch/scaffolds/refresh_stateful.dart';
import 'package:git_touch/widgets/app_bar_title.dart';
import 'package:provider/provider.dart';
import 'package:git_touch/widgets/files_item.dart';
import 'package:git_touch/models/auth.dart';
import 'package:git_touch/widgets/action_button.dart';
import 'package:flutter_gen/gen_l10n/S.dart';
2020-05-12 15:03:13 +02:00
class GhComparisonScreen extends StatelessWidget {
final String owner;
final String name;
final String before;
final String head;
GhComparisonScreen(this.owner, this.name, this.before, this.head);
Widget build(BuildContext context) {
return RefreshStatefulScaffold(
2021-05-16 09:16:35 +02:00
title: AppBarTitle(AppLocalizations.of(context)!.files),
fetch: () async {
2021-05-16 09:16:35 +02:00
final res = await context.read<AuthModel>().ghClient!.getJSON(
2020-10-04 14:37:23 +02:00
'/repos/$owner/$name/compare/$before...$head',
2021-05-16 09:16:35 +02:00
convert: (dynamic vs) => GithubComparisonItem.fromJson(vs));
2020-05-12 15:03:13 +02:00
return res.files;
},
2021-05-16 09:16:35 +02:00
actionBuilder: (dynamic v, _) {
2020-05-12 15:03:13 +02:00
return ActionButton(
2021-05-16 09:16:35 +02:00
title: AppLocalizations.of(context)!.actions,
2020-05-12 15:03:13 +02:00
items: [
...ActionItem.getUrlActions(
'https://github.com/$owner/$name/compare/$before...$head'),
],
);
},
2021-05-16 09:16:35 +02:00
bodyBuilder: (dynamic v, _) {
2020-05-12 15:03:13 +02:00
return Wrap(
children: v
.map<Widget>((vs) => FilesItem(
filename: vs.filename,
additions: vs.additions,
deletions: vs.deletions,
status: vs.status,
2021-02-02 15:43:15 +01:00
patch: vs.patch ?? "No text to be shown here",
2020-05-12 15:03:13 +02:00
))
.toList(),
);
},
);
}
}