added frontend
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fotodocumentation/l10n/app_localizations.dart';
|
||||
import 'package:fotodocumentation/controller/base_controller.dart';
|
||||
|
||||
class GeneralErrorWidget extends StatelessWidget {
|
||||
final String error;
|
||||
final Function()? reload;
|
||||
final int? statusCode;
|
||||
|
||||
const GeneralErrorWidget({super.key, required this.error, this.reload, this.statusCode});
|
||||
|
||||
factory GeneralErrorWidget.fromServerError(ServerError serverError, {Function()? reload}) {
|
||||
return GeneralErrorWidget(error: "", reload: reload, statusCode: serverError.statusCode);
|
||||
}
|
||||
|
||||
factory GeneralErrorWidget.fromSnapshot(AsyncSnapshot snapshot, {Function()? reload}) {
|
||||
var error = snapshot.error;
|
||||
if (error is ServerError) {
|
||||
return GeneralErrorWidget.fromServerError(error, reload: () => reload);
|
||||
}
|
||||
return GeneralErrorWidget(error: snapshot.error.toString(), reload: () => reload);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final localizations = AppLocalizations.of(context)!;
|
||||
final String errorMessage = statusCode != null
|
||||
? localizations.errorWidgetStatusCode(statusCode!)
|
||||
: localizations.errorWidget(error);
|
||||
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.error_outline, size: 60, color: Colors.red[300]),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 16),
|
||||
child: Text(
|
||||
errorMessage,
|
||||
style: TextStyle(color: Colors.red[700]),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (reload != null) ...[
|
||||
ElevatedButton(
|
||||
onPressed: reload,
|
||||
child: Text(localizations.errorWidgetRetryButton),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fotodocumentation/l10n/app_localizations.dart';
|
||||
import 'package:fotodocumentation/pages/ui_utils/general_style.dart';
|
||||
import 'package:fotodocumentation/utils/di_container.dart';
|
||||
|
||||
typedef SubmitCallback = void Function();
|
||||
|
||||
class GeneralSubmitWidget extends StatelessWidget {
|
||||
GeneralStyle get _generalStyle => DiContainer.get();
|
||||
|
||||
final SubmitCallback onSelect;
|
||||
final String? title;
|
||||
|
||||
const GeneralSubmitWidget({super.key, required this.onSelect, this.title});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String text = title ?? AppLocalizations.of(context)!.submitWidget;
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
ElevatedButton(
|
||||
key: Key("SubmitWidgetButton"),
|
||||
style: _generalStyle.elevatedButtonStyle,
|
||||
onPressed: onSelect,
|
||||
child: Text(text),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class PageHeaderWidget extends StatelessWidget {
|
||||
final IconData iconData;
|
||||
final String text;
|
||||
final String subText;
|
||||
final Color? iconColor;
|
||||
|
||||
const PageHeaderWidget({super.key, this.iconData = Icons.business, required this.text, this.subText = "", this.iconColor});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final color = iconColor ?? Theme.of(context).colorScheme.primary;
|
||||
return Card(
|
||||
elevation: 2,
|
||||
margin: EdgeInsets.zero,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
side: BorderSide(
|
||||
color: Colors.grey[300]!,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withAlpha(51),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(
|
||||
iconData,
|
||||
size: 32,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Text(
|
||||
text,
|
||||
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (subText.isNotEmpty) ...[
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
subText,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fotodocumentation/l10n/app_localizations.dart';
|
||||
|
||||
class SearchBarCardWidget extends StatefulWidget {
|
||||
final TextEditingController searchController;
|
||||
final Function(String) onSearch;
|
||||
const SearchBarCardWidget({super.key, required this.searchController, required this.onSearch});
|
||||
|
||||
@override
|
||||
State<SearchBarCardWidget> createState() => _SearchBarCardWidgetState();
|
||||
}
|
||||
|
||||
class _SearchBarCardWidgetState extends State<SearchBarCardWidget> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
elevation: 2,
|
||||
margin: EdgeInsets.zero,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
side: BorderSide(
|
||||
color: Colors.grey[300]!,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
key: Key("Search_text_field"),
|
||||
controller: widget.searchController,
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
decoration: InputDecoration(
|
||||
hintText: AppLocalizations.of(context)!.searchTFHint,
|
||||
border: InputBorder.none,
|
||||
prefixIcon: const Icon(Icons.search, size: 28),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
isDense: true,
|
||||
suffixIcon: InkWell(
|
||||
key: Key("Search_text_clear_button"),
|
||||
onTap: () => _actionClear(),
|
||||
child: const Icon(
|
||||
Icons.close,
|
||||
color: Colors.black,
|
||||
),
|
||||
)
|
||||
),
|
||||
onSubmitted: (_) => _actionSubmit(),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
ElevatedButton.icon(
|
||||
key: Key("Search_text_button"),
|
||||
onPressed: _actionSubmit,
|
||||
icon: const Icon(Icons.search, size: 18),
|
||||
label: Text(AppLocalizations.of(context)!.searchButtonLabel),
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _actionSubmit() {
|
||||
widget.onSearch(widget.searchController.text);
|
||||
}
|
||||
|
||||
void _actionClear() {
|
||||
widget.searchController.text = "";
|
||||
widget.onSearch(widget.searchController.text);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fotodocumentation/l10n/app_localizations.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class TextInputWidget extends StatelessWidget {
|
||||
final String labelText;
|
||||
final bool required;
|
||||
final bool obscureText;
|
||||
final bool readOnly;
|
||||
final Function? onTap;
|
||||
const TextInputWidget({super.key, required this.labelText, this.required = false, this.obscureText = false, this.readOnly = false, this.onTap});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<TextEditingController>(builder: (context, controller, child) {
|
||||
return TextFormField(
|
||||
readOnly: readOnly,
|
||||
obscureText: obscureText,
|
||||
controller: controller,
|
||||
decoration: InputDecoration(
|
||||
border: const UnderlineInputBorder(),
|
||||
labelText: labelText,
|
||||
),
|
||||
validator: (String? value) => required && (value == null || value.isEmpty) ? AppLocalizations.of(context)!.textInputWidgetValidatorText : null,
|
||||
onTap: () => onTap?.call(),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class TextMultiInputWidget extends StatelessWidget {
|
||||
final String labelText;
|
||||
final bool required;
|
||||
final bool obscureText;
|
||||
final bool readOnly;
|
||||
final Function? onTap;
|
||||
final int maxLines;
|
||||
const TextMultiInputWidget({super.key, required this.labelText, this.required = false, this.obscureText = false, this.readOnly = false, this.maxLines = 6, this.onTap});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<TextEditingController>(builder: (context, controller, child) {
|
||||
return TextFormField(
|
||||
readOnly: readOnly,
|
||||
minLines: 3, // Set this
|
||||
maxLines: maxLines, // and this
|
||||
keyboardType: TextInputType.multiline,
|
||||
obscureText: obscureText,
|
||||
controller: controller,
|
||||
decoration: InputDecoration(
|
||||
border: const UnderlineInputBorder(),
|
||||
labelText: labelText,
|
||||
),
|
||||
validator: (String? value) => required && (value == null || value.isEmpty) ? AppLocalizations.of(context)!.textInputWidgetValidatorText : null,
|
||||
onTap: () => onTap?.call(),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fotodocumentation/l10n/app_localizations.dart';
|
||||
|
||||
class WaitingWidget extends StatelessWidget {
|
||||
const WaitingWidget({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const SizedBox(
|
||||
width: 60,
|
||||
height: 60,
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 16),
|
||||
child: Text(AppLocalizations.of(context)!.waitingWidget),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user