97 lines
3 KiB
Dart
97 lines
3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
import '../model/ApiAccess.dart';
|
|
|
|
class StatefulLoginForm extends StatefulWidget {
|
|
const StatefulLoginForm({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<StatefulLoginForm> createState() => _LoginForm();
|
|
}
|
|
|
|
class _LoginForm extends State<StatefulLoginForm> {
|
|
final Uri getTokenUri = Uri.parse(
|
|
"https://www.jetbrains.com/help/youtrack/incloud/integration-with-gitea.html#enable-youtrack-integration-gitea");
|
|
final tokenController = TextEditingController();
|
|
final instanceController = TextEditingController();
|
|
String instance = "gitea.com";
|
|
|
|
late SharedPreferences prefs;
|
|
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final media = MediaQuery.of(context).size;
|
|
|
|
return SingleChildScrollView(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
DropdownButton(
|
|
value: instance,
|
|
items: <String>['gitea.com', 'codeberg.org', 'Other']
|
|
.map<DropdownMenuItem<String>>((String value) {
|
|
return DropdownMenuItem<String>(
|
|
value: value,
|
|
child: Text(value),
|
|
);
|
|
}).toList(),
|
|
onChanged: (String? newValue) {
|
|
setState(() {
|
|
instance = newValue!;
|
|
});
|
|
instance = newValue!;
|
|
print("New Value: $newValue");
|
|
}),
|
|
if (instance == "Other")
|
|
TextField(
|
|
decoration: const InputDecoration(
|
|
labelText: "Instance URL",
|
|
),
|
|
controller: instanceController,
|
|
),
|
|
TextField(
|
|
decoration: const InputDecoration(
|
|
labelText: "Token",
|
|
),
|
|
controller: tokenController,
|
|
obscureText: true,
|
|
),
|
|
SizedBox(
|
|
width:
|
|
(media.width > 600) ? media.width * 0.25 : media.width * 0.5,
|
|
child: Container(
|
|
padding: EdgeInsetsDirectional.all(15),
|
|
child: ElevatedButton(
|
|
child: const Text("Login"),
|
|
onPressed: () => {
|
|
Navigator.pushNamed(context, "/loginstatus",
|
|
arguments: ApiAccess(
|
|
(instance == "Other")
|
|
? instanceController.text
|
|
: instance,
|
|
tokenController.text))
|
|
},
|
|
),
|
|
)),
|
|
//
|
|
TextButton(
|
|
onPressed: () => {_launchUrl(getTokenUri)},
|
|
child: Text("Need a Token? Find out how to generate one!"))
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
void _launchUrl(Uri url) async {
|
|
if (!await launchUrl(url)) throw 'Could not launch $url';
|
|
}
|