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-07 07:35:19 +01:00
|
|
|
import '../utils/utils.dart';
|
2019-02-08 12:34:07 +01:00
|
|
|
import '../widgets/link.dart';
|
2019-02-07 07:35:19 +01:00
|
|
|
|
|
|
|
class LoginScreen extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_LoginScreenState createState() => _LoginScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _LoginScreenState extends State<LoginScreen> {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
var settings = SettingsProvider.of(context);
|
|
|
|
|
2019-02-08 12:34:07 +01:00
|
|
|
return SimpleScaffold(
|
|
|
|
title: Text('Accounts'),
|
|
|
|
bodyBuilder: () {
|
|
|
|
return Container(
|
2019-02-08 03:48:25 +01:00
|
|
|
child: Column(
|
|
|
|
children: settings.githubAccountMap.entries.map<Widget>((entry) {
|
2019-02-08 12:34:07 +01:00
|
|
|
return Link(
|
|
|
|
beforeRedirect: () {
|
2019-02-08 03:48:25 +01:00
|
|
|
settings.setActiveAccount(entry.key);
|
|
|
|
},
|
2019-02-08 12:34:07 +01:00
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.all(10),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border(bottom: BorderSide(color: Colors.black12)),
|
|
|
|
),
|
|
|
|
child: Row(children: <Widget>[
|
|
|
|
CircleAvatar(
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
backgroundImage: NetworkImage(entry.value.avatarUrl),
|
|
|
|
radius: 24,
|
|
|
|
),
|
|
|
|
Padding(padding: EdgeInsets.only(left: 10)),
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Text(entry.key, style: TextStyle(fontSize: 20)),
|
|
|
|
Padding(padding: EdgeInsets.only(top: 6)),
|
|
|
|
Text(entry.value.domain ?? 'https://github.com')
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
settings.activeLogin == entry.key
|
|
|
|
? Icon(Icons.check)
|
|
|
|
: Container(),
|
|
|
|
]),
|
|
|
|
),
|
2019-02-08 03:48:25 +01:00
|
|
|
);
|
|
|
|
}).toList()
|
|
|
|
..add(
|
2019-02-08 12:34:07 +01:00
|
|
|
Link(
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 20),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
Icon(Icons.add),
|
|
|
|
Text('Add account', style: TextStyle(fontSize: 16)),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
beforeRedirect: () {
|
2019-02-08 03:48:25 +01:00
|
|
|
var state = settings.generateRandomString();
|
|
|
|
launch(
|
|
|
|
'https://github.com/login/oauth/authorize?client_id=$clientId&redirect_uri=gittouch://login&scope=user%20repo&state=$state',
|
|
|
|
forceSafariVC: false, // this makes URL Scheme work
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2019-02-08 12:34:07 +01:00
|
|
|
);
|
|
|
|
},
|
2019-02-07 07:35:19 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|