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

123 lines
3.8 KiB
Dart
Raw Normal View History

2019-02-07 07:35:19 +01:00
import 'package:flutter/material.dart';
2019-09-08 14:07:35 +02:00
import 'package:git_touch/models/settings.dart';
2019-09-25 11:06:36 +02:00
import 'package:git_touch/scaffolds/single.dart';
2019-09-11 13:59:47 +02:00
import 'package:git_touch/widgets/app_bar_title.dart';
2019-09-08 14:07:35 +02:00
import 'package:provider/provider.dart';
import '../widgets/link.dart';
import '../widgets/loading.dart';
2019-02-21 14:21:16 +01:00
import '../models/account.dart';
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> {
Widget _buildAccountItem(AccountModel account) {
2019-09-08 14:07:35 +02:00
var settings = Provider.of<SettingsModel>(context);
2019-02-21 14:21:16 +01:00
return Link(
onTap: () {
// Navigator.of(context).pop();
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>[
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>[
Text(account.login, style: TextStyle(fontSize: 20)),
2019-02-21 14:21:16 +01:00
Padding(padding: EdgeInsets.only(top: 6)),
Text(account.domain)
2019-02-21 14:21:16 +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-09-24 15:04:30 +02:00
Widget _buildAddItem({String text, Function onTap}) {
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,
);
}
2019-02-07 07:35:19 +01:00
@override
Widget build(BuildContext context) {
2019-09-08 14:07:35 +02:00
var settings = Provider.of<SettingsModel>(context);
2019-02-07 07:35: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-09-25 11:06:36 +02:00
return SingleScaffold(
2019-09-11 13:59:47 +02:00
title: AppBarTitle('Select account'),
2019-09-25 11:06:36 +02:00
body: settings.loading
2019-09-25 08:24:20 +02:00
? Center(child: Loading())
: Container(
child: Column(
children: [
...settings.githubAccountMap.entries
.map<Widget>((entry) => _buildAccountItem(AccountModel(
avatarUrl: entry.value.avatarUrl,
token: entry.value.token,
platform: PlatformType.github,
domain: 'https://github.com',
login: entry.key)))
.toList(),
...accounts.map(_buildAccountItem),
_buildAddItem(
text: 'GitHub Account',
onTap: settings.redirectToGithubOauth,
),
// _buildAddItem(
// text: 'GitLab Account',
// screenBuilder: (_) => LoginGitlabScreen(),
// )
],
2019-05-12 08:01:12 +02:00
),
2019-09-25 08:24:20 +02:00
),
2019-02-07 07:35:19 +01:00
);
}
}