From 488f5fc8f01acf2d73f23155854a4559de115ae2 Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Wed, 25 Sep 2019 22:01:00 +0800 Subject: [PATCH] feat: watch repository --- lib/screens/repository.dart | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/screens/repository.dart b/lib/screens/repository.dart index af5f020..3e5a94f 100644 --- a/lib/screens/repository.dart +++ b/lib/screens/repository.dart @@ -157,7 +157,7 @@ class RepositoryScreen extends StatelessWidget { Provider.of(context).pushRoute(context, builder); }, ), - if (data != null) + if (data != null) ...[ MyAction( text: data[0]['viewerHasStarred'] ? 'Unstar' : 'Star', onPress: () async { @@ -172,7 +172,24 @@ class RepositoryScreen extends StatelessWidget { } }, ), - // TODO: watch + MyAction( + text: data[0]['viewerSubscription'] == 'SUBSCRIBED' + ? 'Unwatch' + : 'Watch', + onPress: () async { + if (data[0]['viewerSubscription'] == 'SUBSCRIBED') { + await Provider.of(context) + .deleteWithCredentials( + '/repos/$owner/$name/subscription'); + data[0]['viewerSubscription'] = 'UNSUBSCRIBED'; + } else { + Provider.of(context) + .putWithCredentials('/repos/$owner/$name/subscription'); + data[0]['viewerSubscription'] = 'SUBSCRIBED'; + } + }, + ), + ], MyAction( text: 'Share', onPress: () {