mirror of
https://github.com/git-touch/git-touch
synced 2025-02-20 13:30:38 +01:00
feat: gitlab user screen
This commit is contained in:
parent
810e1eb4de
commit
c6c5465ad3
100
lib/main.dart
100
lib/main.dart
@ -3,6 +3,8 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:git_touch/models/code.dart';
|
||||
import 'package:git_touch/models/auth.dart';
|
||||
import 'package:git_touch/models/theme.dart';
|
||||
import 'package:git_touch/screens/gitlab/todos.dart';
|
||||
import 'package:git_touch/screens/gitlab/user.dart';
|
||||
import 'package:git_touch/screens/issues.dart';
|
||||
import 'package:git_touch/screens/notification.dart';
|
||||
import 'package:git_touch/screens/repository.dart';
|
||||
@ -60,30 +62,45 @@ class _HomeState extends State<Home> {
|
||||
}
|
||||
|
||||
List<BottomNavigationBarItem> get _navigationItems {
|
||||
return [
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.rss_feed),
|
||||
title: Text('News'),
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: _buildNotificationIcon(context, false),
|
||||
activeIcon: _buildNotificationIcon(context, true),
|
||||
title: Text('Notification'),
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.trending_up),
|
||||
title: Text('Trending'),
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.search),
|
||||
title: Text('Search'),
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.person_outline),
|
||||
activeIcon: Icon(Icons.person),
|
||||
title: Text('Me'),
|
||||
),
|
||||
];
|
||||
switch (Provider.of<AuthModel>(context).activeAccount.platform) {
|
||||
case PlatformType.github:
|
||||
return [
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.rss_feed),
|
||||
title: Text('News'),
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: _buildNotificationIcon(context, false),
|
||||
activeIcon: _buildNotificationIcon(context, true),
|
||||
title: Text('Notification'),
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.trending_up),
|
||||
title: Text('Trending'),
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.search),
|
||||
title: Text('Search'),
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.person_outline),
|
||||
activeIcon: Icon(Icons.person),
|
||||
title: Text('Me'),
|
||||
),
|
||||
];
|
||||
case PlatformType.gitlab:
|
||||
return [
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.timeline),
|
||||
title: Text('Todos'),
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.person_outline),
|
||||
activeIcon: Icon(Icons.person),
|
||||
title: Text('Me'),
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
_buildScreen(int index) {
|
||||
@ -96,17 +113,30 @@ class _HomeState extends State<Home> {
|
||||
// return TrendingScreen();
|
||||
// return RepoScreen('flutter', 'flutter');
|
||||
// return Image.asset('images/spinner.webp', width: 32, height: 32);
|
||||
switch (index) {
|
||||
case 0:
|
||||
return NewsScreen();
|
||||
case 1:
|
||||
return NotificationScreen();
|
||||
case 2:
|
||||
return TrendingScreen();
|
||||
case 3:
|
||||
return SearchScreen();
|
||||
case 4:
|
||||
return UserScreen(null);
|
||||
switch (Provider.of<AuthModel>(context).activeAccount.platform) {
|
||||
case PlatformType.github:
|
||||
switch (index) {
|
||||
case 0:
|
||||
return NewsScreen();
|
||||
case 1:
|
||||
return NotificationScreen();
|
||||
case 2:
|
||||
return TrendingScreen();
|
||||
case 3:
|
||||
return SearchScreen();
|
||||
case 4:
|
||||
return UserScreen(null);
|
||||
}
|
||||
break;
|
||||
case PlatformType.gitlab:
|
||||
switch (index) {
|
||||
case 0:
|
||||
return GitlabTodosScreen();
|
||||
case 1:
|
||||
return GitlabUserScreen(
|
||||
Provider.of<AuthModel>(context).activeAccount.login);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
69
lib/screens/gitlab/user.dart
Normal file
69
lib/screens/gitlab/user.dart
Normal file
@ -0,0 +1,69 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:git_touch/models/auth.dart';
|
||||
import 'package:git_touch/scaffolds/refresh_stateful.dart';
|
||||
import 'package:git_touch/widgets/border_view.dart';
|
||||
import 'package:git_touch/widgets/repository_item.dart';
|
||||
import 'package:git_touch/widgets/user_item.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class GitlabUserScreen extends StatelessWidget {
|
||||
final String username;
|
||||
|
||||
GitlabUserScreen(this.username);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RefreshStatefulScaffold(
|
||||
title: Text('User'),
|
||||
fetchData: () async {
|
||||
final items = await Provider.of<AuthModel>(context)
|
||||
.fetchGitlab('/users?username=$username');
|
||||
final user = items[0];
|
||||
final projects = await Provider.of<AuthModel>(context)
|
||||
.fetchGitlab('/users/${user['id']}/projects') as List;
|
||||
final langs = await Future.wait(projects.map((p) =>
|
||||
Provider.of<AuthModel>(context)
|
||||
.fetchGitlab('/projects/${p['id']}/languages')));
|
||||
for (var i = 0; i < projects.length; i++) {
|
||||
projects[i]['language'] = langs[i];
|
||||
}
|
||||
return [user, projects];
|
||||
},
|
||||
bodyBuilder: (payload) {
|
||||
final data = payload.data[0];
|
||||
final projects = payload.data[1] as List;
|
||||
|
||||
return Column(
|
||||
children: <Widget>[
|
||||
UserItem(
|
||||
login: data['username'],
|
||||
avatarUrl: data['avatar_url'],
|
||||
name: data['name'],
|
||||
),
|
||||
BorderView(height: 10),
|
||||
Column(
|
||||
children: projects.map((project) {
|
||||
return RepositoryItem({
|
||||
'owner': {
|
||||
'__typename': 'user',
|
||||
'login': project['owner']['name'],
|
||||
'avatarUrl': project['owner']['avatar_url'],
|
||||
},
|
||||
'name': project['name'],
|
||||
'description': project['description'],
|
||||
'isPrivate': project['visibility'] == 'private',
|
||||
'isFork': false,
|
||||
'stargazers': {'totalCount': project['star_count']},
|
||||
'forks': {
|
||||
'totalCount': project['forks_count'],
|
||||
},
|
||||
'primaryLanguage': null
|
||||
});
|
||||
}).toList(),
|
||||
)
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user