From 595e63c4a7b1325c369deddcdff2f07b3a9b02cf Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 4 Sep 2022 20:09:09 +0200 Subject: [PATCH] navigator push --- covas_mobile/lib/main.dart | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/covas_mobile/lib/main.dart b/covas_mobile/lib/main.dart index 00265ef..cba45c4 100644 --- a/covas_mobile/lib/main.dart +++ b/covas_mobile/lib/main.dart @@ -1,6 +1,10 @@ import 'package:flutter/material.dart'; import 'MyHomePage.dart'; +import 'package:http/http.dart' as http; +import 'dart:convert'; +import 'dart:io'; + void main() { runApp(MyApp()); } @@ -21,6 +25,21 @@ class LoginDemo extends StatefulWidget { } class _LoginDemoState extends State { + Future _login() async { + var url = Uri.parse("http://localhost:8083/api/token"); + String credentials = "peter93:toto"; + Codec stringToBase64 = utf8.fuse(base64); + String encoded = stringToBase64.encode(credentials); + var response = await http.get(url, headers: { + HttpHeaders.authorizationHeader: 'Basic $encoded', + }); + + if ((response.statusCode == 200) || (response.statusCode == 201)) { + Navigator.push(context, + MaterialPageRoute(builder: (_) => MyHomePage(title: 'Flutter Demo'))); + } + } + @override Widget build(BuildContext context) { return Scaffold( @@ -81,10 +100,7 @@ class _LoginDemoState extends State { color: Colors.blue, borderRadius: BorderRadius.circular(20)), child: FlatButton( onPressed: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (_) => MyHomePage(title: 'Flutter Demo'))); + _login(); }, child: Text( 'Login',