Remove outdated Flutter migration documents and add new technical descriptions and profile repository implementation

- Deleted `next_steps_flutter.md` and `teknisk_beskrivning_flutter.md` files as they were outdated.
- Added new `next_steps_flutter.md` and `teknisk_beskrivning_flutter.md` files with updated migration plans and technical descriptions for the Flutter frontend.
- Implemented `profile_repository.dart` to handle profile data retrieval and updates using the API.

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Nils-Johan Gynther
2026-04-23 16:40:02 +02:00
parent 6312fd5ce1
commit a5c13a4b3c
20 changed files with 2237 additions and 117 deletions
@@ -0,0 +1,27 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../core/api/api_client.dart';
import '../../../core/api/guarded_api_call.dart';
import '../../../core/api/api_exception.dart';
final profileRepositoryProvider = Provider<ProfileRepository>((ref) {
final apiClient = ref.read(apiClientProvider);
return ProfileRepository(apiClient);
});
class ProfileRepository {
final ApiClient _apiClient;
ProfileRepository(this._apiClient);
Future<Map<String, dynamic>> getProfile() async {
return guardedApiCall(
() => _apiClient.getJson('/api/profile'),
);
}
Future<Map<String, dynamic>> updateProfile(Map<String, dynamic> profileData) async {
return guardedApiCall(
() => _apiClient.patchJson('/api/profile', profileData),
);
}
}
@@ -1,12 +1,122 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../core/api/api_error_mapper.dart';
import '../../data/profile_repository.dart';
class ProfileScreen extends StatelessWidget {
class ProfileScreen extends ConsumerStatefulWidget {
const ProfileScreen({super.key});
@override
ConsumerState<ProfileScreen> createState() => _ProfileScreenState();
}
class _ProfileScreenState extends ConsumerState<ProfileScreen> {
final _formKey = GlobalKey<FormState>();
String _username = '';
String _email = '';
bool _isLoading = true;
@override
void initState() {
super.initState();
_loadProfile();
}
Future<void> _loadProfile() async {
try {
final profile = await ref.read(profileRepositoryProvider).getProfile();
setState(() {
_username = profile['username'] ?? '';
_email = profile['email'] ?? '';
_isLoading = false;
});
} catch (e) {
_showErrorMessage(e);
setState(() {
_isLoading = false;
});
}
}
Future<void> _updateProfile() async {
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
setState(() {
_isLoading = true;
});
try {
await ref.read(profileRepositoryProvider).updateProfile({
'username': _username,
'email': _email,
});
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Profil uppdaterad!')),
);
} catch (e) {
_showErrorMessage(e);
} finally {
setState(() {
_isLoading = false;
});
}
}
}
void _showErrorMessage(dynamic error) {
final message = mapErrorToUserMessage(error, context);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(message)),
);
}
@override
Widget build(BuildContext context) {
return const Center(
child: Text('Profilsida (grundversion)'),
return Scaffold(
appBar: AppBar(
title: const Text('Användarprofil'),
),
body: _isLoading
? const Center(child: CircularProgressIndicator())
: Padding(
padding: const EdgeInsets.all(16.0),
child: Form(
key: _formKey,
child: Column(
children: <Widget>[
TextFormField(
decoration: const InputDecoration(labelText: 'Användarnamn'),
initialValue: _username,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Ange ett användarnamn';
}
return null;
},
onSaved: (value) => _username = value!,
),
TextFormField(
decoration: const InputDecoration(labelText: 'E-post'),
initialValue: _email,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Ange en e-postadress';
}
if (!RegExp(r'^[^@]+@[^@]+\.[^@]+').hasMatch(value)) {
return 'Ange en giltig e-postadress';
}
return null;
},
onSaved: (value) => _email = value!,
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: _updateProfile,
child: const Text('Spara'),
),
],
),
),
),
);
}
}
@@ -0,0 +1,367 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:intl/intl.dart' as intl;
import 'app_localizations_en.dart';
import 'app_localizations_sv.dart';
// ignore_for_file: type=lint
/// Callers can lookup localized strings with an instance of AppLocalizations
/// returned by `AppLocalizations.of(context)`.
///
/// Applications need to include `AppLocalizations.delegate()` in their app's
/// `localizationDelegates` list, and the locales they support in the app's
/// `supportedLocales` list. For example:
///
/// ```dart
/// import 'generated/app_localizations.dart';
///
/// return MaterialApp(
/// localizationsDelegates: AppLocalizations.localizationsDelegates,
/// supportedLocales: AppLocalizations.supportedLocales,
/// home: MyApplicationHome(),
/// );
/// ```
///
/// ## Update pubspec.yaml
///
/// Please make sure to update your pubspec.yaml to include the following
/// packages:
///
/// ```yaml
/// dependencies:
/// # Internationalization support.
/// flutter_localizations:
/// sdk: flutter
/// intl: any # Use the pinned version from flutter_localizations
///
/// # Rest of dependencies
/// ```
///
/// ## iOS Applications
///
/// iOS applications define key application metadata, including supported
/// locales, in an Info.plist file that is built into the application bundle.
/// To configure the locales supported by your app, youll need to edit this
/// file.
///
/// First, open your projects ios/Runner.xcworkspace Xcode workspace file.
/// Then, in the Project Navigator, open the Info.plist file under the Runner
/// projects Runner folder.
///
/// Next, select the Information Property List item, select Add Item from the
/// Editor menu, then select Localizations from the pop-up menu.
///
/// Select and expand the newly-created Localizations item then, for each
/// locale your application supports, add a new item and select the locale
/// you wish to add from the pop-up menu in the Value field. This list should
/// be consistent with the languages listed in the AppLocalizations.supportedLocales
/// property.
abstract class AppLocalizations {
AppLocalizations(String locale)
: localeName = intl.Intl.canonicalizedLocale(locale.toString());
final String localeName;
static AppLocalizations? of(BuildContext context) {
return Localizations.of<AppLocalizations>(context, AppLocalizations);
}
static const LocalizationsDelegate<AppLocalizations> delegate =
_AppLocalizationsDelegate();
/// A list of this localizations delegate along with the default localizations
/// delegates.
///
/// Returns a list of localizations delegates containing this delegate along with
/// GlobalMaterialLocalizations.delegate, GlobalCupertinoLocalizations.delegate,
/// and GlobalWidgetsLocalizations.delegate.
///
/// Additional delegates can be added by appending to this list in
/// MaterialApp. This list does not have to be used at all if a custom list
/// of delegates is preferred or required.
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates =
<LocalizationsDelegate<dynamic>>[
delegate,
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
];
/// A list of this localizations delegate's supported locales.
static const List<Locale> supportedLocales = <Locale>[
Locale('en'),
Locale('sv')
];
/// No description provided for @appTitle.
///
/// In en, this message translates to:
/// **'Recipe App'**
String get appTitle;
/// No description provided for @retryAction.
///
/// In en, this message translates to:
/// **'Retry'**
String get retryAction;
/// No description provided for @mealPlanTitle.
///
/// In en, this message translates to:
/// **'Meal plan'**
String get mealPlanTitle;
/// No description provided for @mealPlanLoading.
///
/// In en, this message translates to:
/// **'Loading meal plan...'**
String get mealPlanLoading;
/// No description provided for @mealPlanWeekPrevious.
///
/// In en, this message translates to:
/// **'Previous week'**
String get mealPlanWeekPrevious;
/// No description provided for @mealPlanWeekNext.
///
/// In en, this message translates to:
/// **'Next week'**
String get mealPlanWeekNext;
/// No description provided for @mealPlanWeekCurrent.
///
/// In en, this message translates to:
/// **'Current week'**
String get mealPlanWeekCurrent;
/// No description provided for @mealPlanDayNoRecipe.
///
/// In en, this message translates to:
/// **'Nothing planned'**
String get mealPlanDayNoRecipe;
/// No description provided for @mealPlanSelectRecipe.
///
/// In en, this message translates to:
/// **'Choose recipe'**
String get mealPlanSelectRecipe;
/// No description provided for @mealPlanViewRecipe.
///
/// In en, this message translates to:
/// **'View recipe'**
String get mealPlanViewRecipe;
/// No description provided for @mealPlanServingsLabel.
///
/// In en, this message translates to:
/// **'Servings'**
String get mealPlanServingsLabel;
/// No description provided for @mealPlanResetServings.
///
/// In en, this message translates to:
/// **'Reset'**
String get mealPlanResetServings;
/// No description provided for @mealPlanSaving.
///
/// In en, this message translates to:
/// **'Saving...'**
String get mealPlanSaving;
/// No description provided for @mealPlanPlannedRecipes.
///
/// In en, this message translates to:
/// **'{count, plural, one {# recipe planned} other {# recipes planned}}'**
String mealPlanPlannedRecipes(int count);
/// No description provided for @mealPlanShoppingTitle.
///
/// In en, this message translates to:
/// **'Shopping list'**
String get mealPlanShoppingTitle;
/// No description provided for @mealPlanPickRecipeHint.
///
/// In en, this message translates to:
/// **'Choose recipes above to see the combined ingredient list.'**
String get mealPlanPickRecipeHint;
/// No description provided for @mealPlanNoShoppingItems.
///
/// In en, this message translates to:
/// **'No ingredients to show for this week.'**
String get mealPlanNoShoppingItems;
/// No description provided for @mealPlanNoRecipesTitle.
///
/// In en, this message translates to:
/// **'There are no recipes to plan yet.'**
String get mealPlanNoRecipesTitle;
/// No description provided for @mealPlanNoRecipesDescription.
///
/// In en, this message translates to:
/// **'Create at least one recipe first, then add it to the meal plan.'**
String get mealPlanNoRecipesDescription;
/// No description provided for @mealPlanMissingCount.
///
/// In en, this message translates to:
/// **'{count, plural, one {# missing} other {# missing}}'**
String mealPlanMissingCount(int count);
/// No description provided for @mealPlanPartialCount.
///
/// In en, this message translates to:
/// **'{count, plural, one {# partially at home} other {# partially at home}}'**
String mealPlanPartialCount(int count);
/// No description provided for @mealPlanEnoughCount.
///
/// In en, this message translates to:
/// **'{count, plural, one {# at home} other {# at home}}'**
String mealPlanEnoughCount(int count);
/// No description provided for @mealPlanPantryCount.
///
/// In en, this message translates to:
/// **'{count, plural, one {# pantry staple} other {# pantry staples}}'**
String mealPlanPantryCount(int count);
/// No description provided for @mealPlanAllAtHome.
///
/// In en, this message translates to:
/// **'You already have everything at home.'**
String get mealPlanAllAtHome;
/// No description provided for @mealPlanStatusMissing.
///
/// In en, this message translates to:
/// **'Missing'**
String get mealPlanStatusMissing;
/// No description provided for @mealPlanStatusPartial.
///
/// In en, this message translates to:
/// **'Partially at home'**
String get mealPlanStatusPartial;
/// No description provided for @mealPlanStatusEnough.
///
/// In en, this message translates to:
/// **'At home'**
String get mealPlanStatusEnough;
/// No description provided for @mealPlanStatusPantry.
///
/// In en, this message translates to:
/// **'Pantry staple'**
String get mealPlanStatusPantry;
/// No description provided for @loginTitle.
///
/// In en, this message translates to:
/// **'Sign in'**
String get loginTitle;
/// No description provided for @usernameLabel.
///
/// In en, this message translates to:
/// **'Username'**
String get usernameLabel;
/// No description provided for @usernameRequired.
///
/// In en, this message translates to:
/// **'Enter your username.'**
String get usernameRequired;
/// No description provided for @passwordLabel.
///
/// In en, this message translates to:
/// **'Password'**
String get passwordLabel;
/// No description provided for @passwordRequired.
///
/// In en, this message translates to:
/// **'Enter your password.'**
String get passwordRequired;
/// No description provided for @loginAction.
///
/// In en, this message translates to:
/// **'Sign in'**
String get loginAction;
/// No description provided for @sessionExpiredError.
///
/// In en, this message translates to:
/// **'Your session has expired. Sign in again.'**
String get sessionExpiredError;
/// No description provided for @forbiddenError.
///
/// In en, this message translates to:
/// **'You do not have permission to use this feature.'**
String get forbiddenError;
/// No description provided for @serverError.
///
/// In en, this message translates to:
/// **'A server error occurred. Try again in a moment.'**
String get serverError;
/// No description provided for @networkError.
///
/// In en, this message translates to:
/// **'Network error. Check your connection and try again.'**
String get networkError;
/// No description provided for @unexpectedError.
///
/// In en, this message translates to:
/// **'An unexpected error occurred.'**
String get unexpectedError;
}
class _AppLocalizationsDelegate
extends LocalizationsDelegate<AppLocalizations> {
const _AppLocalizationsDelegate();
@override
Future<AppLocalizations> load(Locale locale) {
return SynchronousFuture<AppLocalizations>(lookupAppLocalizations(locale));
}
@override
bool isSupported(Locale locale) =>
<String>['en', 'sv'].contains(locale.languageCode);
@override
bool shouldReload(_AppLocalizationsDelegate old) => false;
}
AppLocalizations lookupAppLocalizations(Locale locale) {
// Lookup logic when only language code is specified.
switch (locale.languageCode) {
case 'en':
return AppLocalizationsEn();
case 'sv':
return AppLocalizationsSv();
}
throw FlutterError(
'AppLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
'an issue with the localizations generation tool. Please file an issue '
'on GitHub with a reproducible sample app and the gen-l10n configuration '
'that was used.');
}
@@ -0,0 +1,171 @@
// ignore: unused_import
import 'package:intl/intl.dart' as intl;
import 'app_localizations.dart';
// ignore_for_file: type=lint
/// The translations for English (`en`).
class AppLocalizationsEn extends AppLocalizations {
AppLocalizationsEn([String locale = 'en']) : super(locale);
@override
String get appTitle => 'Recipe App';
@override
String get retryAction => 'Retry';
@override
String get mealPlanTitle => 'Meal plan';
@override
String get mealPlanLoading => 'Loading meal plan...';
@override
String get mealPlanWeekPrevious => 'Previous week';
@override
String get mealPlanWeekNext => 'Next week';
@override
String get mealPlanWeekCurrent => 'Current week';
@override
String get mealPlanDayNoRecipe => 'Nothing planned';
@override
String get mealPlanSelectRecipe => 'Choose recipe';
@override
String get mealPlanViewRecipe => 'View recipe';
@override
String get mealPlanServingsLabel => 'Servings';
@override
String get mealPlanResetServings => 'Reset';
@override
String get mealPlanSaving => 'Saving...';
@override
String mealPlanPlannedRecipes(int count) {
String _temp0 = intl.Intl.pluralLogic(
count,
locale: localeName,
other: '# recipes planned',
one: '# recipe planned',
);
return '$_temp0';
}
@override
String get mealPlanShoppingTitle => 'Shopping list';
@override
String get mealPlanPickRecipeHint =>
'Choose recipes above to see the combined ingredient list.';
@override
String get mealPlanNoShoppingItems => 'No ingredients to show for this week.';
@override
String get mealPlanNoRecipesTitle => 'There are no recipes to plan yet.';
@override
String get mealPlanNoRecipesDescription =>
'Create at least one recipe first, then add it to the meal plan.';
@override
String mealPlanMissingCount(int count) {
String _temp0 = intl.Intl.pluralLogic(
count,
locale: localeName,
other: '# missing',
one: '# missing',
);
return '$_temp0';
}
@override
String mealPlanPartialCount(int count) {
String _temp0 = intl.Intl.pluralLogic(
count,
locale: localeName,
other: '# partially at home',
one: '# partially at home',
);
return '$_temp0';
}
@override
String mealPlanEnoughCount(int count) {
String _temp0 = intl.Intl.pluralLogic(
count,
locale: localeName,
other: '# at home',
one: '# at home',
);
return '$_temp0';
}
@override
String mealPlanPantryCount(int count) {
String _temp0 = intl.Intl.pluralLogic(
count,
locale: localeName,
other: '# pantry staples',
one: '# pantry staple',
);
return '$_temp0';
}
@override
String get mealPlanAllAtHome => 'You already have everything at home.';
@override
String get mealPlanStatusMissing => 'Missing';
@override
String get mealPlanStatusPartial => 'Partially at home';
@override
String get mealPlanStatusEnough => 'At home';
@override
String get mealPlanStatusPantry => 'Pantry staple';
@override
String get loginTitle => 'Sign in';
@override
String get usernameLabel => 'Username';
@override
String get usernameRequired => 'Enter your username.';
@override
String get passwordLabel => 'Password';
@override
String get passwordRequired => 'Enter your password.';
@override
String get loginAction => 'Sign in';
@override
String get sessionExpiredError => 'Your session has expired. Sign in again.';
@override
String get forbiddenError =>
'You do not have permission to use this feature.';
@override
String get serverError => 'A server error occurred. Try again in a moment.';
@override
String get networkError =>
'Network error. Check your connection and try again.';
@override
String get unexpectedError => 'An unexpected error occurred.';
}
@@ -0,0 +1,172 @@
// ignore: unused_import
import 'package:intl/intl.dart' as intl;
import 'app_localizations.dart';
// ignore_for_file: type=lint
/// The translations for Swedish (`sv`).
class AppLocalizationsSv extends AppLocalizations {
AppLocalizationsSv([String locale = 'sv']) : super(locale);
@override
String get appTitle => 'Recipe App';
@override
String get retryAction => 'Försök igen';
@override
String get mealPlanTitle => 'Matsedel';
@override
String get mealPlanLoading => 'Laddar matsedel...';
@override
String get mealPlanWeekPrevious => 'Förra veckan';
@override
String get mealPlanWeekNext => 'Nästa vecka';
@override
String get mealPlanWeekCurrent => 'Denna vecka';
@override
String get mealPlanDayNoRecipe => 'Inget planerat';
@override
String get mealPlanSelectRecipe => 'Välj recept';
@override
String get mealPlanViewRecipe => 'Visa recept';
@override
String get mealPlanServingsLabel => 'Portioner';
@override
String get mealPlanResetServings => 'Återställ';
@override
String get mealPlanSaving => 'Sparar...';
@override
String mealPlanPlannedRecipes(int count) {
String _temp0 = intl.Intl.pluralLogic(
count,
locale: localeName,
other: '# recept planerade',
one: '# recept planerat',
);
return '$_temp0';
}
@override
String get mealPlanShoppingTitle => 'Inköpslista';
@override
String get mealPlanPickRecipeHint =>
'Välj recept ovan för att se en samlad ingredienslista.';
@override
String get mealPlanNoShoppingItems =>
'Inga ingredienser att visa för den här veckan.';
@override
String get mealPlanNoRecipesTitle =>
'Det finns inga recept att planera ännu.';
@override
String get mealPlanNoRecipesDescription =>
'Skapa minst ett recept först, så kan du lägga det i matsedeln.';
@override
String mealPlanMissingCount(int count) {
String _temp0 = intl.Intl.pluralLogic(
count,
locale: localeName,
other: '# saknas',
one: '# saknas',
);
return '$_temp0';
}
@override
String mealPlanPartialCount(int count) {
String _temp0 = intl.Intl.pluralLogic(
count,
locale: localeName,
other: '# delvis hemma',
one: '# delvis hemma',
);
return '$_temp0';
}
@override
String mealPlanEnoughCount(int count) {
String _temp0 = intl.Intl.pluralLogic(
count,
locale: localeName,
other: '# hemma',
one: '# hemma',
);
return '$_temp0';
}
@override
String mealPlanPantryCount(int count) {
String _temp0 = intl.Intl.pluralLogic(
count,
locale: localeName,
other: '# baslager',
one: '# baslager',
);
return '$_temp0';
}
@override
String get mealPlanAllAtHome => 'Du har allt hemma.';
@override
String get mealPlanStatusMissing => 'Saknas';
@override
String get mealPlanStatusPartial => 'Delvis hemma';
@override
String get mealPlanStatusEnough => 'Finns hemma';
@override
String get mealPlanStatusPantry => 'Baslager';
@override
String get loginTitle => 'Logga in';
@override
String get usernameLabel => 'Användarnamn';
@override
String get usernameRequired => 'Ange ditt användarnamn.';
@override
String get passwordLabel => 'Lösenord';
@override
String get passwordRequired => 'Ange ditt lösenord.';
@override
String get loginAction => 'Logga in';
@override
String get sessionExpiredError => 'Din session har gått ut. Logga in igen.';
@override
String get forbiddenError => 'Du saknar behörighet för denna funktion.';
@override
String get serverError => 'Serverfel uppstod. Försök igen om en stund.';
@override
String get networkError =>
'Nätverksfel. Kontrollera anslutningen och försök igen.';
@override
String get unexpectedError => 'Ett oväntat fel uppstod.';
}