2020-04-30 18:04:24 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:git_touch/models/github.dart';
|
|
|
|
import 'package:git_touch/scaffolds/list_stateful.dart';
|
|
|
|
import 'package:git_touch/widgets/action_button.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';
|
2021-02-03 05:04:41 +01:00
|
|
|
import 'package:flutter_gen/gen_l10n/S.dart';
|
2020-04-30 18:04:24 +02:00
|
|
|
|
|
|
|
class GhFilesScreen extends StatelessWidget {
|
|
|
|
final String owner;
|
|
|
|
final String name;
|
|
|
|
final int pullNumber;
|
|
|
|
GhFilesScreen(this.owner, this.name, this.pullNumber);
|
|
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return ListStatefulScaffold<GithubFilesItem, int>(
|
2021-05-16 09:16:35 +02:00
|
|
|
title: AppBarTitle(AppLocalizations.of(context)!.files),
|
2020-04-30 18:04:24 +02:00
|
|
|
actionBuilder: () {
|
|
|
|
return ActionButton(
|
|
|
|
title: 'Actions',
|
|
|
|
items: [
|
|
|
|
...ActionItem.getUrlActions(
|
|
|
|
'https://github.com/$owner/$name/pull/$pullNumber/files'),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
2020-10-06 14:52:40 +02:00
|
|
|
fetch: (page) async {
|
2020-10-04 16:10:05 +02:00
|
|
|
page = page ?? 1;
|
|
|
|
final res = await context
|
|
|
|
.read<AuthModel>()
|
2021-05-16 09:16:35 +02:00
|
|
|
.ghClient!
|
2020-10-04 16:10:05 +02:00
|
|
|
.getJSON<List, List<GithubFilesItem>>(
|
|
|
|
'/repos/$owner/$name/pulls/$pullNumber/files?page=$page',
|
|
|
|
convert: (vs) => [for (var v in vs) GithubFilesItem.fromJson(v)],
|
|
|
|
);
|
|
|
|
return ListPayload(
|
|
|
|
cursor: page + 1,
|
|
|
|
items: res,
|
|
|
|
hasMore: res.isNotEmpty,
|
|
|
|
);
|
|
|
|
},
|
2020-04-30 18:04:24 +02:00
|
|
|
itemBuilder: (v) {
|
|
|
|
return FilesItem(
|
|
|
|
filename: v.filename,
|
|
|
|
additions: v.additions,
|
|
|
|
deletions: v.deletions,
|
|
|
|
status: v.status,
|
|
|
|
patch: v.patch,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|