fixed what dartls told me to, ryszard biegaj

This commit is contained in:
doman 2023-07-29 18:27:11 +02:00
parent b8d7b51cff
commit fcbb12266b
3 changed files with 19 additions and 19 deletions

View file

@ -56,14 +56,14 @@ class _MyHomePageState extends State<MyHomePage> {
), ),
body: Center( body: Center(
child: Container( child: Container(
constraints: BoxConstraints(maxWidth: 600), constraints: const BoxConstraints(maxWidth: 600),
padding: EdgeInsets.all(10), padding: const EdgeInsets.all(10),
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
FilledButton( FilledButton(
onPressed: _login, onPressed: _login,
child: Text('Login'), child: const Text('Login'),
) )
], ],
), ),

View file

@ -5,23 +5,23 @@ import 'dart:html';
class ApiClient { class ApiClient {
final String baseUrl; final String baseUrl;
String? token = null; String? token;
String? refreshToken = null; String? refreshToken;
http.Client httpClient = http.Client(); http.Client httpClient = http.Client();
ApiClient({ ApiClient({
required this.baseUrl, required this.baseUrl,
}) { }) {
if (window.localStorage.containsKey('token')) { if (window.localStorage.containsKey('token')) {
this.token = window.localStorage['token']; token = window.localStorage['token'];
} }
if (window.localStorage.containsKey('refreshToken')) { if (window.localStorage.containsKey('refreshToken')) {
this.refreshToken = window.localStorage['refreshToken']; refreshToken = window.localStorage['refreshToken'];
} }
} }
Map<String, String> headers() { Map<String, String> headers() {
if (this.token == null) { if (token == null) {
throw Exception('Not logged in'); throw Exception('Not logged in');
} }
@ -30,8 +30,8 @@ class ApiClient {
'Accept': 'application/json', 'Accept': 'application/json',
}; };
if (this.token != null) { if (token != null) {
headers['Authorization'] = 'Bearer ${this.token}'; headers['Authorization'] = 'Bearer $token';
} }
return headers; return headers;
@ -40,7 +40,7 @@ class ApiClient {
Future<Map<String, dynamic>> get(String path) async { Future<Map<String, dynamic>> get(String path) async {
final response = await httpClient.get( final response = await httpClient.get(
Uri.parse('$baseUrl$path'), Uri.parse('$baseUrl$path'),
headers: this.headers(), headers: headers(),
); );
return jsonDecode(response.body); return jsonDecode(response.body);
} }
@ -49,7 +49,7 @@ class ApiClient {
final response = await httpClient.post( final response = await httpClient.post(
Uri.parse('$baseUrl$path'), Uri.parse('$baseUrl$path'),
body: jsonEncode(body), body: jsonEncode(body),
headers: this.headers(), headers: headers(),
); );
return jsonDecode(response.body); return jsonDecode(response.body);
} }
@ -58,7 +58,7 @@ class ApiClient {
Future<Map<String, dynamic>> delete(String path) async { Future<Map<String, dynamic>> delete(String path) async {
final response = await httpClient.delete( final response = await httpClient.delete(
Uri.parse('$baseUrl$path'), Uri.parse('$baseUrl$path'),
headers: this.headers(), headers: headers(),
); );
return jsonDecode(response.body); return jsonDecode(response.body);
} }
@ -67,7 +67,7 @@ class ApiClient {
final response = await httpClient.patch( final response = await httpClient.patch(
Uri.parse('$baseUrl$path'), Uri.parse('$baseUrl$path'),
body: jsonEncode(body), body: jsonEncode(body),
headers: this.headers(), headers: headers(),
); );
return jsonDecode(response.body); return jsonDecode(response.body);
} }

View file

@ -3,7 +3,7 @@ import 'package:fooder_web/based.dart';
class LoginScreen extends BasedScreen { class LoginScreen extends BasedScreen {
LoginScreen({super.key, required super.apiClient}); const LoginScreen({super.key, required super.apiClient});
@override @override
State<LoginScreen> createState() => _LoginScreen(); State<LoginScreen> createState() => _LoginScreen();
@ -35,12 +35,12 @@ class _LoginScreen extends State<LoginScreen> {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary, backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text("ANALUJ"), title: const Text("ANALUJ"),
), ),
body: Center( body: Center(
child: Container( child: Container(
constraints: BoxConstraints(maxWidth: 600), constraints: const BoxConstraints(maxWidth: 600),
padding: EdgeInsets.all(10), padding: const EdgeInsets.all(10),
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
@ -59,7 +59,7 @@ class _LoginScreen extends State<LoginScreen> {
), ),
FilledButton( FilledButton(
onPressed: _login, onPressed: _login,
child: Text('Login'), child: const Text('Login'),
) )
], ],
), ),