navigator push
This commit is contained in:
parent
327b18049b
commit
595e63c4a7
@ -1,6 +1,10 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'MyHomePage.dart';
|
import 'MyHomePage.dart';
|
||||||
|
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(MyApp());
|
runApp(MyApp());
|
||||||
}
|
}
|
||||||
@ -21,6 +25,21 @@ class LoginDemo extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _LoginDemoState extends State<LoginDemo> {
|
class _LoginDemoState extends State<LoginDemo> {
|
||||||
|
Future<void> _login() async {
|
||||||
|
var url = Uri.parse("http://localhost:8083/api/token");
|
||||||
|
String credentials = "peter93:toto";
|
||||||
|
Codec<String, String> 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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@ -81,10 +100,7 @@ class _LoginDemoState extends State<LoginDemo> {
|
|||||||
color: Colors.blue, borderRadius: BorderRadius.circular(20)),
|
color: Colors.blue, borderRadius: BorderRadius.circular(20)),
|
||||||
child: FlatButton(
|
child: FlatButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.push(
|
_login();
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (_) => MyHomePage(title: 'Flutter Demo')));
|
|
||||||
},
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
'Login',
|
'Login',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user