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';
|
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-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-09-26 16:14:14 +02:00
|
|
|
Widget _buildAccountItem(int index) {
|
|
|
|
final settings = Provider.of<SettingsModel>(context);
|
|
|
|
final account = settings.accounts[index];
|
2019-02-21 14:21:16 +01:00
|
|
|
|
|
|
|
return Link(
|
|
|
|
onTap: () {
|
|
|
|
// Navigator.of(context).pop();
|
2019-09-26 16:14:14 +02:00
|
|
|
settings.setActiveAccountIndex(index);
|
2019-02-21 14:21:16 +01:00
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.all(10),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border(bottom: BorderSide(color: Colors.black12)),
|
|
|
|
),
|
2019-09-26 16:14:14 +02:00
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Avatar(url: account.avatarUrl, size: 24),
|
|
|
|
Padding(padding: EdgeInsets.only(left: 10)),
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Text(account.login, style: TextStyle(fontSize: 20)),
|
|
|
|
Padding(padding: EdgeInsets.only(top: 6)),
|
|
|
|
Text(account.domain)
|
|
|
|
],
|
|
|
|
),
|
2019-02-21 14:21:16 +01:00
|
|
|
),
|
2019-09-26 16:14:14 +02:00
|
|
|
(index == settings.activeAccountIndex)
|
|
|
|
? 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}) {
|
2019-02-21 11:43:41 +01:00
|
|
|
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-26 16:14:14 +02:00
|
|
|
final settings = Provider.of<SettingsModel>(context);
|
2019-02-21 15:36:19 +01:00
|
|
|
|
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: [
|
2019-09-26 16:14:14 +02:00
|
|
|
...List.generate(settings.accounts.length, _buildAccountItem),
|
2019-09-25 08:24:20 +02:00
|
|
|
_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
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|