2019-02-07 07:35:19 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
import '../providers/settings.dart';
|
2019-02-08 12:34:07 +01:00
|
|
|
import '../scaffolds/simple.dart';
|
2019-02-09 11:20:14 +01:00
|
|
|
import '../utils/constants.dart';
|
2019-02-08 12:34:07 +01:00
|
|
|
import '../widgets/link.dart';
|
2019-02-10 06:17:25 +01:00
|
|
|
import '../widgets/loading.dart';
|
2019-02-21 14:21:16 +01:00
|
|
|
import '../models/account.dart';
|
2019-03-09 10:03:33 +01:00
|
|
|
import '../widgets/avatar.dart';
|
|
|
|
// import 'login_gitlab.dart';
|
2019-02-07 07:35:19 +01:00
|
|
|
|
|
|
|
class LoginScreen extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_LoginScreenState createState() => _LoginScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _LoginScreenState extends State<LoginScreen> {
|
2019-02-21 15:36:19 +01:00
|
|
|
Widget _buildAccountItem(AccountModel account) {
|
2019-02-21 14:21:16 +01:00
|
|
|
var settings = SettingsProvider.of(context);
|
|
|
|
|
|
|
|
return Link(
|
|
|
|
onTap: () {
|
|
|
|
// Navigator.of(context).pop();
|
2019-02-21 15:36:19 +01:00
|
|
|
settings.setActiveAccount(
|
|
|
|
account.platform, account.domain, account.login);
|
2019-02-21 14:21:16 +01:00
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.all(10),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border(bottom: BorderSide(color: Colors.black12)),
|
|
|
|
),
|
|
|
|
child: Row(children: <Widget>[
|
2019-03-09 10:03:33 +01:00
|
|
|
Avatar(url: account.avatarUrl, size: 24),
|
2019-02-21 14:21:16 +01:00
|
|
|
Padding(padding: EdgeInsets.only(left: 10)),
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
2019-02-21 15:36:19 +01:00
|
|
|
Text(account.login, style: TextStyle(fontSize: 20)),
|
2019-02-21 14:21:16 +01:00
|
|
|
Padding(padding: EdgeInsets.only(top: 6)),
|
2019-02-21 15:36:19 +01:00
|
|
|
Text(account.domain)
|
2019-02-21 14:21:16 +01:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2019-02-21 15:36:19 +01:00
|
|
|
(settings.activePlatform == account.platform &&
|
|
|
|
settings.activeDomain == account.domain &&
|
|
|
|
settings.activeLogin == account.login)
|
|
|
|
? Icon(Icons.check)
|
|
|
|
: Container(),
|
2019-02-21 14:21:16 +01:00
|
|
|
]),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-02-21 11:43:41 +01:00
|
|
|
Widget _buildAddItem(
|
|
|
|
{String text, Function onTap, WidgetBuilder screenBuilder}) {
|
|
|
|
return Link(
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 20),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border(bottom: BorderSide(color: Colors.black12)),
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
Icon(Icons.add),
|
|
|
|
Text(text, style: TextStyle(fontSize: 16)),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onTap: onTap,
|
|
|
|
screenBuilder: screenBuilder,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-02-07 07:35:19 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
var settings = SettingsProvider.of(context);
|
|
|
|
|
2019-02-21 15:36:19 +01:00
|
|
|
List<AccountModel> accounts = [];
|
|
|
|
settings.accountMap.forEach((platform, v0) {
|
|
|
|
v0.forEach((domain, v1) {
|
|
|
|
v1.forEach((login, v2) {
|
|
|
|
accounts.add(AccountModel(
|
|
|
|
avatarUrl: v2.avatarUrl,
|
|
|
|
token: v2.token,
|
|
|
|
platform: platform,
|
|
|
|
domain: domain,
|
|
|
|
login: login,
|
|
|
|
));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-08 12:34:07 +01:00
|
|
|
return SimpleScaffold(
|
2019-02-08 13:52:10 +01:00
|
|
|
title: Text('Select account'),
|
2019-02-08 12:34:07 +01:00
|
|
|
bodyBuilder: () {
|
2019-02-10 06:17:25 +01:00
|
|
|
if (settings.loading) {
|
|
|
|
return Center(child: Loading());
|
|
|
|
}
|
|
|
|
|
2019-02-08 12:34:07 +01:00
|
|
|
return Container(
|
2019-02-08 03:48:25 +01:00
|
|
|
child: Column(
|
2019-02-21 14:21:16 +01:00
|
|
|
children: settings.githubAccountMap.entries
|
2019-02-21 15:36:19 +01:00
|
|
|
.map<Widget>((entry) => _buildAccountItem(AccountModel(
|
|
|
|
avatarUrl: entry.value.avatarUrl,
|
|
|
|
token: entry.value.token,
|
|
|
|
platform: PlatformType.github,
|
|
|
|
domain: 'https://github.com',
|
|
|
|
login: entry.key)))
|
2019-02-21 14:21:16 +01:00
|
|
|
.toList()
|
2019-02-21 15:36:19 +01:00
|
|
|
..addAll(accounts.map(_buildAccountItem))
|
2019-02-21 14:21:16 +01:00
|
|
|
..addAll([
|
|
|
|
_buildAddItem(
|
|
|
|
text: 'GitHub Account',
|
|
|
|
onTap: () {
|
|
|
|
var state = settings.generateRandomString();
|
|
|
|
launch(
|
|
|
|
'https://github.com/login/oauth/authorize?client_id=$clientId&redirect_uri=gittouch://login&scope=user%20repo&state=$state',
|
|
|
|
);
|
|
|
|
},
|
2019-02-08 12:34:07 +01:00
|
|
|
),
|
2019-03-02 09:42:51 +01:00
|
|
|
// _buildAddItem(
|
|
|
|
// text: 'GitLab Account',
|
|
|
|
// screenBuilder: (_) => LoginGitlabScreen(),
|
|
|
|
// )
|
2019-02-08 12:34:07 +01:00
|
|
|
]),
|
2019-02-08 03:48:25 +01:00
|
|
|
),
|
2019-02-08 12:34:07 +01:00
|
|
|
);
|
|
|
|
},
|
2019-02-07 07:35:19 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|