Line data Source code
1 : import 'package:amadeus_proto/api/utils/api_error.dart';
2 : import 'package:flutter/foundation.dart';
3 : import 'package:flutter/material.dart';
4 : import 'package:flutter/widgets.dart';
5 :
6 : /// Widget to display [ApiError]
7 : ///
8 : /// - [apiError] the error to display **(in debug mode only)**
9 : /// - [errorMessage] the error message to display **(in release mode only)**, if not provided,
10 : /// the message will be `"Une erreur est survenue"`
11 : ///
12 : /// In release mode, this widget will **only display [errorMessage]**.
13 : /// In debug mode, this widget will the status code and the error message contained
14 : /// in the [apiError] in a [Column]. If the error message of [apiError] is null,
15 : /// the message will be `"Pas d'informations supplémentaires"`
16 : class ApiErrorDisplayer extends StatelessWidget {
17 2 : const ApiErrorDisplayer({super.key, required this.apiError, this.errorMessage});
18 :
19 : final ApiError apiError;
20 : final String? errorMessage;
21 :
22 2 : @override
23 : Widget build(BuildContext context) {
24 : Widget child;
25 : if (const bool.fromEnvironment("release") || kReleaseMode) {
26 2 : child = Text(errorMessage ?? "Une erreur est survenue");
27 : } else {
28 1 : child = Column(
29 1 : children: [
30 1 : Text(
31 : style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
32 3 : apiError.httpErrorCode.toString(),
33 : ),
34 3 : Text(apiError.message ?? "Pas d'informations supplémentaires"),
35 : ],
36 : );
37 : }
38 2 : return Center(child: child);
39 : }
40 : }
|