fixed what dartls told me to, ryszard biegaj
This commit is contained in:
parent
b8d7b51cff
commit
fcbb12266b
3 changed files with 19 additions and 19 deletions
|
@ -56,14 +56,14 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||
),
|
||||
body: Center(
|
||||
child: Container(
|
||||
constraints: BoxConstraints(maxWidth: 600),
|
||||
padding: EdgeInsets.all(10),
|
||||
constraints: const BoxConstraints(maxWidth: 600),
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
FilledButton(
|
||||
onPressed: _login,
|
||||
child: Text('Login'),
|
||||
child: const Text('Login'),
|
||||
)
|
||||
],
|
||||
),
|
||||
|
|
|
@ -5,23 +5,23 @@ import 'dart:html';
|
|||
|
||||
class ApiClient {
|
||||
final String baseUrl;
|
||||
String? token = null;
|
||||
String? refreshToken = null;
|
||||
String? token;
|
||||
String? refreshToken;
|
||||
http.Client httpClient = http.Client();
|
||||
|
||||
ApiClient({
|
||||
required this.baseUrl,
|
||||
}) {
|
||||
if (window.localStorage.containsKey('token')) {
|
||||
this.token = window.localStorage['token'];
|
||||
token = window.localStorage['token'];
|
||||
}
|
||||
if (window.localStorage.containsKey('refreshToken')) {
|
||||
this.refreshToken = window.localStorage['refreshToken'];
|
||||
refreshToken = window.localStorage['refreshToken'];
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, String> headers() {
|
||||
if (this.token == null) {
|
||||
if (token == null) {
|
||||
throw Exception('Not logged in');
|
||||
}
|
||||
|
||||
|
@ -30,8 +30,8 @@ class ApiClient {
|
|||
'Accept': 'application/json',
|
||||
};
|
||||
|
||||
if (this.token != null) {
|
||||
headers['Authorization'] = 'Bearer ${this.token}';
|
||||
if (token != null) {
|
||||
headers['Authorization'] = 'Bearer $token';
|
||||
}
|
||||
|
||||
return headers;
|
||||
|
@ -40,7 +40,7 @@ class ApiClient {
|
|||
Future<Map<String, dynamic>> get(String path) async {
|
||||
final response = await httpClient.get(
|
||||
Uri.parse('$baseUrl$path'),
|
||||
headers: this.headers(),
|
||||
headers: headers(),
|
||||
);
|
||||
return jsonDecode(response.body);
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ class ApiClient {
|
|||
final response = await httpClient.post(
|
||||
Uri.parse('$baseUrl$path'),
|
||||
body: jsonEncode(body),
|
||||
headers: this.headers(),
|
||||
headers: headers(),
|
||||
);
|
||||
return jsonDecode(response.body);
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ class ApiClient {
|
|||
Future<Map<String, dynamic>> delete(String path) async {
|
||||
final response = await httpClient.delete(
|
||||
Uri.parse('$baseUrl$path'),
|
||||
headers: this.headers(),
|
||||
headers: headers(),
|
||||
);
|
||||
return jsonDecode(response.body);
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ class ApiClient {
|
|||
final response = await httpClient.patch(
|
||||
Uri.parse('$baseUrl$path'),
|
||||
body: jsonEncode(body),
|
||||
headers: this.headers(),
|
||||
headers: headers(),
|
||||
);
|
||||
return jsonDecode(response.body);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import 'package:fooder_web/based.dart';
|
|||
|
||||
|
||||
class LoginScreen extends BasedScreen {
|
||||
LoginScreen({super.key, required super.apiClient});
|
||||
const LoginScreen({super.key, required super.apiClient});
|
||||
|
||||
@override
|
||||
State<LoginScreen> createState() => _LoginScreen();
|
||||
|
@ -35,12 +35,12 @@ class _LoginScreen extends State<LoginScreen> {
|
|||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text("ANALUJ"),
|
||||
title: const Text("ANALUJ"),
|
||||
),
|
||||
body: Center(
|
||||
child: Container(
|
||||
constraints: BoxConstraints(maxWidth: 600),
|
||||
padding: EdgeInsets.all(10),
|
||||
constraints: const BoxConstraints(maxWidth: 600),
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
|
@ -59,7 +59,7 @@ class _LoginScreen extends State<LoginScreen> {
|
|||
),
|
||||
FilledButton(
|
||||
onPressed: _login,
|
||||
child: Text('Login'),
|
||||
child: const Text('Login'),
|
||||
)
|
||||
],
|
||||
),
|
||||
|
|
Loading…
Reference in a new issue