feat: přidat výběr z funkčních instancí

This commit is contained in:
Matyáš Caras 2022-09-12 16:49:42 +02:00
parent c6a60744b7
commit 28eba7d9ab
2 changed files with 49 additions and 37 deletions

View file

@ -179,6 +179,8 @@ class _LoginPageState extends State<LoginPage> {
TextEditingController passControl = TextEditingController(); TextEditingController passControl = TextEditingController();
TextEditingController canteenControl = TextEditingController(); TextEditingController canteenControl = TextEditingController();
bool rememberMe = false; bool rememberMe = false;
bool _showUrl = false;
String dropdownUrl = instance.first["url"] ?? "";
@override @override
void initState() { void initState() {
@ -301,12 +303,39 @@ class _LoginPageState extends State<LoginPage> {
controller: passControl, controller: passControl,
obscureText: true, obscureText: true,
), ),
TextField( const SizedBox(
autofillHints: const [AutofillHints.url], height: 10,
decoration: InputDecoration( ),
labelText: Languages.of(context)!.iCanteenUrl), DropdownButton(
keyboardType: TextInputType.url, isExpanded: true,
controller: canteenControl, value: dropdownUrl,
items: instance.map<DropdownMenuItem<String>>((e) {
return DropdownMenuItem<String>(
value: e["url"],
child: Text(e["name"]!),
);
}).toList(),
onChanged: (String? value) {
setState(() {
if (value == "") {
_showUrl = true;
} else {
_showUrl = false;
}
dropdownUrl = value!;
});
},
),
AnimatedOpacity(
opacity: _showUrl ? 1.0 : 0.0,
duration: const Duration(milliseconds: 300),
child: TextField(
autofillHints: const [AutofillHints.url],
decoration: InputDecoration(
labelText: Languages.of(context)!.iCanteenUrl),
keyboardType: TextInputType.url,
controller: canteenControl,
),
), ),
Row(mainAxisAlignment: MainAxisAlignment.center, children: [ Row(mainAxisAlignment: MainAxisAlignment.center, children: [
Switch( Switch(
@ -320,36 +349,14 @@ class _LoginPageState extends State<LoginPage> {
]), ]),
TextButton( TextButton(
onPressed: () async { onPressed: () async {
if (canteenControl.text.contains("http://")) { var canteenUrl = (dropdownUrl == "")
// kontrolujeme šifrované spojení ? canteenControl.text
var d = await showDialog<bool>( : dropdownUrl;
context: context, if (!canteenUrl.startsWith("https://") &&
builder: (c) => AlertDialog( !canteenUrl.startsWith("http://")) {
title: Text(Languages.of(context)!.warning), canteenUrl = "https://$canteenUrl";
content: SingleChildScrollView(
child: Text(
Languages.of(context)!.httpLogin)),
actions: [
TextButton(
onPressed: () =>
Navigator.pop(c, true),
child:
Text(Languages.of(context)!.yes)),
TextButton(
onPressed: () =>
Navigator.pop(c, false),
child: Text(
Languages.of(context)!.noChange))
],
));
if (!d!) return;
} }
if (!canteenControl.text.startsWith("https://") && var canteen = Canteen(canteenUrl);
!canteenControl.text.startsWith("http://")) {
canteenControl.text =
"https://${canteenControl.text}";
}
var canteen = Canteen(canteenControl.text);
try { try {
var l = await canteen.login( var l = await canteen.login(
userControl.text, passControl.text); userControl.text, passControl.text);
@ -365,8 +372,8 @@ class _LoginPageState extends State<LoginPage> {
return; return;
} }
if (rememberMe) { if (rememberMe) {
LoginManager.setDetails(userControl.text, LoginManager.setDetails(
passControl.text, canteenControl.text); userControl.text, passControl.text, canteenUrl);
} }
// souhlas // souhlas
const storage = FlutterSecureStorage(); const storage = FlutterSecureStorage();

View file

@ -90,3 +90,8 @@ DateTime casNaDate(TimeOfDay c) {
return DateTime.parse( return DateTime.parse(
"${now.year}-${(now.month < 10 ? "0" : "") + now.month.toString()}-${(now.day < 10 ? "0" : "") + now.day.toString()} ${(c.hour < 10 ? "0" : "") + c.hour.toString()}:${(c.minute < 10 ? "0" : "") + c.minute.toString()}:00"); "${now.year}-${(now.month < 10 ? "0" : "") + now.month.toString()}-${(now.day < 10 ? "0" : "") + now.day.toString()} ${(c.hour < 10 ? "0" : "") + c.hour.toString()}:${(c.minute < 10 ? "0" : "") + c.minute.toString()}:00");
} }
List<Map<String, String>> instance = [
{"name": "SŠTE Brno, Olomoucká", "url": "https://stravovani.sstebrno.cz"},
{"name": "Jiné", "url": ""}
];