Refactor the auth provider, and move it to riverpod

This commit is contained in:
Roland Geider
2026-04-17 16:25:04 +02:00
parent 70dff579d4
commit 8ad3585ce6
38 changed files with 1838 additions and 2022 deletions

View File

@@ -22,7 +22,8 @@ import 'package:mockito/mockito.dart';
import 'package:provider/provider.dart';
import 'package:wger/l10n/generated/app_localizations.dart';
import 'package:wger/models/measurements/measurement_category.dart';
import 'package:wger/providers/auth.dart';
import 'package:wger/providers/auth_notifier.dart';
import 'package:wger/providers/auth_state.dart';
import 'package:wger/providers/body_weight_repository.dart';
import 'package:wger/providers/gallery.dart';
import 'package:wger/providers/measurement_repository.dart';
@@ -44,15 +45,20 @@ import '../test_data/nutritional_plans.dart';
import '../test_data/profile.dart';
import '../test_data/routines.dart';
class _FakeAuthNotifier extends AuthNotifier {
_FakeAuthNotifier(this._state);
final AuthState _state;
@override
Future<AuthState> build() async => _state;
}
Widget createDashboardScreen({Locale? locale}) {
locale ??= const Locale('en');
final mockGalleryProvider = MockGalleryProvider();
final mockAuthProvider = MockAuthProvider();
when(mockAuthProvider.setServerVersion()).thenAnswer((_) async {});
when(mockAuthProvider.dataInit).thenReturn(true);
final mockNutritionProvider = weight.MockNutritionPlansProvider();
when(
@@ -73,10 +79,16 @@ Widget createDashboardScreen({Locale? locale}) {
final mockUserProvider = MockUserProvider();
when(mockUserProvider.profile).thenReturn(tProfile1);
final loggedInAuth = const AuthState(
status: AuthStatus.loggedIn,
token: 'test-token',
serverUrl: 'http://localhost',
);
final container = riverpod.ProviderContainer.test(
overrides: [
bodyWeightRepositoryProvider.overrideWithValue(mockBodyWeightRepository),
measurementRepositoryProvider.overrideWithValue(mockMeasurementRepo),
authProvider.overrideWith(() => _FakeAuthNotifier(loggedInAuth)),
],
);
container.read(routinesRiverpodProvider.notifier).state = RoutinesState(
@@ -100,9 +112,6 @@ Widget createDashboardScreen({Locale? locale}) {
ChangeNotifierProvider<GalleryProvider>(
create: (context) => mockGalleryProvider,
),
ChangeNotifierProvider<AuthProvider>(
create: (context) => mockAuthProvider,
),
ChangeNotifierProvider<NutritionPlansProvider>(
create: (context) => mockNutritionProvider,

View File

@@ -39,7 +39,7 @@ Future<PowerSyncDatabase> powerSyncInstance(Ref ref) async {
await db.initialize();
final baseProvider = ref.read(wgerBaseProvider);
final currentConnector = DjangoConnector(baseUrl: baseProvider.auth.serverUrl!);
final currentConnector = DjangoConnector(baseUrl: baseProvider.serverUrl!);
db.connect(connector: currentConnector);
ref.onDispose(db.close);

View File

@@ -46,7 +46,7 @@ final class PowerSyncInstanceProvider
}
}
String _$powerSyncInstanceHash() => r'd4048d9589d6b975dfda0225c0e49af08f34edd0';
String _$powerSyncInstanceHash() => r'cc51119f46b1a2838312e5bb60cec1db8748caac';
@ProviderFor(didCompleteSync)
final didCompleteSyncProvider = DidCompleteSyncFamily._();

View File

@@ -18,7 +18,7 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart' as riverpod;
import 'package:flutter_riverpod/flutter_riverpod.dart' hide Consumer, Provider;
import 'package:logging/logging.dart';
import 'package:provider/provider.dart';
import 'package:wger/core/exceptions/http_exception.dart';
@@ -27,6 +27,8 @@ import 'package:wger/helpers/errors.dart';
import 'package:wger/helpers/shared_preferences.dart';
import 'package:wger/l10n/generated/app_localizations.dart';
import 'package:wger/providers/add_exercise.dart';
import 'package:wger/providers/auth_notifier.dart';
import 'package:wger/providers/auth_state.dart';
import 'package:wger/providers/base_provider.dart';
import 'package:wger/providers/gallery.dart';
import 'package:wger/providers/nutrition.dart';
@@ -65,7 +67,6 @@ import 'package:wger/widgets/core/log_overview.dart';
import 'package:wger/widgets/core/settings.dart';
import 'helpers/logs.dart';
import 'providers/auth.dart';
void _setupLogging() {
Logger.root.level = kDebugMode ? Level.ALL : Level.INFO;
@@ -137,124 +138,102 @@ void main() async {
};
// Application
runApp(const MainApp());
runApp(const ProviderScope(child: MainApp()));
}
class MainApp extends StatelessWidget {
class MainApp extends ConsumerWidget {
const MainApp();
Widget _getHomeScreen(AuthProvider auth) {
switch (auth.state) {
case AuthState.loggedIn:
Widget _getHomeScreen(AuthState auth) {
switch (auth.status) {
case AuthStatus.loggedIn:
return const EagerInitialization();
// return HomeTabsScreen();
case AuthState.updateRequired:
case AuthStatus.updateRequired:
return const UpdateAppScreen();
case AuthState.serverUpdateRequired:
case AuthStatus.serverUpdateRequired:
return const UpdateServerScreen();
default:
return FutureBuilder(
future: auth.tryAutoLogin(),
builder: (ctx, authResultSnapshot) =>
authResultSnapshot.connectionState == ConnectionState.waiting
? const SplashScreen()
: const AuthScreen(),
);
case AuthStatus.loggedOut:
return const AuthScreen();
}
}
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (ctx) => AuthProvider()),
ChangeNotifierProxyProvider<AuthProvider, NutritionPlansProvider>(
create: (context) => NutritionPlansProvider(
WgerBaseProvider(Provider.of(context, listen: false)),
[],
),
update: (context, auth, previous) =>
previous ?? NutritionPlansProvider(WgerBaseProvider(auth), []),
),
ChangeNotifierProxyProvider<AuthProvider, UserProvider>(
create: (context) => UserProvider(
WgerBaseProvider(Provider.of(context, listen: false)),
),
update: (context, base, previous) => previous ?? UserProvider(WgerBaseProvider(base)),
),
ChangeNotifierProxyProvider<AuthProvider, GalleryProvider>(
create: (context) => GalleryProvider(
Provider.of(context, listen: false),
[],
),
update: (context, auth, previous) => previous ?? GalleryProvider(auth, []),
),
ChangeNotifierProxyProvider<AuthProvider, AddExerciseProvider>(
create: (context) => AddExerciseProvider(
WgerBaseProvider(Provider.of(context, listen: false)),
),
update: (context, base, previous) =>
previous ?? AddExerciseProvider(WgerBaseProvider(base)),
),
],
child: Consumer<AuthProvider>(
builder: (ctx, auth, _) {
final baseInstance = WgerBaseProvider(Provider.of(ctx, listen: false));
return Consumer<UserProvider>(
builder: (ctx, user, _) => riverpod.ProviderScope(
overrides: [
wgerBaseProvider.overrideWithValue(baseInstance),
],
child: riverpod.Consumer(
builder: (rpCtx, ref, _) {
return MaterialApp(
title: 'wger',
navigatorKey: navigatorKey,
theme: wgerLightTheme,
darkTheme: wgerDarkTheme,
highContrastTheme: wgerLightThemeHc,
highContrastDarkTheme: wgerDarkThemeHc,
themeMode: user.themeMode,
home: _getHomeScreen(auth),
routes: {
DashboardScreen.routeName: (ctx) => const DashboardScreen(),
FormScreen.routeName: (ctx) => const FormScreen(),
GalleryScreen.routeName: (ctx) => const GalleryScreen(),
GymModeScreen.routeName: (ctx) => const GymModeScreen(),
HomeTabsScreen.routeName: (ctx) => HomeTabsScreen(),
MeasurementCategoriesScreen.routeName: (ctx) =>
const MeasurementCategoriesScreen(),
MeasurementEntriesScreen.routeName: (ctx) => const MeasurementEntriesScreen(),
NutritionalPlansScreen.routeName: (ctx) => const NutritionalPlansScreen(),
NutritionalDiaryScreen.routeName: (ctx) => const NutritionalDiaryScreen(),
NutritionalPlanScreen.routeName: (ctx) => const NutritionalPlanScreen(),
LogMealsScreen.routeName: (ctx) => const LogMealsScreen(),
LogMealScreen.routeName: (ctx) => const LogMealScreen(),
WeightScreen.routeName: (ctx) => const WeightScreen(),
RoutineScreen.routeName: (ctx) => const RoutineScreen(),
RoutineEditScreen.routeName: (ctx) => const RoutineEditScreen(),
WorkoutLogsScreen.routeName: (ctx) => const WorkoutLogsScreen(),
RoutineListScreen.routeName: (ctx) => const RoutineListScreen(),
ExercisesScreen.routeName: (ctx) => const ExercisesScreen(),
ExerciseDetailScreen.routeName: (ctx) => const ExerciseDetailScreen(),
AddExerciseScreen.routeName: (ctx) => const AddExerciseScreen(),
AboutPage.routeName: (ctx) => const AboutPage(),
SettingsPage.routeName: (ctx) => const SettingsPage(),
LogOverviewPage.routeName: (ctx) => const LogOverviewPage(),
ConfigurePlatesScreen.routeName: (ctx) => const ConfigurePlatesScreen(),
ConfigureDashboardWidgetsScreen.routeName: (ctx) =>
const ConfigureDashboardWidgetsScreen(),
TrophyScreen.routeName: (ctx) => const TrophyScreen(),
},
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
);
},
Widget build(BuildContext context, WidgetRef ref) {
final authAsync = ref.watch(authProvider);
return authAsync.when(
loading: () => const MaterialApp(home: SplashScreen()),
error: (error, stack) => MaterialApp(
home: Scaffold(body: Center(child: Text('$error'))),
),
data: (authState) {
final base = ref.watch(wgerBaseProvider);
return MultiProvider(
providers: [
Provider<WgerBaseProvider>.value(value: base),
ChangeNotifierProvider<NutritionPlansProvider>(
create: (_) => NutritionPlansProvider(base, []),
),
ChangeNotifierProvider<UserProvider>(
create: (_) => UserProvider(base),
),
ChangeNotifierProvider<GalleryProvider>(
create: (_) => GalleryProvider(
serverUrl: base.serverUrl,
token: base.token,
applicationVersion: base.applicationVersion,
),
),
);
},
),
ChangeNotifierProvider<AddExerciseProvider>(
create: (_) => AddExerciseProvider(base),
),
],
child: Consumer<UserProvider>(
builder: (ctx, user, _) => MaterialApp(
title: 'wger',
navigatorKey: navigatorKey,
theme: wgerLightTheme,
darkTheme: wgerDarkTheme,
highContrastTheme: wgerLightThemeHc,
highContrastDarkTheme: wgerDarkThemeHc,
themeMode: user.themeMode,
home: _getHomeScreen(authState),
routes: {
DashboardScreen.routeName: (ctx) => const DashboardScreen(),
FormScreen.routeName: (ctx) => const FormScreen(),
GalleryScreen.routeName: (ctx) => const GalleryScreen(),
GymModeScreen.routeName: (ctx) => const GymModeScreen(),
HomeTabsScreen.routeName: (ctx) => HomeTabsScreen(),
MeasurementCategoriesScreen.routeName: (ctx) => const MeasurementCategoriesScreen(),
MeasurementEntriesScreen.routeName: (ctx) => const MeasurementEntriesScreen(),
NutritionalPlansScreen.routeName: (ctx) => const NutritionalPlansScreen(),
NutritionalDiaryScreen.routeName: (ctx) => const NutritionalDiaryScreen(),
NutritionalPlanScreen.routeName: (ctx) => const NutritionalPlanScreen(),
LogMealsScreen.routeName: (ctx) => const LogMealsScreen(),
LogMealScreen.routeName: (ctx) => const LogMealScreen(),
WeightScreen.routeName: (ctx) => const WeightScreen(),
RoutineScreen.routeName: (ctx) => const RoutineScreen(),
RoutineEditScreen.routeName: (ctx) => const RoutineEditScreen(),
WorkoutLogsScreen.routeName: (ctx) => const WorkoutLogsScreen(),
RoutineListScreen.routeName: (ctx) => const RoutineListScreen(),
ExercisesScreen.routeName: (ctx) => const ExercisesScreen(),
ExerciseDetailScreen.routeName: (ctx) => const ExerciseDetailScreen(),
AddExerciseScreen.routeName: (ctx) => const AddExerciseScreen(),
AboutPage.routeName: (ctx) => const AboutPage(),
SettingsPage.routeName: (ctx) => const SettingsPage(),
LogOverviewPage.routeName: (ctx) => const LogOverviewPage(),
ConfigurePlatesScreen.routeName: (ctx) => const ConfigurePlatesScreen(),
ConfigureDashboardWidgetsScreen.routeName: (ctx) =>
const ConfigureDashboardWidgetsScreen(),
TrophyScreen.routeName: (ctx) => const TrophyScreen(),
},
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
),
),
);
},
);
}
}

View File

@@ -1,363 +0,0 @@
/*
* This file is part of wger Workout Manager <https://github.com/wger-project>.
* Copyright (c) 2020 - 2026 wger Team
*
* wger Workout Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:http/http.dart' as http;
import 'package:logging/logging.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:version/version.dart';
import 'package:wger/core/exceptions/http_exception.dart';
import 'package:wger/helpers/consts.dart';
import 'package:wger/helpers/shared_preferences.dart';
import 'helpers.dart';
enum LoginActions {
update,
proceed,
}
enum AuthState {
updateRequired,
serverUpdateRequired,
loggedIn,
loggedOut,
}
class AuthProvider with ChangeNotifier {
final _logger = Logger('AuthProvider');
String? token;
String? serverUrl;
String? serverVersion;
PackageInfo? applicationVersion;
Map<String, String> metadata = {};
AuthState state = AuthState.loggedOut;
static const MIN_APP_VERSION_URL = 'min-app-version';
static const SERVER_VERSION_URL = 'version';
static const REGISTRATION_URL = 'register';
static const LOGIN_URL = 'login';
static const USERPROFILE_URL = 'userprofile';
late http.Client client;
AuthProvider([http.Client? client]) {
this.client = client ?? http.Client();
}
/// flag to indicate that the application has successfully loaded all initial data
bool dataInit = false;
bool get isAuth {
return token != null;
}
/// Server application version
Future<void> setServerVersion() async {
final response = await client.get(makeUri(serverUrl!, SERVER_VERSION_URL));
serverVersion = json.decode(response.body);
}
/// (flutter) Application version
Future<void> setApplicationVersion() async {
applicationVersion = await PackageInfo.fromPlatform();
}
Future<void> initVersions(String serverUrl) async {
this.serverUrl = serverUrl;
await setApplicationVersion();
await setServerVersion();
}
/// Checking if there is a new version of the application.
Future<bool> applicationUpdateRequired([String? version]) async {
final applicationCurrentVersion = version ?? applicationVersion!.version;
final response = await client.get(makeUri(serverUrl!, MIN_APP_VERSION_URL));
final currentVersion = Version.parse(applicationCurrentVersion);
final requiredAppVersion = Version.parse(jsonDecode(response.body));
final needUpdate = requiredAppVersion > currentVersion;
if (needUpdate) {
_logger.fine('Application update required: $requiredAppVersion > $currentVersion');
}
return needUpdate;
}
/// Checks whether the connected server meets the minimum version required
/// by this build of the app.
///
/// [version] overrides [serverVersion] and is intended for unit testing.
bool serverUpdateRequired([String? version]) {
final rawVersion = version ?? serverVersion;
if (rawVersion == null) {
// If we couldn't read the server version, allow the login to proceed
// so as not to lock out users on unexpected server configurations.
_logger.warning('serverUpdateRequired: serverVersion is null, skipping check');
return false;
}
// Strip common non-semver suffixes emitted by Python/Django backends,
// e.g. '2.5.0a2' → '2.5.0', '2.3.0 (git-abc1234)' → '2.3.0'.
final sanitized = rawVersion
.replaceFirst(RegExp(r'\s.*$'), '') // strip trailing space + anything after
.replaceFirst(RegExp(r'[a-zA-Z].*$'), ''); // strip alpha/beta/rc suffix
final Version current;
try {
current = Version.parse(sanitized);
} on FormatException {
// Completely unparseable version string — be lenient and allow login.
_logger.warning(
'serverUpdateRequired: could not parse server version "$rawVersion" '
'(sanitized: "$sanitized"), skipping check',
);
return false;
}
final required = Version.parse(MIN_SERVER_VERSION);
final needUpdate = current < required;
if (needUpdate) {
_logger.fine('Server update required: server $current < minimum $required');
}
return needUpdate;
}
/// Registers a new user
Future<LoginActions> register({
required String username,
required String password,
required String email,
required String serverUrl,
String locale = 'en',
}) async {
// Register
final Map<String, String> data = {
'username': username,
'password': password,
};
if (email != '') {
data['email'] = email;
}
final response = await client.post(
makeUri(serverUrl, REGISTRATION_URL),
headers: {
HttpHeaders.contentTypeHeader: 'application/json; charset=UTF-8',
HttpHeaders.userAgentHeader: getAppNameHeader(),
HttpHeaders.acceptLanguageHeader: locale,
},
body: json.encode(data),
);
if (response.statusCode >= 400) {
throw WgerHttpException(response);
}
return login(username, password, serverUrl, null);
}
/// Authenticates a user
Future<LoginActions> login(
String username,
String password,
String serverUrl,
String? apiToken,
) async {
await logout(shouldNotify: false);
// Login using the API token
if (apiToken != null && apiToken.isNotEmpty) {
final response = await client.get(
makeUri(serverUrl, USERPROFILE_URL),
headers: {
HttpHeaders.contentTypeHeader: 'application/json; charset=UTF-8',
HttpHeaders.userAgentHeader: getAppNameHeader(),
HttpHeaders.authorizationHeader: 'Token $apiToken',
},
);
if (response.statusCode >= 400) {
throw WgerHttpException(response);
}
token = apiToken;
// Login using password
} else {
final response = await client.post(
makeUri(serverUrl, LOGIN_URL),
headers: {
HttpHeaders.contentTypeHeader: 'application/json; charset=utf-8',
HttpHeaders.userAgentHeader: getAppNameHeader(),
},
body: json.encode({'username': username, 'password': password}),
);
if (response.statusCode >= 400) {
throw WgerHttpException(response);
}
final responseData = json.decode(response.body);
token = responseData['token'];
}
await initVersions(serverUrl);
// If the server is too old for this app version, surface the dedicated
// screen so the user knows what to do (ask their server admin to upgrade).
if (serverUpdateRequired()) {
state = AuthState.serverUpdateRequired;
return LoginActions.update;
}
// If app update is required don't log in user
if (await applicationUpdateRequired()) {
state = AuthState.updateRequired;
return LoginActions.update;
}
// Log user in
state = AuthState.loggedIn;
notifyListeners();
// store login data in shared preferences
final prefs = PreferenceHelper.asyncPref;
final userData = json.encode({
'token': token,
'serverUrl': this.serverUrl,
});
final serverData = json.encode({'serverUrl': this.serverUrl});
prefs.setString(PREFS_USER, userData);
prefs.setString(PREFS_LAST_SERVER, serverData);
return LoginActions.proceed;
}
/// Loads the last server URL from which the user successfully logged in
Future<String> getServerUrlFromPrefs() async {
final prefs = PreferenceHelper.asyncPref;
if (!(await prefs.containsKey(PREFS_LAST_SERVER))) {
return DEFAULT_SERVER_PROD;
}
final userData = json.decode((await prefs.getString(PREFS_LAST_SERVER))!);
return userData['serverUrl'] as String;
}
/// Tries to auto-login the user with the stored token
Future<void> tryAutoLogin() async {
final prefs = PreferenceHelper.asyncPref;
if (!(await prefs.containsKey(PREFS_USER))) {
_logger.info('autologin failed, no saved user data');
state = AuthState.loggedOut;
return;
}
final userData = json.decode((await prefs.getString(PREFS_USER))!);
if (!userData.containsKey('token') || !userData.containsKey('serverUrl')) {
_logger.info('autologin failed, no token or serverUrl');
state = AuthState.loggedOut;
return;
}
token = userData['token'];
serverUrl = userData['serverUrl'];
if (token == null || serverUrl == null) {
_logger.info('autologin failed, token or serverUrl is null');
state = AuthState.loggedOut;
return;
}
// // Try to talk to a URL using the token, if this doesn't work, log out
final response = await client.head(
makeUri(serverUrl!, 'routine'),
headers: {
HttpHeaders.contentTypeHeader: 'application/json; charset=UTF-8',
HttpHeaders.userAgentHeader: getAppNameHeader(),
HttpHeaders.authorizationHeader: 'Token $token',
},
);
if (response.statusCode != 200) {
_logger.info('autologin failed, statusCode: ${response.statusCode}');
await logout();
return;
}
await initVersions(serverUrl!);
// If the server is too old for this app version, surface the dedicated
// screen so the user knows what to do (ask their server admin to upgrade).
if (serverUpdateRequired()) {
state = AuthState.serverUpdateRequired;
notifyListeners();
return;
}
// If app update is required don't log in user
if (await applicationUpdateRequired()) {
state = AuthState.updateRequired;
} else {
state = AuthState.loggedIn;
_logger.info('autologin successful');
}
notifyListeners();
}
Future<void> logout({bool shouldNotify = true}) async {
_logger.fine('logging out');
token = null;
serverUrl = null;
dataInit = false;
state = AuthState.loggedOut;
if (shouldNotify) {
notifyListeners();
}
final prefs = PreferenceHelper.asyncPref;
prefs.remove(PREFS_USER);
}
/// Returns the application name and version
///
/// This is used in the headers when talking to the API
String getAppNameHeader() {
String out = '';
if (applicationVersion != null) {
out =
'/${applicationVersion!.version} '
'(${applicationVersion!.packageName}; '
'build: ${applicationVersion!.buildNumber}; '
'platform: ${Platform.operatingSystem})'
' - https://github.com/wger-project';
}
return 'wger App$out';
}
}

View File

@@ -0,0 +1,356 @@
/*
* This file is part of wger Workout Manager <https://github.com/wger-project>.
* Copyright (c) 2020 - 2026 wger Team
*
* wger Workout Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:flutter_riverpod/flutter_riverpod.dart' show Provider;
import 'package:http/http.dart' as http;
import 'package:logging/logging.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:version/version.dart';
import 'package:wger/core/exceptions/http_exception.dart';
import 'package:wger/helpers/consts.dart';
import 'package:wger/helpers/shared_preferences.dart';
import 'package:wger/providers/auth_state.dart';
import 'package:wger/providers/helpers.dart';
part 'auth_notifier.g.dart';
const MIN_APP_VERSION_URL = 'min-app-version';
const SERVER_VERSION_URL = 'version';
const REGISTRATION_URL = 'register';
const LOGIN_URL = 'login';
const USERPROFILE_URL = 'userprofile';
/// HTTP client used by the auth notifier. Override in tests.
final authHttpClientProvider = Provider<http.Client>((ref) => http.Client());
@Riverpod(keepAlive: true)
class AuthNotifier extends _$AuthNotifier {
final _logger = Logger('AuthNotifier');
late http.Client _client;
@override
Future<AuthState> build() async {
_client = ref.read(authHttpClientProvider);
return _tryAutoLogin();
}
Future<AuthState> _tryAutoLogin() async {
final prefs = PreferenceHelper.asyncPref;
final appVersion = await PackageInfo.fromPlatform();
if (!(await prefs.containsKey(PREFS_USER))) {
_logger.info('autologin failed, no saved user data');
return AuthState(applicationVersion: appVersion);
}
final userData = json.decode((await prefs.getString(PREFS_USER))!);
if (!userData.containsKey('token') || !userData.containsKey('serverUrl')) {
_logger.info('autologin failed, no token or serverUrl');
return AuthState(applicationVersion: appVersion);
}
final String? token = userData['token'];
final String? serverUrl = userData['serverUrl'];
if (token == null || serverUrl == null) {
_logger.info('autologin failed, token or serverUrl is null');
return AuthState(applicationVersion: appVersion);
}
// Probe a URL using the token, if this doesn't work, log out
final response = await _client.head(
makeUri(serverUrl, 'routine'),
headers: {
HttpHeaders.contentTypeHeader: 'application/json; charset=UTF-8',
HttpHeaders.userAgentHeader: getAppNameHeader(appVersion),
HttpHeaders.authorizationHeader: 'Token $token',
},
);
if (response.statusCode != 200) {
_logger.info('autologin failed, statusCode: ${response.statusCode}');
await prefs.remove(PREFS_USER);
return AuthState(applicationVersion: appVersion);
}
final serverVersion = await _fetchServerVersion(serverUrl);
if (serverUpdateRequired(serverVersion)) {
return AuthState(
status: AuthStatus.serverUpdateRequired,
token: token,
serverUrl: serverUrl,
serverVersion: serverVersion,
applicationVersion: appVersion,
);
}
if (await _applicationUpdateRequired(serverUrl, appVersion.version)) {
return AuthState(
status: AuthStatus.updateRequired,
token: token,
serverUrl: serverUrl,
serverVersion: serverVersion,
applicationVersion: appVersion,
);
}
_logger.info('autologin successful');
return AuthState(
status: AuthStatus.loggedIn,
token: token,
serverUrl: serverUrl,
serverVersion: serverVersion,
applicationVersion: appVersion,
);
}
/// Returns the current state value or a blank default. Callers that
/// mutate state should always compose on top of this.
AuthState _currentOrBlank() => state.asData?.value ?? const AuthState();
/// Registers a new user and logs in.
Future<LoginActions> register({
required String username,
required String password,
required String email,
required String serverUrl,
String locale = 'en',
}) async {
final appVersion = _currentOrBlank().applicationVersion ?? await PackageInfo.fromPlatform();
final data = <String, String>{
'username': username,
'password': password,
};
if (email.isNotEmpty) {
data['email'] = email;
}
final response = await _client.post(
makeUri(serverUrl, REGISTRATION_URL),
headers: {
HttpHeaders.contentTypeHeader: 'application/json; charset=UTF-8',
HttpHeaders.userAgentHeader: getAppNameHeader(appVersion),
HttpHeaders.acceptLanguageHeader: locale,
},
body: json.encode(data),
);
if (response.statusCode >= 400) {
throw WgerHttpException(response);
}
return login(username, password, serverUrl, null);
}
/// Authenticates a user (by password or API token).
Future<LoginActions> login(
String username,
String password,
String serverUrl,
String? apiToken,
) async {
final current = _currentOrBlank();
final appVersion = current.applicationVersion ?? await PackageInfo.fromPlatform();
final String token;
if (apiToken != null && apiToken.isNotEmpty) {
final response = await _client.get(
makeUri(serverUrl, USERPROFILE_URL),
headers: {
HttpHeaders.contentTypeHeader: 'application/json; charset=UTF-8',
HttpHeaders.userAgentHeader: getAppNameHeader(appVersion),
HttpHeaders.authorizationHeader: 'Token $apiToken',
},
);
if (response.statusCode >= 400) {
throw WgerHttpException(response);
}
token = apiToken;
} else {
final response = await _client.post(
makeUri(serverUrl, LOGIN_URL),
headers: {
HttpHeaders.contentTypeHeader: 'application/json; charset=utf-8',
HttpHeaders.userAgentHeader: getAppNameHeader(appVersion),
},
body: json.encode({'username': username, 'password': password}),
);
if (response.statusCode >= 400) {
throw WgerHttpException(response);
}
token = json.decode(response.body)['token'];
}
final serverVersion = await _fetchServerVersion(serverUrl);
// Persist login before the update-gate checks, matching legacy behavior.
final prefs = PreferenceHelper.asyncPref;
await prefs.setString(
PREFS_USER,
json.encode({'token': token, 'serverUrl': serverUrl}),
);
await prefs.setString(
PREFS_LAST_SERVER,
json.encode({'serverUrl': serverUrl}),
);
if (serverUpdateRequired(serverVersion)) {
state = AsyncData(
current.copyWith(
status: AuthStatus.serverUpdateRequired,
token: token,
serverUrl: serverUrl,
serverVersion: serverVersion,
applicationVersion: appVersion,
),
);
return LoginActions.update;
}
if (await _applicationUpdateRequired(serverUrl, appVersion.version)) {
state = AsyncData(
current.copyWith(
status: AuthStatus.updateRequired,
token: token,
serverUrl: serverUrl,
serverVersion: serverVersion,
applicationVersion: appVersion,
),
);
return LoginActions.update;
}
state = AsyncData(
current.copyWith(
status: AuthStatus.loggedIn,
token: token,
serverUrl: serverUrl,
serverVersion: serverVersion,
applicationVersion: appVersion,
),
);
return LoginActions.proceed;
}
Future<void> logout() async {
_logger.fine('logging out');
state = AsyncData(
AuthState(applicationVersion: _currentOrBlank().applicationVersion),
);
await PreferenceHelper.asyncPref.remove(PREFS_USER);
}
/// Refreshes the server version into the state.
Future<void> setServerVersion() async {
final current = _currentOrBlank();
if (current.serverUrl == null) {
return;
}
final v = await _fetchServerVersion(current.serverUrl!);
state = AsyncData(current.copyWith(serverVersion: v));
}
/// Marks that the initial eager data-load has completed.
void setDataInit(bool value) {
state = AsyncData(_currentOrBlank().copyWith(dataInit: value));
}
Future<String> _fetchServerVersion(String serverUrl) async {
final response = await _client.get(makeUri(serverUrl, SERVER_VERSION_URL));
return json.decode(response.body);
}
Future<bool> _applicationUpdateRequired(String serverUrl, String appVersion) async {
final response = await _client.get(makeUri(serverUrl, MIN_APP_VERSION_URL));
final current = Version.parse(appVersion);
final required = Version.parse(jsonDecode(response.body));
final needUpdate = required > current;
if (needUpdate) {
_logger.fine('Application update required: $required > $current');
}
return needUpdate;
}
/// Loads the last server URL the user successfully logged in with.
static Future<String> getServerUrlFromPrefs() async {
final prefs = PreferenceHelper.asyncPref;
if (!(await prefs.containsKey(PREFS_LAST_SERVER))) {
return DEFAULT_SERVER_PROD;
}
final userData = json.decode((await prefs.getString(PREFS_LAST_SERVER))!);
return userData['serverUrl'] as String;
}
}
/// Checks whether the connected server meets the minimum version required
/// by this build of the app.
///
/// Returns false (lenient) when the version cannot be read or parsed, so
/// users aren't locked out on unexpected server configurations.
bool serverUpdateRequired(String? rawVersion) {
final logger = Logger('AuthNotifier');
if (rawVersion == null) {
logger.warning('serverUpdateRequired: serverVersion is null, skipping check');
return false;
}
// Strip common non-semver suffixes emitted by Python/Django backends,
// e.g. '2.5.0a2' → '2.5.0', '2.3.0 (git-abc1234)' → '2.3.0'.
final sanitized = rawVersion
.replaceFirst(RegExp(r'\s.*$'), '')
.replaceFirst(RegExp(r'[a-zA-Z].*$'), '');
final Version current;
try {
current = Version.parse(sanitized);
} on FormatException {
logger.warning(
'serverUpdateRequired: could not parse server version "$rawVersion" '
'(sanitized: "$sanitized"), skipping check',
);
return false;
}
final required = Version.parse(MIN_SERVER_VERSION);
final needUpdate = current < required;
if (needUpdate) {
logger.fine('Server update required: server $current < minimum $required');
}
return needUpdate;
}
/// User-agent header string identifying the app/version/platform.
String getAppNameHeader(PackageInfo? applicationVersion) {
String out = '';
if (applicationVersion != null) {
out =
'/${applicationVersion.version} '
'(${applicationVersion.packageName}; '
'build: ${applicationVersion.buildNumber}; '
'platform: ${Platform.operatingSystem})'
' - https://github.com/wger-project';
}
return 'wger App$out';
}

View File

@@ -0,0 +1,53 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'auth_notifier.dart';
// **************************************************************************
// RiverpodGenerator
// **************************************************************************
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint, type=warning
@ProviderFor(AuthNotifier)
final authProvider = AuthNotifierProvider._();
final class AuthNotifierProvider extends $AsyncNotifierProvider<AuthNotifier, AuthState> {
AuthNotifierProvider._()
: super(
from: null,
argument: null,
retry: null,
name: r'authProvider',
isAutoDispose: false,
dependencies: null,
$allTransitiveDependencies: null,
);
@override
String debugGetCreateSourceHash() => _$authNotifierHash();
@$internal
@override
AuthNotifier create() => AuthNotifier();
}
String _$authNotifierHash() => r'd49a270e893f5179da0228f4be679f7d8a7b16eb';
abstract class _$AuthNotifier extends $AsyncNotifier<AuthState> {
FutureOr<AuthState> build();
@$mustCallSuper
@override
void runBuild() {
final ref = this.ref as $Ref<AsyncValue<AuthState>, AuthState>;
final element =
ref.element
as $ClassProviderElement<
AnyNotifier<AsyncValue<AuthState>, AuthState>,
AsyncValue<AuthState>,
Object?,
Object?
>;
element.handleCreate(ref, build);
}
}

View File

@@ -0,0 +1,50 @@
/*
* This file is part of wger Workout Manager <https://github.com/wger-project>.
* Copyright (c) 2020 - 2026 wger Team
*
* wger Workout Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:package_info_plus/package_info_plus.dart';
part 'auth_state.freezed.dart';
enum AuthStatus {
loggedOut,
loggedIn,
updateRequired,
serverUpdateRequired,
}
enum LoginActions {
update,
proceed,
}
@freezed
sealed class AuthState with _$AuthState {
const factory AuthState({
@Default(AuthStatus.loggedOut) AuthStatus status,
String? token,
String? serverUrl,
String? serverVersion,
PackageInfo? applicationVersion,
@Default(false) bool dataInit,
}) = _AuthState;
const AuthState._();
bool get isAuth => token != null;
}

View File

@@ -0,0 +1,280 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// coverage:ignore-file
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'auth_state.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$AuthState {
AuthStatus get status; String? get token; String? get serverUrl; String? get serverVersion; PackageInfo? get applicationVersion; bool get dataInit;
/// Create a copy of AuthState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$AuthStateCopyWith<AuthState> get copyWith => _$AuthStateCopyWithImpl<AuthState>(this as AuthState, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is AuthState&&(identical(other.status, status) || other.status == status)&&(identical(other.token, token) || other.token == token)&&(identical(other.serverUrl, serverUrl) || other.serverUrl == serverUrl)&&(identical(other.serverVersion, serverVersion) || other.serverVersion == serverVersion)&&(identical(other.applicationVersion, applicationVersion) || other.applicationVersion == applicationVersion)&&(identical(other.dataInit, dataInit) || other.dataInit == dataInit));
}
@override
int get hashCode => Object.hash(runtimeType,status,token,serverUrl,serverVersion,applicationVersion,dataInit);
@override
String toString() {
return 'AuthState(status: $status, token: $token, serverUrl: $serverUrl, serverVersion: $serverVersion, applicationVersion: $applicationVersion, dataInit: $dataInit)';
}
}
/// @nodoc
abstract mixin class $AuthStateCopyWith<$Res> {
factory $AuthStateCopyWith(AuthState value, $Res Function(AuthState) _then) = _$AuthStateCopyWithImpl;
@useResult
$Res call({
AuthStatus status, String? token, String? serverUrl, String? serverVersion, PackageInfo? applicationVersion, bool dataInit
});
}
/// @nodoc
class _$AuthStateCopyWithImpl<$Res>
implements $AuthStateCopyWith<$Res> {
_$AuthStateCopyWithImpl(this._self, this._then);
final AuthState _self;
final $Res Function(AuthState) _then;
/// Create a copy of AuthState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? status = null,Object? token = freezed,Object? serverUrl = freezed,Object? serverVersion = freezed,Object? applicationVersion = freezed,Object? dataInit = null,}) {
return _then(_self.copyWith(
status: null == status ? _self.status : status // ignore: cast_nullable_to_non_nullable
as AuthStatus,token: freezed == token ? _self.token : token // ignore: cast_nullable_to_non_nullable
as String?,serverUrl: freezed == serverUrl ? _self.serverUrl : serverUrl // ignore: cast_nullable_to_non_nullable
as String?,serverVersion: freezed == serverVersion ? _self.serverVersion : serverVersion // ignore: cast_nullable_to_non_nullable
as String?,applicationVersion: freezed == applicationVersion ? _self.applicationVersion : applicationVersion // ignore: cast_nullable_to_non_nullable
as PackageInfo?,dataInit: null == dataInit ? _self.dataInit : dataInit // ignore: cast_nullable_to_non_nullable
as bool,
));
}
}
/// Adds pattern-matching-related methods to [AuthState].
extension AuthStatePatterns on AuthState {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _AuthState value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _AuthState() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _AuthState value) $default,){
final _that = this;
switch (_that) {
case _AuthState():
return $default(_that);}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _AuthState value)? $default,){
final _that = this;
switch (_that) {
case _AuthState() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( AuthStatus status, String? token, String? serverUrl, String? serverVersion, PackageInfo? applicationVersion, bool dataInit)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _AuthState() when $default != null:
return $default(_that.status,_that.token,_that.serverUrl,_that.serverVersion,_that.applicationVersion,_that.dataInit);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( AuthStatus status, String? token, String? serverUrl, String? serverVersion, PackageInfo? applicationVersion, bool dataInit) $default,) {final _that = this;
switch (_that) {
case _AuthState():
return $default(_that.status,_that.token,_that.serverUrl,_that.serverVersion,_that.applicationVersion,_that.dataInit);}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( AuthStatus status, String? token, String? serverUrl, String? serverVersion, PackageInfo? applicationVersion, bool dataInit)? $default,) {final _that = this;
switch (_that) {
case _AuthState() when $default != null:
return $default(_that.status,_that.token,_that.serverUrl,_that.serverVersion,_that.applicationVersion,_that.dataInit);case _:
return null;
}
}
}
/// @nodoc
class _AuthState extends AuthState {
const _AuthState({this.status = AuthStatus.loggedOut, this.token, this.serverUrl, this.serverVersion, this.applicationVersion, this.dataInit = false}): super._();
@override@JsonKey() final AuthStatus status;
@override final String? token;
@override final String? serverUrl;
@override final String? serverVersion;
@override final PackageInfo? applicationVersion;
@override@JsonKey() final bool dataInit;
/// Create a copy of AuthState
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$AuthStateCopyWith<_AuthState> get copyWith => __$AuthStateCopyWithImpl<_AuthState>(this, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _AuthState&&(identical(other.status, status) || other.status == status)&&(identical(other.token, token) || other.token == token)&&(identical(other.serverUrl, serverUrl) || other.serverUrl == serverUrl)&&(identical(other.serverVersion, serverVersion) || other.serverVersion == serverVersion)&&(identical(other.applicationVersion, applicationVersion) || other.applicationVersion == applicationVersion)&&(identical(other.dataInit, dataInit) || other.dataInit == dataInit));
}
@override
int get hashCode => Object.hash(runtimeType,status,token,serverUrl,serverVersion,applicationVersion,dataInit);
@override
String toString() {
return 'AuthState(status: $status, token: $token, serverUrl: $serverUrl, serverVersion: $serverVersion, applicationVersion: $applicationVersion, dataInit: $dataInit)';
}
}
/// @nodoc
abstract mixin class _$AuthStateCopyWith<$Res> implements $AuthStateCopyWith<$Res> {
factory _$AuthStateCopyWith(_AuthState value, $Res Function(_AuthState) _then) = __$AuthStateCopyWithImpl;
@override @useResult
$Res call({
AuthStatus status, String? token, String? serverUrl, String? serverVersion, PackageInfo? applicationVersion, bool dataInit
});
}
/// @nodoc
class __$AuthStateCopyWithImpl<$Res>
implements _$AuthStateCopyWith<$Res> {
__$AuthStateCopyWithImpl(this._self, this._then);
final _AuthState _self;
final $Res Function(_AuthState) _then;
/// Create a copy of AuthState
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? status = null,Object? token = freezed,Object? serverUrl = freezed,Object? serverVersion = freezed,Object? applicationVersion = freezed,Object? dataInit = null,}) {
return _then(_AuthState(
status: null == status ? _self.status : status // ignore: cast_nullable_to_non_nullable
as AuthStatus,token: freezed == token ? _self.token : token // ignore: cast_nullable_to_non_nullable
as String?,serverUrl: freezed == serverUrl ? _self.serverUrl : serverUrl // ignore: cast_nullable_to_non_nullable
as String?,serverVersion: freezed == serverVersion ? _self.serverVersion : serverVersion // ignore: cast_nullable_to_non_nullable
as String?,applicationVersion: freezed == applicationVersion ? _self.applicationVersion : applicationVersion // ignore: cast_nullable_to_non_nullable
as PackageInfo?,dataInit: null == dataInit ? _self.dataInit : dataInit // ignore: cast_nullable_to_non_nullable
as bool,
));
}
}
// dart format on

View File

@@ -23,8 +23,9 @@ import 'dart:math' as math;
import 'package:http/http.dart' as http;
import 'package:logging/logging.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:wger/core/exceptions/http_exception.dart';
import 'package:wger/providers/auth.dart';
import 'package:wger/providers/auth_notifier.dart' show getAppNameHeader;
import 'package:wger/providers/helpers.dart';
/// default timeout for GET requests
@@ -33,25 +34,36 @@ const DEFAULT_TIMEOUT = Duration(seconds: 15);
/// Base provider class.
///
/// Provides a couple of comfort functions so we avoid a bit of boilerplate.
/// Holds a snapshot of the auth-relevant fields (serverUrl, token, app version)
/// so it can build authenticated requests without depending on a specific
/// state-management library.
class WgerBaseProvider {
final _logger = Logger('WgerBaseProvider');
AuthProvider auth;
final String? serverUrl;
final String? token;
final PackageInfo? applicationVersion;
late http.Client client;
WgerBaseProvider(this.auth, [http.Client? client]) {
auth = auth;
WgerBaseProvider({
this.serverUrl,
this.token,
this.applicationVersion,
http.Client? client,
}) {
this.client = client ?? http.Client();
}
String getAppNameHeaderValue() => getAppNameHeader(applicationVersion);
Map<String, String> getDefaultHeaders({bool includeAuth = false, String? language}) {
final out = {
HttpHeaders.contentTypeHeader: 'application/json; charset=UTF-8',
HttpHeaders.userAgentHeader: auth.getAppNameHeader(),
HttpHeaders.userAgentHeader: getAppNameHeaderValue(),
};
if (includeAuth) {
out[HttpHeaders.authorizationHeader] = 'Token ${auth.token}';
out[HttpHeaders.authorizationHeader] = 'Token $token';
}
if (language != null) {
@@ -63,7 +75,7 @@ class WgerBaseProvider {
/// Helper function to make a URL.
Uri makeUrl(String path, {int? id, String? objectMethod, Map<String, dynamic>? query}) {
return makeUri(auth.serverUrl!, path, id, objectMethod, query);
return makeUri(serverUrl!, path, id, objectMethod, query);
}
/// Fetch and retrieve the overview list of objects, returns the JSON parsed response

View File

@@ -17,7 +17,6 @@
*/
import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
@@ -31,7 +30,13 @@ class GalleryProvider extends WgerBaseProvider with ChangeNotifier {
List<gallery.Image> images = [];
GalleryProvider(super.auth, List<gallery.Image> entries, [super.client]) : images = entries;
GalleryProvider({
super.serverUrl,
super.token,
super.applicationVersion,
List<gallery.Image> entries = const [],
super.client,
}) : images = List.of(entries);
/// Clears all lists
void clear() {
@@ -56,10 +61,7 @@ class GalleryProvider extends WgerBaseProvider with ChangeNotifier {
Future<void> addImage(gallery.Image image, XFile imageFile) async {
// create multipart request
final request = http.MultipartRequest('POST', makeUrl(_galleryUrlPath));
request.headers.addAll({
HttpHeaders.authorizationHeader: 'Token ${auth.token}',
HttpHeaders.userAgentHeader: auth.getAppNameHeader(),
});
request.headers.addAll(getDefaultHeaders(includeAuth: true));
request.files.add(await http.MultipartFile.fromPath('image', imageFile.path));
request.fields['date'] = dateToYYYYMMDD(image.date)!;
request.fields['description'] = image.description;
@@ -75,10 +77,7 @@ class GalleryProvider extends WgerBaseProvider with ChangeNotifier {
Future<void> editImage(gallery.Image image, XFile? imageFile) async {
final request = http.MultipartRequest('PATCH', makeUrl(_galleryUrlPath, id: image.id));
request.headers.addAll({
HttpHeaders.authorizationHeader: 'Token ${auth.token}',
HttpHeaders.userAgentHeader: auth.getAppNameHeader(),
});
request.headers.addAll(getDefaultHeaders(includeAuth: true));
// Only send the image if a new one was selected
if (imageFile != null) {

View File

@@ -1,6 +1,6 @@
/*
* This file is part of wger Workout Manager <https://github.com/wger-project>.
* Copyright (c) 2025 - 2025 wger Team
* Copyright (c) 2025 - 2026 wger Team
*
* wger Workout Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@@ -17,15 +17,20 @@
*/
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:wger/providers/auth.dart';
import 'package:wger/providers/auth_notifier.dart';
import 'package:wger/providers/base_provider.dart';
/// Central provider that maps an existing [AuthProvider] (from the provider package)
/// to a [WgerBaseProvider] used by repositories.
/// Central provider that builds a [WgerBaseProvider] from the current
/// [AuthNotifier] state. Consumers read this to make authenticated HTTP
/// requests. Rebuilds whenever the auth state changes.
///
/// Usage: ref.watch(wgerBaseProvider(authProvider))
/// Note: not using riverpod_generator here because the generated provider
/// class name would collide with [WgerBaseProvider] from base_provider.dart.
final wgerBaseProvider = Provider<WgerBaseProvider>((ref) {
throw UnimplementedError(
'Override wgerBaseProvider in a ProviderScope with your existing WgerBaseProvider instance',
final auth = ref.watch(authProvider).value;
return WgerBaseProvider(
serverUrl: auth?.serverUrl,
token: auth?.token,
applicationVersion: auth?.applicationVersion,
);
});

View File

@@ -18,11 +18,13 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:wger/core/exceptions/http_exception.dart';
import 'package:wger/helpers/consts.dart';
import 'package:wger/helpers/errors.dart';
import 'package:wger/l10n/generated/app_localizations.dart';
import 'package:wger/providers/auth_notifier.dart';
import 'package:wger/providers/auth_state.dart';
import 'package:wger/screens/update_app_screen.dart';
import 'package:wger/screens/update_server_screen.dart';
import 'package:wger/theme/theme.dart';
@@ -32,8 +34,6 @@ import 'package:wger/widgets/auth/password_field.dart';
import 'package:wger/widgets/auth/server_field.dart';
import 'package:wger/widgets/auth/username_field.dart';
import '../providers/auth.dart';
enum AuthMode {
Register,
Login,
@@ -100,14 +100,14 @@ class AuthScreen extends StatelessWidget {
}
}
class AuthCard extends StatefulWidget {
class AuthCard extends ConsumerStatefulWidget {
const AuthCard();
@override
_AuthCardState createState() => _AuthCardState();
}
class _AuthCardState extends State<AuthCard> {
class _AuthCardState extends ConsumerState<AuthCard> {
bool isObscure = true;
bool confirmIsObscure = true;
Widget errorMessage = const SizedBox.shrink();
@@ -147,8 +147,10 @@ class _AuthCardState extends State<AuthCard> {
@override
void initState() {
super.initState();
context.read<AuthProvider>().getServerUrlFromPrefs().then((value) {
_serverUrlController.text = value;
AuthNotifier.getServerUrlFromPrefs().then((value) {
if (mounted) {
_serverUrlController.text = value;
}
});
_preFillTextfields();
@@ -179,10 +181,11 @@ class _AuthCardState extends State<AuthCard> {
});
try {
final authNotifier = ref.read(authProvider.notifier);
// Login existing user
late LoginActions res;
if (_authMode == AuthMode.Login) {
res = await context.read<AuthProvider>().login(
res = await authNotifier.login(
_authData['username']!,
_authData['password']!,
_authData['serverUrl']!,
@@ -191,7 +194,7 @@ class _AuthCardState extends State<AuthCard> {
// Register new user
} else {
res = await Provider.of<AuthProvider>(context, listen: false).register(
res = await authNotifier.register(
username: _authData['username']!,
password: _authData['password']!,
email: _authData['email']!,
@@ -202,13 +205,13 @@ class _AuthCardState extends State<AuthCard> {
// Navigate to the appropriate "update required" screen.
if (res == LoginActions.update && mounted) {
final authState = context.read<AuthProvider>().state;
if (authState == AuthState.updateRequired) {
final status = ref.read(authProvider).value?.status;
if (status == AuthStatus.updateRequired) {
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => const UpdateAppScreen()),
);
return;
} else if (authState == AuthState.serverUpdateRequired) {
} else if (status == AuthStatus.serverUpdateRequired) {
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => const UpdateServerScreen()),
);

View File

@@ -24,7 +24,7 @@ import 'package:provider/provider.dart';
import 'package:rive/rive.dart';
import 'package:wger/helpers/material.dart';
import 'package:wger/l10n/generated/app_localizations.dart';
import 'package:wger/providers/auth.dart';
import 'package:wger/providers/auth_notifier.dart';
import 'package:wger/providers/exercise_state_notifier.dart';
import 'package:wger/providers/gallery.dart';
import 'package:wger/providers/nutrition.dart';
@@ -114,10 +114,11 @@ class _HomeTabsScreenState extends ConsumerState<HomeTabsScreen>
/// Load initial data from the server
Future<void> _loadEntries() async {
final languageCode = Localizations.localeOf(context).languageCode;
final authProvider = context.read<AuthProvider>();
final authNotifier = ref.read(authProvider.notifier);
final authState = ref.read(authProvider).value;
final trophyNotifier = ref.read(trophyStateProvider.notifier);
if (!authProvider.dataInit) {
if (authState != null && !authState.dataInit) {
final nutritionPlansProvider = context.read<NutritionPlansProvider>();
final galleryProvider = context.read<GalleryProvider>();
final userProvider = context.read<UserProvider>();
@@ -133,7 +134,7 @@ class _HomeTabsScreenState extends ConsumerState<HomeTabsScreen>
// Base data
widget._logger.info('Loading base data');
await Future.wait([
authProvider.setServerVersion(),
authNotifier.setServerVersion(),
userProvider.fetchAndSetProfile(),
nutritionPlansProvider.fetchIngredientsFromCache(),
]);
@@ -178,7 +179,7 @@ class _HomeTabsScreenState extends ConsumerState<HomeTabsScreen>
}
}
authProvider.dataInit = true;
authNotifier.setDataInit(true);
}
@override

View File

@@ -19,18 +19,18 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:provider/provider.dart';
import 'package:wger/core/wide_screen_wrapper.dart';
import 'package:wger/helpers/consts.dart';
import 'package:wger/helpers/misc.dart';
import 'package:wger/l10n/generated/app_localizations.dart';
import 'package:wger/providers/auth.dart';
import 'package:wger/providers/auth_notifier.dart';
import 'package:wger/screens/add_exercise_screen.dart';
import 'log_overview.dart';
class AboutPage extends StatelessWidget {
class AboutPage extends ConsumerWidget {
static String routeName = '/AboutPage';
const AboutPage({super.key});
@@ -49,8 +49,8 @@ class AboutPage extends StatelessWidget {
}
@override
Widget build(BuildContext context) {
final authProvider = Provider.of<AuthProvider>(context, listen: false);
Widget build(BuildContext context, WidgetRef ref) {
final authState = ref.watch(authProvider).value;
final i18n = AppLocalizations.of(context);
final today = DateTime.now();
@@ -83,8 +83,8 @@ class AboutPage extends StatelessWidget {
),
),
Text(
'App: ${authProvider.applicationVersion?.version ?? 'N/A'}\n'
'Server: ${authProvider.serverVersion ?? 'N/A'}',
'App: ${authState?.applicationVersion?.version ?? 'N/A'}\n'
'Server: ${authState?.serverVersion ?? 'N/A'}',
style: Theme.of(context).textTheme.bodySmall,
),
Padding(
@@ -208,8 +208,8 @@ class AboutPage extends StatelessWidget {
context: context,
applicationName: 'wger',
applicationVersion:
'App: ${authProvider.applicationVersion?.version ?? 'N/A'} '
'Server: ${authProvider.serverVersion ?? 'N/A'}',
'App: ${authState?.applicationVersion?.version ?? 'N/A'} '
'Server: ${authState?.serverVersion ?? 'N/A'}',
applicationLegalese: '\u{a9} ${today.year} wger contributors',
applicationIcon: Padding(
padding: const EdgeInsets.only(top: 10),

View File

@@ -22,7 +22,7 @@ import 'package:powersync/powersync.dart' as ps;
import 'package:provider/provider.dart';
import 'package:wger/database/powersync/powersync.dart' show syncStatus;
import 'package:wger/l10n/generated/app_localizations.dart';
import 'package:wger/providers/auth.dart';
import 'package:wger/providers/auth_notifier.dart';
import 'package:wger/providers/gallery.dart';
import 'package:wger/providers/nutrition.dart';
import 'package:wger/providers/user.dart';
@@ -104,11 +104,11 @@ class MainAppBar extends ConsumerWidget implements PreferredSizeWidget {
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
}
class MainSettingsDialog extends StatelessWidget {
class MainSettingsDialog extends ConsumerWidget {
const MainSettingsDialog({super.key});
@override
Widget build(BuildContext context) {
Widget build(BuildContext context, WidgetRef ref) {
return AlertDialog(
title: Text(AppLocalizations.of(context).optionsLabel),
actions: [
@@ -154,7 +154,7 @@ class MainSettingsDialog extends StatelessWidget {
leading: const Icon(Icons.exit_to_app),
title: Text(AppLocalizations.of(context).logout),
onTap: () {
context.read<AuthProvider>().logout();
ref.read(authProvider.notifier).logout();
// context.read<RoutinesProvider>().clear();
context.read<NutritionPlansProvider>().clear();
// context.read<BodyWeightProvider>().clear();

View File

@@ -0,0 +1,75 @@
/*
* This file is part of wger Workout Manager <https://github.com/wger-project>.
* Copyright (c) 2026 wger Team
*
* wger Workout Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter_test/flutter_test.dart';
import 'package:version/version.dart';
import 'package:wger/helpers/consts.dart';
import 'package:wger/providers/auth_notifier.dart';
void main() {
group('min server version check', () {
final minVersion = Version.parse(MIN_SERVER_VERSION);
final aboveMin = Version(minVersion.major, minVersion.minor + 1, 0).toString();
const atMin = MIN_SERVER_VERSION;
final belowMin = Version(minVersion.major, minVersion.minor - 1, 0).toString();
test('server version greater than min — no update needed', () {
expect(serverUpdateRequired(aboveMin), false);
});
test('server version equal to min — no update needed', () {
expect(serverUpdateRequired(atMin), false);
});
test('server version less than min — update needed', () {
expect(serverUpdateRequired(belowMin), true);
});
test('server version with patch component less than min — update needed', () {
expect(serverUpdateRequired('$belowMin.9'), true);
});
test('server version with patch component greater than min — no update needed', () {
expect(serverUpdateRequired('$atMin.1'), false);
});
test('null server version — returns false (lenient, no lockout)', () {
expect(serverUpdateRequired(null), false);
});
test('server version with pre-release suffix — still parsed correctly', () {
expect(serverUpdateRequired('$aboveMin.0-beta'), false);
});
test('server version with Python alpha suffix (e.g. 1.2.3.0a2) — parsed correctly', () {
expect(serverUpdateRequired('$aboveMin.0a2'), false);
});
test('server version with Python alpha suffix below min — blocked', () {
expect(serverUpdateRequired('$belowMin.0a2'), true);
});
test('server version with build metadata suffix — still parsed correctly', () {
expect(serverUpdateRequired('$belowMin.0 (git-abc1234)'), true);
});
test('completely unparseable server version — returns false (lenient)', () {
expect(serverUpdateRequired('unknown'), false);
});
});
}

View File

@@ -1,148 +0,0 @@
/*
* This file is part of wger Workout Manager <https://github.com/wger-project>.
* Copyright (c) 2026 wger Team
*
* wger Workout Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter_test/flutter_test.dart';
import 'package:http/http.dart';
import 'package:mockito/mockito.dart';
import 'package:version/version.dart';
import 'package:wger/helpers/consts.dart';
import 'package:wger/providers/auth.dart';
import '../other/base_provider_test.mocks.dart';
void main() {
late AuthProvider authProvider;
late MockClient mockClient;
final Uri tVersionUri = Uri(
scheme: 'http',
host: 'localhost',
path: 'api/v2/min-app-version/',
);
setUp(() {
mockClient = MockClient();
authProvider = AuthProvider(mockClient);
authProvider.serverUrl = 'http://localhost';
});
group('min application version check', () {
test('app version higher than min version', () async {
// arrange
when(mockClient.get(tVersionUri)).thenAnswer((_) => Future(() => Response('"1.2.0"', 200)));
final updateNeeded = await authProvider.applicationUpdateRequired('1.3.0');
// assert
expect(updateNeeded, false);
});
test('app version higher than min version - 1', () async {
// arrange
when(mockClient.get(tVersionUri)).thenAnswer((_) => Future(() => Response('"1.3"', 200)));
final updateNeeded = await authProvider.applicationUpdateRequired('1.1');
// assert
expect(updateNeeded, true);
});
test('app version higher than min version - 2', () async {
// arrange
when(mockClient.get(tVersionUri)).thenAnswer((_) => Future(() => Response('"1.3.0"', 200)));
final updateNeeded = await authProvider.applicationUpdateRequired('1.1');
// assert
expect(updateNeeded, true);
});
test('app version equal as min version', () async {
// arrange
when(mockClient.get(tVersionUri)).thenAnswer((_) => Future(() => Response('"1.3.0"', 200)));
final updateNeeded = await authProvider.applicationUpdateRequired('1.3.0');
// assert
expect(updateNeeded, false);
});
});
group('min server version check', () {
final minVersion = Version.parse(MIN_SERVER_VERSION);
final aboveMin = Version(minVersion.major, minVersion.minor + 1, 0).toString();
const atMin = MIN_SERVER_VERSION;
final belowMin = Version(minVersion.major, minVersion.minor - 1, 0).toString();
test('server version greater than min — no update needed', () {
authProvider.serverVersion = aboveMin;
expect(authProvider.serverUpdateRequired(), false);
});
test('server version equal to min — no update needed', () {
authProvider.serverVersion = atMin;
expect(authProvider.serverUpdateRequired(), false);
});
test('server version less than min — update needed', () {
authProvider.serverVersion = belowMin;
expect(authProvider.serverUpdateRequired(), true);
});
test('server version with patch component less than min — update needed', () {
authProvider.serverVersion = '$belowMin.9';
expect(authProvider.serverUpdateRequired(), true);
});
test('server version with patch component greater than min — no update needed', () {
authProvider.serverVersion = '$atMin.1';
expect(authProvider.serverUpdateRequired(), false);
});
test('null server version — returns false (lenient, no lockout)', () {
authProvider.serverVersion = null;
expect(authProvider.serverUpdateRequired(), false);
});
test('version override parameter is used instead of stored serverVersion', () {
authProvider.serverVersion = '99.0'; // would normally not require update
expect(authProvider.serverUpdateRequired(belowMin), true);
});
test('server version with pre-release suffix — still parsed correctly', () {
authProvider.serverVersion = '$aboveMin.0-beta';
expect(authProvider.serverUpdateRequired(), false);
});
test('server version with Python alpha suffix (e.g. 1.2.3.0a2) — parsed correctly', () {
authProvider.serverVersion = '$aboveMin.0a2';
expect(authProvider.serverUpdateRequired(), false);
});
test('server version with Python alpha suffix below min — blocked', () {
authProvider.serverVersion = '${belowMin}.0a2';
expect(authProvider.serverUpdateRequired(), true);
});
test('server version with build metadata suffix — still parsed correctly', () {
authProvider.serverVersion = '$belowMin.0 (git-abc1234)';
expect(authProvider.serverUpdateRequired(), true);
});
test('completely unparseable server version — returns false (lenient)', () {
authProvider.serverVersion = 'unknown';
expect(authProvider.serverUpdateRequired(), false);
});
});
}

View File

@@ -19,18 +19,18 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:http/http.dart' as http;
import 'package:http/http.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart';
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
import 'package:wger/l10n/generated/app_localizations.dart';
import 'package:wger/providers/auth.dart';
import 'package:wger/providers/auth_notifier.dart';
import 'package:wger/screens/auth_screen.dart';
import 'auth_screen_test.mocks.dart';
@@ -40,7 +40,6 @@ void main() {
/// Replacement for SharedPreferences.setMockInitialValues()
SharedPreferencesAsyncPlatform.instance = InMemorySharedPreferencesAsync.empty();
late AuthProvider authProvider;
late MockClient mockClient;
final Uri tRegistration = Uri(
@@ -66,24 +65,22 @@ void main() {
'token': '1234567890abcdef1234567890abcdef12345678',
};
MultiProvider getWidget() {
return MultiProvider(
providers: [ChangeNotifierProvider(create: (ctx) => authProvider)],
child: Consumer<AuthProvider>(
builder: (ctx, auth, _) => const MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
locale: Locale('en'),
home: AuthScreen(),
),
Widget getWidget() {
return ProviderScope(
overrides: [
authHttpClientProvider.overrideWithValue(mockClient),
],
child: const MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
locale: Locale('en'),
home: AuthScreen(),
),
);
}
setUp(() {
mockClient = MockClient();
authProvider = AuthProvider(mockClient);
authProvider.serverUrl = 'https://wger.de';
SharedPreferences.setMockInitialValues({});
PackageInfo.setMockInitialValues(
@@ -120,6 +117,7 @@ void main() {
testWidgets('Login smoke test', (WidgetTester tester) async {
// Act
await tester.pumpWidget(getWidget());
await tester.pumpAndSettle();
// Assert
expect(find.text('wger'), findsOneWidget);
@@ -141,6 +139,7 @@ void main() {
testWidgets('Login - with username & password - happy path', (WidgetTester tester) async {
// Arrange
await tester.pumpWidget(getWidget());
await tester.pumpAndSettle();
// Act
await tester.enterText(find.byKey(const Key('inputUsername')), 'testuser');
@@ -177,6 +176,7 @@ void main() {
).thenAnswer((_) => Future(() => Response(json.encode(response), 400)));
await tester.pumpWidget(getWidget());
await tester.pumpAndSettle();
// Act
await tester.enterText(find.byKey(const Key('inputUsername')), 'testuser');
@@ -199,6 +199,7 @@ void main() {
testWidgets('Login - with API token - happy path', (WidgetTester tester) async {
// Arrange
await tester.pumpWidget(getWidget());
await tester.pumpAndSettle();
// Act
await tester.tap(find.byKey(const ValueKey('toggleCustomServerButton')));
@@ -252,6 +253,7 @@ void main() {
mockClient.get(tProfileCheck, headers: anyNamed('headers')),
).thenAnswer((_) => Future(() => Response(json.encode(response), 400)));
await tester.pumpWidget(getWidget());
await tester.pumpAndSettle();
// Act
await tester.tap(find.byKey(const ValueKey('toggleCustomServerButton')));
@@ -297,6 +299,7 @@ void main() {
await tester.binding.setSurfaceSize(const Size(1080, 1920));
tester.view.devicePixelRatio = 1.0;
await tester.pumpWidget(getWidget());
await tester.pumpAndSettle();
// Act
await tester.tap(find.byKey(const Key('toggleActionButton')));
@@ -325,6 +328,7 @@ void main() {
await tester.binding.setSurfaceSize(const Size(1080, 1920));
tester.view.devicePixelRatio = 1.0;
await tester.pumpWidget(getWidget());
await tester.pumpAndSettle();
// Act
await tester.tap(find.byKey(const Key('toggleActionButton')));
@@ -365,6 +369,7 @@ void main() {
),
).thenAnswer((_) => Future(() => Response(json.encode(response), 400)));
await tester.pumpWidget(getWidget());
await tester.pumpAndSettle();
// Act
await tester.tap(find.byKey(const Key('toggleActionButton')));

View File

@@ -5,10 +5,10 @@
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i5;
import 'package:http/http.dart' as _i3;
import 'package:http/http.dart' as _i2;
import 'package:mockito/mockito.dart' as _i1;
import 'package:wger/providers/auth.dart' as _i2;
import 'package:wger/providers/base_provider.dart' as _i4;
import 'package:mockito/src/dummies.dart' as _i4;
import 'package:wger/providers/base_provider.dart' as _i3;
// ignore_for_file: type=lint
// ignore_for_file: avoid_redundant_argument_values
@@ -25,58 +25,51 @@ import 'package:wger/providers/base_provider.dart' as _i4;
// ignore_for_file: subtype_of_sealed_class
// ignore_for_file: invalid_use_of_internal_member
class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider {
_FakeAuthProvider_0(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeClient_0 extends _i1.SmartFake implements _i2.Client {
_FakeClient_0(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeClient_1 extends _i1.SmartFake implements _i3.Client {
_FakeClient_1(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeUri_1 extends _i1.SmartFake implements Uri {
_FakeUri_1(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeUri_2 extends _i1.SmartFake implements Uri {
_FakeUri_2(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeResponse_3 extends _i1.SmartFake implements _i3.Response {
_FakeResponse_3(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeResponse_2 extends _i1.SmartFake implements _i2.Response {
_FakeResponse_2(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
/// A class which mocks [WgerBaseProvider].
///
/// See the documentation for Mockito's code generation for more information.
class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
class MockWgerBaseProvider extends _i1.Mock implements _i3.WgerBaseProvider {
MockWgerBaseProvider() {
_i1.throwOnMissingStub(this);
}
@override
_i2.AuthProvider get auth =>
(super.noSuchMethod(
Invocation.getter(#auth),
returnValue: _FakeAuthProvider_0(this, Invocation.getter(#auth)),
)
as _i2.AuthProvider);
@override
_i3.Client get client =>
_i2.Client get client =>
(super.noSuchMethod(
Invocation.getter(#client),
returnValue: _FakeClient_1(this, Invocation.getter(#client)),
returnValue: _FakeClient_0(this, Invocation.getter(#client)),
)
as _i3.Client);
as _i2.Client);
@override
set auth(_i2.AuthProvider? value) => super.noSuchMethod(
Invocation.setter(#auth, value),
returnValueForMissingStub: null,
);
@override
set client(_i3.Client? value) => super.noSuchMethod(
set client(_i2.Client? value) => super.noSuchMethod(
Invocation.setter(#client, value),
returnValueForMissingStub: null,
);
@override
String getAppNameHeaderValue() =>
(super.noSuchMethod(
Invocation.method(#getAppNameHeaderValue, []),
returnValue: _i4.dummyValue<String>(
this,
Invocation.method(#getAppNameHeaderValue, []),
),
)
as String);
@override
Map<String, String> getDefaultHeaders({
bool? includeAuth = false,
@@ -104,7 +97,7 @@ class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
[path],
{#id: id, #objectMethod: objectMethod, #query: query},
),
returnValue: _FakeUri_2(
returnValue: _FakeUri_1(
this,
Invocation.method(
#makeUrl,
@@ -178,15 +171,15 @@ class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
as _i5.Future<Map<String, dynamic>>);
@override
_i5.Future<_i3.Response> deleteRequest(String? url, int? id) =>
_i5.Future<_i2.Response> deleteRequest(String? url, int? id) =>
(super.noSuchMethod(
Invocation.method(#deleteRequest, [url, id]),
returnValue: _i5.Future<_i3.Response>.value(
_FakeResponse_3(
returnValue: _i5.Future<_i2.Response>.value(
_FakeResponse_2(
this,
Invocation.method(#deleteRequest, [url, id]),
),
),
)
as _i5.Future<_i3.Response>);
as _i5.Future<_i2.Response>);
}

View File

@@ -3,24 +3,24 @@
// Do not manually edit this file.
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i12;
import 'dart:ui' as _i14;
import 'dart:async' as _i11;
import 'dart:ui' as _i13;
import 'package:flutter/material.dart' as _i16;
import 'package:http/http.dart' as _i10;
import 'package:flutter/material.dart' as _i15;
import 'package:http/http.dart' as _i9;
import 'package:mockito/mockito.dart' as _i1;
import 'package:mockito/src/dummies.dart' as _i17;
import 'package:shared_preferences/shared_preferences.dart' as _i8;
import 'package:wger/database/ingredients/ingredients_database.dart' as _i3;
import 'package:wger/models/nutrition/ingredient.dart' as _i7;
import 'package:wger/models/nutrition/ingredient_weight_unit.dart' as _i13;
import 'package:wger/models/nutrition/ingredient_weight_unit.dart' as _i12;
import 'package:wger/models/nutrition/meal.dart' as _i5;
import 'package:wger/models/nutrition/meal_item.dart' as _i6;
import 'package:wger/models/nutrition/nutritional_plan.dart' as _i4;
import 'package:wger/models/user/profile.dart' as _i17;
import 'package:wger/providers/auth.dart' as _i9;
import 'package:wger/models/user/profile.dart' as _i16;
import 'package:wger/providers/base_provider.dart' as _i2;
import 'package:wger/providers/nutrition.dart' as _i11;
import 'package:wger/providers/user.dart' as _i15;
import 'package:wger/providers/nutrition.dart' as _i10;
import 'package:wger/providers/user.dart' as _i14;
// ignore_for_file: type=lint
// ignore_for_file: avoid_redundant_argument_values
@@ -69,26 +69,22 @@ class _FakeSharedPreferencesAsync_6 extends _i1.SmartFake implements _i8.SharedP
: super(parent, parentInvocation);
}
class _FakeAuthProvider_7 extends _i1.SmartFake implements _i9.AuthProvider {
_FakeAuthProvider_7(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeClient_7 extends _i1.SmartFake implements _i9.Client {
_FakeClient_7(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeClient_8 extends _i1.SmartFake implements _i10.Client {
_FakeClient_8(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeUri_8 extends _i1.SmartFake implements Uri {
_FakeUri_8(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeUri_9 extends _i1.SmartFake implements Uri {
_FakeUri_9(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeResponse_10 extends _i1.SmartFake implements _i10.Response {
_FakeResponse_10(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeResponse_9 extends _i1.SmartFake implements _i9.Response {
_FakeResponse_9(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
/// A class which mocks [NutritionPlansProvider].
///
/// See the documentation for Mockito's code generation for more information.
class MockNutritionPlansProvider extends _i1.Mock implements _i11.NutritionPlansProvider {
class MockNutritionPlansProvider extends _i1.Mock implements _i10.NutritionPlansProvider {
MockNutritionPlansProvider() {
_i1.throwOnMissingStub(this);
}
@@ -169,145 +165,145 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i11.NutritionPlans
(super.noSuchMethod(Invocation.method(#findMealById, [id])) as _i5.Meal?);
@override
_i12.Future<void> fetchAndSetAllPlansSparse() =>
_i11.Future<void> fetchAndSetAllPlansSparse() =>
(super.noSuchMethod(
Invocation.method(#fetchAndSetAllPlansSparse, []),
returnValue: _i12.Future<void>.value(),
returnValueForMissingStub: _i12.Future<void>.value(),
returnValue: _i11.Future<void>.value(),
returnValueForMissingStub: _i11.Future<void>.value(),
)
as _i12.Future<void>);
as _i11.Future<void>);
@override
_i12.Future<void> fetchAndSetAllPlansFull() =>
_i11.Future<void> fetchAndSetAllPlansFull() =>
(super.noSuchMethod(
Invocation.method(#fetchAndSetAllPlansFull, []),
returnValue: _i12.Future<void>.value(),
returnValueForMissingStub: _i12.Future<void>.value(),
returnValue: _i11.Future<void>.value(),
returnValueForMissingStub: _i11.Future<void>.value(),
)
as _i12.Future<void>);
as _i11.Future<void>);
@override
_i12.Future<_i4.NutritionalPlan> fetchAndSetPlanSparse(int? planId) =>
_i11.Future<_i4.NutritionalPlan> fetchAndSetPlanSparse(int? planId) =>
(super.noSuchMethod(
Invocation.method(#fetchAndSetPlanSparse, [planId]),
returnValue: _i12.Future<_i4.NutritionalPlan>.value(
returnValue: _i11.Future<_i4.NutritionalPlan>.value(
_FakeNutritionalPlan_2(
this,
Invocation.method(#fetchAndSetPlanSparse, [planId]),
),
),
)
as _i12.Future<_i4.NutritionalPlan>);
as _i11.Future<_i4.NutritionalPlan>);
@override
_i12.Future<_i4.NutritionalPlan> fetchAndSetPlanFull(int? planId) =>
_i11.Future<_i4.NutritionalPlan> fetchAndSetPlanFull(int? planId) =>
(super.noSuchMethod(
Invocation.method(#fetchAndSetPlanFull, [planId]),
returnValue: _i12.Future<_i4.NutritionalPlan>.value(
returnValue: _i11.Future<_i4.NutritionalPlan>.value(
_FakeNutritionalPlan_2(
this,
Invocation.method(#fetchAndSetPlanFull, [planId]),
),
),
)
as _i12.Future<_i4.NutritionalPlan>);
as _i11.Future<_i4.NutritionalPlan>);
@override
_i12.Future<_i4.NutritionalPlan> addPlan(_i4.NutritionalPlan? planData) =>
_i11.Future<_i4.NutritionalPlan> addPlan(_i4.NutritionalPlan? planData) =>
(super.noSuchMethod(
Invocation.method(#addPlan, [planData]),
returnValue: _i12.Future<_i4.NutritionalPlan>.value(
returnValue: _i11.Future<_i4.NutritionalPlan>.value(
_FakeNutritionalPlan_2(
this,
Invocation.method(#addPlan, [planData]),
),
),
)
as _i12.Future<_i4.NutritionalPlan>);
as _i11.Future<_i4.NutritionalPlan>);
@override
_i12.Future<void> editPlan(_i4.NutritionalPlan? plan) =>
_i11.Future<void> editPlan(_i4.NutritionalPlan? plan) =>
(super.noSuchMethod(
Invocation.method(#editPlan, [plan]),
returnValue: _i12.Future<void>.value(),
returnValueForMissingStub: _i12.Future<void>.value(),
returnValue: _i11.Future<void>.value(),
returnValueForMissingStub: _i11.Future<void>.value(),
)
as _i12.Future<void>);
as _i11.Future<void>);
@override
_i12.Future<void> deletePlan(int? id) =>
_i11.Future<void> deletePlan(int? id) =>
(super.noSuchMethod(
Invocation.method(#deletePlan, [id]),
returnValue: _i12.Future<void>.value(),
returnValueForMissingStub: _i12.Future<void>.value(),
returnValue: _i11.Future<void>.value(),
returnValueForMissingStub: _i11.Future<void>.value(),
)
as _i12.Future<void>);
as _i11.Future<void>);
@override
_i12.Future<_i5.Meal> addMeal(_i5.Meal? meal, int? planId) =>
_i11.Future<_i5.Meal> addMeal(_i5.Meal? meal, int? planId) =>
(super.noSuchMethod(
Invocation.method(#addMeal, [meal, planId]),
returnValue: _i12.Future<_i5.Meal>.value(
returnValue: _i11.Future<_i5.Meal>.value(
_FakeMeal_3(this, Invocation.method(#addMeal, [meal, planId])),
),
)
as _i12.Future<_i5.Meal>);
as _i11.Future<_i5.Meal>);
@override
_i12.Future<_i5.Meal> editMeal(_i5.Meal? meal) =>
_i11.Future<_i5.Meal> editMeal(_i5.Meal? meal) =>
(super.noSuchMethod(
Invocation.method(#editMeal, [meal]),
returnValue: _i12.Future<_i5.Meal>.value(
returnValue: _i11.Future<_i5.Meal>.value(
_FakeMeal_3(this, Invocation.method(#editMeal, [meal])),
),
)
as _i12.Future<_i5.Meal>);
as _i11.Future<_i5.Meal>);
@override
_i12.Future<void> deleteMeal(_i5.Meal? meal) =>
_i11.Future<void> deleteMeal(_i5.Meal? meal) =>
(super.noSuchMethod(
Invocation.method(#deleteMeal, [meal]),
returnValue: _i12.Future<void>.value(),
returnValueForMissingStub: _i12.Future<void>.value(),
returnValue: _i11.Future<void>.value(),
returnValueForMissingStub: _i11.Future<void>.value(),
)
as _i12.Future<void>);
as _i11.Future<void>);
@override
_i12.Future<_i6.MealItem> addMealItem(
_i11.Future<_i6.MealItem> addMealItem(
_i6.MealItem? mealItem,
_i5.Meal? meal,
) =>
(super.noSuchMethod(
Invocation.method(#addMealItem, [mealItem, meal]),
returnValue: _i12.Future<_i6.MealItem>.value(
returnValue: _i11.Future<_i6.MealItem>.value(
_FakeMealItem_4(
this,
Invocation.method(#addMealItem, [mealItem, meal]),
),
),
)
as _i12.Future<_i6.MealItem>);
as _i11.Future<_i6.MealItem>);
@override
_i12.Future<void> deleteMealItem(_i6.MealItem? mealItem) =>
_i11.Future<void> deleteMealItem(_i6.MealItem? mealItem) =>
(super.noSuchMethod(
Invocation.method(#deleteMealItem, [mealItem]),
returnValue: _i12.Future<void>.value(),
returnValueForMissingStub: _i12.Future<void>.value(),
returnValue: _i11.Future<void>.value(),
returnValueForMissingStub: _i11.Future<void>.value(),
)
as _i12.Future<void>);
as _i11.Future<void>);
@override
_i12.Future<void> clearIngredientCache() =>
_i11.Future<void> clearIngredientCache() =>
(super.noSuchMethod(
Invocation.method(#clearIngredientCache, []),
returnValue: _i12.Future<void>.value(),
returnValueForMissingStub: _i12.Future<void>.value(),
returnValue: _i11.Future<void>.value(),
returnValueForMissingStub: _i11.Future<void>.value(),
)
as _i12.Future<void>);
as _i11.Future<void>);
@override
_i12.Future<void> cacheIngredient(
_i11.Future<void> cacheIngredient(
_i7.Ingredient? ingredient, {
_i3.IngredientDatabase? database,
}) =>
@@ -317,13 +313,13 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i11.NutritionPlans
[ingredient],
{#database: database},
),
returnValue: _i12.Future<void>.value(),
returnValueForMissingStub: _i12.Future<void>.value(),
returnValue: _i11.Future<void>.value(),
returnValueForMissingStub: _i11.Future<void>.value(),
)
as _i12.Future<void>);
as _i11.Future<void>);
@override
_i12.Future<_i7.Ingredient> fetchIngredient(
_i11.Future<_i7.Ingredient> fetchIngredient(
int? ingredientId, {
_i3.IngredientDatabase? database,
}) =>
@@ -333,7 +329,7 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i11.NutritionPlans
[ingredientId],
{#database: database},
),
returnValue: _i12.Future<_i7.Ingredient>.value(
returnValue: _i11.Future<_i7.Ingredient>.value(
_FakeIngredient_5(
this,
Invocation.method(
@@ -344,34 +340,34 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i11.NutritionPlans
),
),
)
as _i12.Future<_i7.Ingredient>);
as _i11.Future<_i7.Ingredient>);
@override
_i12.Future<List<_i13.IngredientWeightUnit>> fetchWeightUnits(
_i11.Future<List<_i12.IngredientWeightUnit>> fetchWeightUnits(
int? ingredientId,
) =>
(super.noSuchMethod(
Invocation.method(#fetchWeightUnits, [ingredientId]),
returnValue: _i12.Future<List<_i13.IngredientWeightUnit>>.value(
<_i13.IngredientWeightUnit>[],
returnValue: _i11.Future<List<_i12.IngredientWeightUnit>>.value(
<_i12.IngredientWeightUnit>[],
),
)
as _i12.Future<List<_i13.IngredientWeightUnit>>);
as _i11.Future<List<_i12.IngredientWeightUnit>>);
@override
_i12.Future<void> fetchIngredientsFromCache() =>
_i11.Future<void> fetchIngredientsFromCache() =>
(super.noSuchMethod(
Invocation.method(#fetchIngredientsFromCache, []),
returnValue: _i12.Future<void>.value(),
returnValueForMissingStub: _i12.Future<void>.value(),
returnValue: _i11.Future<void>.value(),
returnValueForMissingStub: _i11.Future<void>.value(),
)
as _i12.Future<void>);
as _i11.Future<void>);
@override
_i12.Future<List<_i7.Ingredient>> searchIngredient(
_i11.Future<List<_i7.Ingredient>> searchIngredient(
String? name, {
String? languageCode = 'en',
_i11.IngredientSearchLanguage? searchLanguage = _i11.IngredientSearchLanguage.current,
_i10.IngredientSearchLanguage? searchLanguage = _i10.IngredientSearchLanguage.current,
bool? isVegan = false,
bool? isVegetarian = false,
}) =>
@@ -386,31 +382,31 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i11.NutritionPlans
#isVegetarian: isVegetarian,
},
),
returnValue: _i12.Future<List<_i7.Ingredient>>.value(
returnValue: _i11.Future<List<_i7.Ingredient>>.value(
<_i7.Ingredient>[],
),
)
as _i12.Future<List<_i7.Ingredient>>);
as _i11.Future<List<_i7.Ingredient>>);
@override
_i12.Future<_i7.Ingredient?> searchIngredientWithBarcode(String? barcode) =>
_i11.Future<_i7.Ingredient?> searchIngredientWithBarcode(String? barcode) =>
(super.noSuchMethod(
Invocation.method(#searchIngredientWithBarcode, [barcode]),
returnValue: _i12.Future<_i7.Ingredient?>.value(),
returnValue: _i11.Future<_i7.Ingredient?>.value(),
)
as _i12.Future<_i7.Ingredient?>);
as _i11.Future<_i7.Ingredient?>);
@override
_i12.Future<void> logMealToDiary(_i5.Meal? meal, DateTime? mealDateTime) =>
_i11.Future<void> logMealToDiary(_i5.Meal? meal, DateTime? mealDateTime) =>
(super.noSuchMethod(
Invocation.method(#logMealToDiary, [meal, mealDateTime]),
returnValue: _i12.Future<void>.value(),
returnValueForMissingStub: _i12.Future<void>.value(),
returnValue: _i11.Future<void>.value(),
returnValueForMissingStub: _i11.Future<void>.value(),
)
as _i12.Future<void>);
as _i11.Future<void>);
@override
_i12.Future<void> logIngredientToDiary(
_i11.Future<void> logIngredientToDiary(
_i6.MealItem? mealItem,
int? planId, [
DateTime? dateTime,
@@ -421,37 +417,37 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i11.NutritionPlans
planId,
dateTime,
]),
returnValue: _i12.Future<void>.value(),
returnValueForMissingStub: _i12.Future<void>.value(),
returnValue: _i11.Future<void>.value(),
returnValueForMissingStub: _i11.Future<void>.value(),
)
as _i12.Future<void>);
as _i11.Future<void>);
@override
_i12.Future<void> deleteLog(int? logId, int? planId) =>
_i11.Future<void> deleteLog(int? logId, int? planId) =>
(super.noSuchMethod(
Invocation.method(#deleteLog, [logId, planId]),
returnValue: _i12.Future<void>.value(),
returnValueForMissingStub: _i12.Future<void>.value(),
returnValue: _i11.Future<void>.value(),
returnValueForMissingStub: _i11.Future<void>.value(),
)
as _i12.Future<void>);
as _i11.Future<void>);
@override
_i12.Future<void> fetchAndSetLogs(_i4.NutritionalPlan? plan) =>
_i11.Future<void> fetchAndSetLogs(_i4.NutritionalPlan? plan) =>
(super.noSuchMethod(
Invocation.method(#fetchAndSetLogs, [plan]),
returnValue: _i12.Future<void>.value(),
returnValueForMissingStub: _i12.Future<void>.value(),
returnValue: _i11.Future<void>.value(),
returnValueForMissingStub: _i11.Future<void>.value(),
)
as _i12.Future<void>);
as _i11.Future<void>);
@override
void addListener(_i14.VoidCallback? listener) => super.noSuchMethod(
void addListener(_i13.VoidCallback? listener) => super.noSuchMethod(
Invocation.method(#addListener, [listener]),
returnValueForMissingStub: null,
);
@override
void removeListener(_i14.VoidCallback? listener) => super.noSuchMethod(
void removeListener(_i13.VoidCallback? listener) => super.noSuchMethod(
Invocation.method(#removeListener, [listener]),
returnValueForMissingStub: null,
);
@@ -472,18 +468,18 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i11.NutritionPlans
/// A class which mocks [UserProvider].
///
/// See the documentation for Mockito's code generation for more information.
class MockUserProvider extends _i1.Mock implements _i15.UserProvider {
class MockUserProvider extends _i1.Mock implements _i14.UserProvider {
MockUserProvider() {
_i1.throwOnMissingStub(this);
}
@override
_i16.ThemeMode get themeMode =>
_i15.ThemeMode get themeMode =>
(super.noSuchMethod(
Invocation.getter(#themeMode),
returnValue: _i16.ThemeMode.system,
returnValue: _i15.ThemeMode.system,
)
as _i16.ThemeMode);
as _i15.ThemeMode);
@override
_i2.WgerBaseProvider get baseProvider =>
@@ -508,23 +504,23 @@ class MockUserProvider extends _i1.Mock implements _i15.UserProvider {
as _i8.SharedPreferencesAsync);
@override
List<_i15.DashboardWidget> get dashboardWidgets =>
List<_i14.DashboardWidget> get dashboardWidgets =>
(super.noSuchMethod(
Invocation.getter(#dashboardWidgets),
returnValue: <_i15.DashboardWidget>[],
returnValue: <_i14.DashboardWidget>[],
)
as List<_i15.DashboardWidget>);
as List<_i14.DashboardWidget>);
@override
List<_i15.DashboardWidget> get allDashboardWidgets =>
List<_i14.DashboardWidget> get allDashboardWidgets =>
(super.noSuchMethod(
Invocation.getter(#allDashboardWidgets),
returnValue: <_i15.DashboardWidget>[],
returnValue: <_i14.DashboardWidget>[],
)
as List<_i15.DashboardWidget>);
as List<_i14.DashboardWidget>);
@override
set themeMode(_i16.ThemeMode? value) => super.noSuchMethod(
set themeMode(_i15.ThemeMode? value) => super.noSuchMethod(
Invocation.setter(#themeMode, value),
returnValueForMissingStub: null,
);
@@ -536,7 +532,7 @@ class MockUserProvider extends _i1.Mock implements _i15.UserProvider {
);
@override
set profile(_i17.Profile? value) => super.noSuchMethod(
set profile(_i16.Profile? value) => super.noSuchMethod(
Invocation.setter(#profile, value),
returnValueForMissingStub: null,
);
@@ -552,7 +548,7 @@ class MockUserProvider extends _i1.Mock implements _i15.UserProvider {
);
@override
bool isDashboardWidgetVisible(_i15.DashboardWidget? key) =>
bool isDashboardWidgetVisible(_i14.DashboardWidget? key) =>
(super.noSuchMethod(
Invocation.method(#isDashboardWidgetVisible, [key]),
returnValue: false,
@@ -560,67 +556,67 @@ class MockUserProvider extends _i1.Mock implements _i15.UserProvider {
as bool);
@override
_i12.Future<void> setDashboardWidgetVisible(
_i15.DashboardWidget? key,
_i11.Future<void> setDashboardWidgetVisible(
_i14.DashboardWidget? key,
bool? visible,
) =>
(super.noSuchMethod(
Invocation.method(#setDashboardWidgetVisible, [key, visible]),
returnValue: _i12.Future<void>.value(),
returnValueForMissingStub: _i12.Future<void>.value(),
returnValue: _i11.Future<void>.value(),
returnValueForMissingStub: _i11.Future<void>.value(),
)
as _i12.Future<void>);
as _i11.Future<void>);
@override
_i12.Future<void> setDashboardOrder(int? oldIndex, int? newIndex) =>
_i11.Future<void> setDashboardOrder(int? oldIndex, int? newIndex) =>
(super.noSuchMethod(
Invocation.method(#setDashboardOrder, [oldIndex, newIndex]),
returnValue: _i12.Future<void>.value(),
returnValueForMissingStub: _i12.Future<void>.value(),
returnValue: _i11.Future<void>.value(),
returnValueForMissingStub: _i11.Future<void>.value(),
)
as _i12.Future<void>);
as _i11.Future<void>);
@override
void setThemeMode(_i16.ThemeMode? mode) => super.noSuchMethod(
void setThemeMode(_i15.ThemeMode? mode) => super.noSuchMethod(
Invocation.method(#setThemeMode, [mode]),
returnValueForMissingStub: null,
);
@override
_i12.Future<void> fetchAndSetProfile() =>
_i11.Future<void> fetchAndSetProfile() =>
(super.noSuchMethod(
Invocation.method(#fetchAndSetProfile, []),
returnValue: _i12.Future<void>.value(),
returnValueForMissingStub: _i12.Future<void>.value(),
returnValue: _i11.Future<void>.value(),
returnValueForMissingStub: _i11.Future<void>.value(),
)
as _i12.Future<void>);
as _i11.Future<void>);
@override
_i12.Future<void> saveProfile() =>
_i11.Future<void> saveProfile() =>
(super.noSuchMethod(
Invocation.method(#saveProfile, []),
returnValue: _i12.Future<void>.value(),
returnValueForMissingStub: _i12.Future<void>.value(),
returnValue: _i11.Future<void>.value(),
returnValueForMissingStub: _i11.Future<void>.value(),
)
as _i12.Future<void>);
as _i11.Future<void>);
@override
_i12.Future<void> verifyEmail() =>
_i11.Future<void> verifyEmail() =>
(super.noSuchMethod(
Invocation.method(#verifyEmail, []),
returnValue: _i12.Future<void>.value(),
returnValueForMissingStub: _i12.Future<void>.value(),
returnValue: _i11.Future<void>.value(),
returnValueForMissingStub: _i11.Future<void>.value(),
)
as _i12.Future<void>);
as _i11.Future<void>);
@override
void addListener(_i14.VoidCallback? listener) => super.noSuchMethod(
void addListener(_i13.VoidCallback? listener) => super.noSuchMethod(
Invocation.method(#addListener, [listener]),
returnValueForMissingStub: null,
);
@override
void removeListener(_i14.VoidCallback? listener) => super.noSuchMethod(
void removeListener(_i13.VoidCallback? listener) => super.noSuchMethod(
Invocation.method(#removeListener, [listener]),
returnValueForMissingStub: null,
);
@@ -647,33 +643,30 @@ class MockWgerBaseProvider extends _i1.Mock implements _i2.WgerBaseProvider {
}
@override
_i9.AuthProvider get auth =>
(super.noSuchMethod(
Invocation.getter(#auth),
returnValue: _FakeAuthProvider_7(this, Invocation.getter(#auth)),
)
as _i9.AuthProvider);
@override
_i10.Client get client =>
_i9.Client get client =>
(super.noSuchMethod(
Invocation.getter(#client),
returnValue: _FakeClient_8(this, Invocation.getter(#client)),
returnValue: _FakeClient_7(this, Invocation.getter(#client)),
)
as _i10.Client);
as _i9.Client);
@override
set auth(_i9.AuthProvider? value) => super.noSuchMethod(
Invocation.setter(#auth, value),
returnValueForMissingStub: null,
);
@override
set client(_i10.Client? value) => super.noSuchMethod(
set client(_i9.Client? value) => super.noSuchMethod(
Invocation.setter(#client, value),
returnValueForMissingStub: null,
);
@override
String getAppNameHeaderValue() =>
(super.noSuchMethod(
Invocation.method(#getAppNameHeaderValue, []),
returnValue: _i17.dummyValue<String>(
this,
Invocation.method(#getAppNameHeaderValue, []),
),
)
as String);
@override
Map<String, String> getDefaultHeaders({
bool? includeAuth = false,
@@ -701,7 +694,7 @@ class MockWgerBaseProvider extends _i1.Mock implements _i2.WgerBaseProvider {
[path],
{#id: id, #objectMethod: objectMethod, #query: query},
),
returnValue: _FakeUri_9(
returnValue: _FakeUri_8(
this,
Invocation.method(
#makeUrl,
@@ -713,7 +706,7 @@ class MockWgerBaseProvider extends _i1.Mock implements _i2.WgerBaseProvider {
as Uri);
@override
_i12.Future<dynamic> fetch(
_i11.Future<dynamic> fetch(
Uri? uri, {
int? maxRetries = 3,
Duration? initialDelay = const Duration(milliseconds: 250),
@@ -731,12 +724,12 @@ class MockWgerBaseProvider extends _i1.Mock implements _i2.WgerBaseProvider {
#language: language,
},
),
returnValue: _i12.Future<dynamic>.value(),
returnValue: _i11.Future<dynamic>.value(),
)
as _i12.Future<dynamic>);
as _i11.Future<dynamic>);
@override
_i12.Future<List<dynamic>> fetchPaginated(
_i11.Future<List<dynamic>> fetchPaginated(
Uri? uri, {
String? language,
Duration? timeout = const Duration(seconds: 15),
@@ -747,48 +740,48 @@ class MockWgerBaseProvider extends _i1.Mock implements _i2.WgerBaseProvider {
[uri],
{#language: language, #timeout: timeout},
),
returnValue: _i12.Future<List<dynamic>>.value(<dynamic>[]),
returnValue: _i11.Future<List<dynamic>>.value(<dynamic>[]),
)
as _i12.Future<List<dynamic>>);
as _i11.Future<List<dynamic>>);
@override
_i12.Future<Map<String, dynamic>> post(
_i11.Future<Map<String, dynamic>> post(
Map<String, dynamic>? data,
Uri? uri,
) =>
(super.noSuchMethod(
Invocation.method(#post, [data, uri]),
returnValue: _i12.Future<Map<String, dynamic>>.value(
returnValue: _i11.Future<Map<String, dynamic>>.value(
<String, dynamic>{},
),
)
as _i12.Future<Map<String, dynamic>>);
as _i11.Future<Map<String, dynamic>>);
@override
_i12.Future<Map<String, dynamic>> patch(
_i11.Future<Map<String, dynamic>> patch(
Map<String, dynamic>? data,
Uri? uri,
) =>
(super.noSuchMethod(
Invocation.method(#patch, [data, uri]),
returnValue: _i12.Future<Map<String, dynamic>>.value(
returnValue: _i11.Future<Map<String, dynamic>>.value(
<String, dynamic>{},
),
)
as _i12.Future<Map<String, dynamic>>);
as _i11.Future<Map<String, dynamic>>);
@override
_i12.Future<_i10.Response> deleteRequest(String? url, int? id) =>
_i11.Future<_i9.Response> deleteRequest(String? url, int? id) =>
(super.noSuchMethod(
Invocation.method(#deleteRequest, [url, id]),
returnValue: _i12.Future<_i10.Response>.value(
_FakeResponse_10(
returnValue: _i11.Future<_i9.Response>.value(
_FakeResponse_9(
this,
Invocation.method(#deleteRequest, [url, id]),
),
),
)
as _i12.Future<_i10.Response>);
as _i11.Future<_i9.Response>);
}
/// A class which mocks [SharedPreferencesAsync].
@@ -801,131 +794,131 @@ class MockSharedPreferencesAsync extends _i1.Mock implements _i8.SharedPreferenc
}
@override
_i12.Future<Set<String>> getKeys({Set<String>? allowList}) =>
_i11.Future<Set<String>> getKeys({Set<String>? allowList}) =>
(super.noSuchMethod(
Invocation.method(#getKeys, [], {#allowList: allowList}),
returnValue: _i12.Future<Set<String>>.value(<String>{}),
returnValue: _i11.Future<Set<String>>.value(<String>{}),
)
as _i12.Future<Set<String>>);
as _i11.Future<Set<String>>);
@override
_i12.Future<Map<String, Object?>> getAll({Set<String>? allowList}) =>
_i11.Future<Map<String, Object?>> getAll({Set<String>? allowList}) =>
(super.noSuchMethod(
Invocation.method(#getAll, [], {#allowList: allowList}),
returnValue: _i12.Future<Map<String, Object?>>.value(
returnValue: _i11.Future<Map<String, Object?>>.value(
<String, Object?>{},
),
)
as _i12.Future<Map<String, Object?>>);
as _i11.Future<Map<String, Object?>>);
@override
_i12.Future<bool?> getBool(String? key) =>
_i11.Future<bool?> getBool(String? key) =>
(super.noSuchMethod(
Invocation.method(#getBool, [key]),
returnValue: _i12.Future<bool?>.value(),
returnValue: _i11.Future<bool?>.value(),
)
as _i12.Future<bool?>);
as _i11.Future<bool?>);
@override
_i12.Future<int?> getInt(String? key) =>
_i11.Future<int?> getInt(String? key) =>
(super.noSuchMethod(
Invocation.method(#getInt, [key]),
returnValue: _i12.Future<int?>.value(),
returnValue: _i11.Future<int?>.value(),
)
as _i12.Future<int?>);
as _i11.Future<int?>);
@override
_i12.Future<double?> getDouble(String? key) =>
_i11.Future<double?> getDouble(String? key) =>
(super.noSuchMethod(
Invocation.method(#getDouble, [key]),
returnValue: _i12.Future<double?>.value(),
returnValue: _i11.Future<double?>.value(),
)
as _i12.Future<double?>);
as _i11.Future<double?>);
@override
_i12.Future<String?> getString(String? key) =>
_i11.Future<String?> getString(String? key) =>
(super.noSuchMethod(
Invocation.method(#getString, [key]),
returnValue: _i12.Future<String?>.value(),
returnValue: _i11.Future<String?>.value(),
)
as _i12.Future<String?>);
as _i11.Future<String?>);
@override
_i12.Future<List<String>?> getStringList(String? key) =>
_i11.Future<List<String>?> getStringList(String? key) =>
(super.noSuchMethod(
Invocation.method(#getStringList, [key]),
returnValue: _i12.Future<List<String>?>.value(),
returnValue: _i11.Future<List<String>?>.value(),
)
as _i12.Future<List<String>?>);
as _i11.Future<List<String>?>);
@override
_i12.Future<bool> containsKey(String? key) =>
_i11.Future<bool> containsKey(String? key) =>
(super.noSuchMethod(
Invocation.method(#containsKey, [key]),
returnValue: _i12.Future<bool>.value(false),
returnValue: _i11.Future<bool>.value(false),
)
as _i12.Future<bool>);
as _i11.Future<bool>);
@override
_i12.Future<void> setBool(String? key, bool? value) =>
_i11.Future<void> setBool(String? key, bool? value) =>
(super.noSuchMethod(
Invocation.method(#setBool, [key, value]),
returnValue: _i12.Future<void>.value(),
returnValueForMissingStub: _i12.Future<void>.value(),
returnValue: _i11.Future<void>.value(),
returnValueForMissingStub: _i11.Future<void>.value(),
)
as _i12.Future<void>);
as _i11.Future<void>);
@override
_i12.Future<void> setInt(String? key, int? value) =>
_i11.Future<void> setInt(String? key, int? value) =>
(super.noSuchMethod(
Invocation.method(#setInt, [key, value]),
returnValue: _i12.Future<void>.value(),
returnValueForMissingStub: _i12.Future<void>.value(),
returnValue: _i11.Future<void>.value(),
returnValueForMissingStub: _i11.Future<void>.value(),
)
as _i12.Future<void>);
as _i11.Future<void>);
@override
_i12.Future<void> setDouble(String? key, double? value) =>
_i11.Future<void> setDouble(String? key, double? value) =>
(super.noSuchMethod(
Invocation.method(#setDouble, [key, value]),
returnValue: _i12.Future<void>.value(),
returnValueForMissingStub: _i12.Future<void>.value(),
returnValue: _i11.Future<void>.value(),
returnValueForMissingStub: _i11.Future<void>.value(),
)
as _i12.Future<void>);
as _i11.Future<void>);
@override
_i12.Future<void> setString(String? key, String? value) =>
_i11.Future<void> setString(String? key, String? value) =>
(super.noSuchMethod(
Invocation.method(#setString, [key, value]),
returnValue: _i12.Future<void>.value(),
returnValueForMissingStub: _i12.Future<void>.value(),
returnValue: _i11.Future<void>.value(),
returnValueForMissingStub: _i11.Future<void>.value(),
)
as _i12.Future<void>);
as _i11.Future<void>);
@override
_i12.Future<void> setStringList(String? key, List<String>? value) =>
_i11.Future<void> setStringList(String? key, List<String>? value) =>
(super.noSuchMethod(
Invocation.method(#setStringList, [key, value]),
returnValue: _i12.Future<void>.value(),
returnValueForMissingStub: _i12.Future<void>.value(),
returnValue: _i11.Future<void>.value(),
returnValueForMissingStub: _i11.Future<void>.value(),
)
as _i12.Future<void>);
as _i11.Future<void>);
@override
_i12.Future<void> remove(String? key) =>
_i11.Future<void> remove(String? key) =>
(super.noSuchMethod(
Invocation.method(#remove, [key]),
returnValue: _i12.Future<void>.value(),
returnValueForMissingStub: _i12.Future<void>.value(),
returnValue: _i11.Future<void>.value(),
returnValueForMissingStub: _i11.Future<void>.value(),
)
as _i12.Future<void>);
as _i11.Future<void>);
@override
_i12.Future<void> clear({Set<String>? allowList}) =>
_i11.Future<void> clear({Set<String>? allowList}) =>
(super.noSuchMethod(
Invocation.method(#clear, [], {#allowList: allowList}),
returnValue: _i12.Future<void>.value(),
returnValueForMissingStub: _i12.Future<void>.value(),
returnValue: _i11.Future<void>.value(),
returnValueForMissingStub: _i11.Future<void>.value(),
)
as _i12.Future<void>);
as _i11.Future<void>);
}

View File

@@ -3,20 +3,19 @@
// Do not manually edit this file.
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i13;
import 'dart:ui' as _i14;
import 'dart:async' as _i12;
import 'dart:ui' as _i13;
import 'package:http/http.dart' as _i4;
import 'package:http/http.dart' as _i3;
import 'package:mockito/mockito.dart' as _i1;
import 'package:mockito/src/dummies.dart' as _i7;
import 'package:wger/models/core/language.dart' as _i11;
import 'package:wger/models/exercises/category.dart' as _i12;
import 'package:wger/models/exercises/equipment.dart' as _i8;
import 'package:wger/models/exercises/exercise_submission.dart' as _i10;
import 'package:wger/models/exercises/exercise_submission_images.dart' as _i6;
import 'package:wger/models/exercises/muscle.dart' as _i9;
import 'package:wger/providers/add_exercise.dart' as _i5;
import 'package:wger/providers/auth.dart' as _i3;
import 'package:mockito/src/dummies.dart' as _i6;
import 'package:wger/models/core/language.dart' as _i10;
import 'package:wger/models/exercises/category.dart' as _i11;
import 'package:wger/models/exercises/equipment.dart' as _i7;
import 'package:wger/models/exercises/exercise_submission.dart' as _i9;
import 'package:wger/models/exercises/exercise_submission_images.dart' as _i5;
import 'package:wger/models/exercises/muscle.dart' as _i8;
import 'package:wger/providers/add_exercise.dart' as _i4;
import 'package:wger/providers/base_provider.dart' as _i2;
// ignore_for_file: type=lint
@@ -39,26 +38,22 @@ class _FakeWgerBaseProvider_0 extends _i1.SmartFake implements _i2.WgerBaseProvi
: super(parent, parentInvocation);
}
class _FakeAuthProvider_1 extends _i1.SmartFake implements _i3.AuthProvider {
_FakeAuthProvider_1(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeClient_1 extends _i1.SmartFake implements _i3.Client {
_FakeClient_1(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeClient_2 extends _i1.SmartFake implements _i4.Client {
_FakeClient_2(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeUri_2 extends _i1.SmartFake implements Uri {
_FakeUri_2(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeUri_3 extends _i1.SmartFake implements Uri {
_FakeUri_3(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeResponse_4 extends _i1.SmartFake implements _i4.Response {
_FakeResponse_4(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeResponse_3 extends _i1.SmartFake implements _i3.Response {
_FakeResponse_3(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
/// A class which mocks [AddExerciseProvider].
///
/// See the documentation for Mockito's code generation for more information.
class MockAddExerciseProvider extends _i1.Mock implements _i5.AddExerciseProvider {
class MockAddExerciseProvider extends _i1.Mock implements _i4.AddExerciseProvider {
MockAddExerciseProvider() {
_i1.throwOnMissingStub(this);
}
@@ -75,18 +70,18 @@ class MockAddExerciseProvider extends _i1.Mock implements _i5.AddExerciseProvide
as _i2.WgerBaseProvider);
@override
List<_i6.ExerciseSubmissionImage> get exerciseImages =>
List<_i5.ExerciseSubmissionImage> get exerciseImages =>
(super.noSuchMethod(
Invocation.getter(#exerciseImages),
returnValue: <_i6.ExerciseSubmissionImage>[],
returnValue: <_i5.ExerciseSubmissionImage>[],
)
as List<_i6.ExerciseSubmissionImage>);
as List<_i5.ExerciseSubmissionImage>);
@override
String get author =>
(super.noSuchMethod(
Invocation.getter(#author),
returnValue: _i7.dummyValue<String>(
returnValue: _i6.dummyValue<String>(
this,
Invocation.getter(#author),
),
@@ -110,43 +105,43 @@ class MockAddExerciseProvider extends _i1.Mock implements _i5.AddExerciseProvide
as List<String>);
@override
List<_i8.Equipment> get equipment =>
List<_i7.Equipment> get equipment =>
(super.noSuchMethod(
Invocation.getter(#equipment),
returnValue: <_i8.Equipment>[],
returnValue: <_i7.Equipment>[],
)
as List<_i8.Equipment>);
as List<_i7.Equipment>);
@override
bool get newVariation =>
(super.noSuchMethod(Invocation.getter(#newVariation), returnValue: false) as bool);
@override
List<_i9.Muscle> get primaryMuscles =>
List<_i8.Muscle> get primaryMuscles =>
(super.noSuchMethod(
Invocation.getter(#primaryMuscles),
returnValue: <_i9.Muscle>[],
returnValue: <_i8.Muscle>[],
)
as List<_i9.Muscle>);
as List<_i8.Muscle>);
@override
List<_i9.Muscle> get secondaryMuscles =>
List<_i8.Muscle> get secondaryMuscles =>
(super.noSuchMethod(
Invocation.getter(#secondaryMuscles),
returnValue: <_i9.Muscle>[],
returnValue: <_i8.Muscle>[],
)
as List<_i9.Muscle>);
as List<_i8.Muscle>);
@override
_i10.ExerciseSubmissionApi get exerciseApiObject =>
_i9.ExerciseSubmissionApi get exerciseApiObject =>
(super.noSuchMethod(
Invocation.getter(#exerciseApiObject),
returnValue: _i7.dummyValue<_i10.ExerciseSubmissionApi>(
returnValue: _i6.dummyValue<_i9.ExerciseSubmissionApi>(
this,
Invocation.getter(#exerciseApiObject),
),
)
as _i10.ExerciseSubmissionApi);
as _i9.ExerciseSubmissionApi);
@override
set author(String? value) => super.noSuchMethod(
@@ -179,13 +174,13 @@ class MockAddExerciseProvider extends _i1.Mock implements _i5.AddExerciseProvide
);
@override
set languageEn(_i11.Language? value) => super.noSuchMethod(
set languageEn(_i10.Language? value) => super.noSuchMethod(
Invocation.setter(#languageEn, value),
returnValueForMissingStub: null,
);
@override
set languageTranslation(_i11.Language? value) => super.noSuchMethod(
set languageTranslation(_i10.Language? value) => super.noSuchMethod(
Invocation.setter(#languageTranslation, value),
returnValueForMissingStub: null,
);
@@ -203,13 +198,13 @@ class MockAddExerciseProvider extends _i1.Mock implements _i5.AddExerciseProvide
);
@override
set category(_i12.ExerciseCategory? value) => super.noSuchMethod(
set category(_i11.ExerciseCategory? value) => super.noSuchMethod(
Invocation.setter(#category, value),
returnValueForMissingStub: null,
);
@override
set equipment(List<_i8.Equipment>? equipment) => super.noSuchMethod(
set equipment(List<_i7.Equipment>? equipment) => super.noSuchMethod(
Invocation.setter(#equipment, equipment),
returnValueForMissingStub: null,
);
@@ -227,13 +222,13 @@ class MockAddExerciseProvider extends _i1.Mock implements _i5.AddExerciseProvide
);
@override
set primaryMuscles(List<_i9.Muscle>? muscles) => super.noSuchMethod(
set primaryMuscles(List<_i8.Muscle>? muscles) => super.noSuchMethod(
Invocation.setter(#primaryMuscles, muscles),
returnValueForMissingStub: null,
);
@override
set secondaryMuscles(List<_i9.Muscle>? muscles) => super.noSuchMethod(
set secondaryMuscles(List<_i8.Muscle>? muscles) => super.noSuchMethod(
Invocation.setter(#secondaryMuscles, muscles),
returnValueForMissingStub: null,
);
@@ -249,7 +244,7 @@ class MockAddExerciseProvider extends _i1.Mock implements _i5.AddExerciseProvide
);
@override
void addExerciseImages(List<_i6.ExerciseSubmissionImage>? images) => super.noSuchMethod(
void addExerciseImages(List<_i5.ExerciseSubmissionImage>? images) => super.noSuchMethod(
Invocation.method(#addExerciseImages, [images]),
returnValueForMissingStub: null,
);
@@ -261,46 +256,46 @@ class MockAddExerciseProvider extends _i1.Mock implements _i5.AddExerciseProvide
);
@override
_i13.Future<int> postExerciseToServer() =>
_i12.Future<int> postExerciseToServer() =>
(super.noSuchMethod(
Invocation.method(#postExerciseToServer, []),
returnValue: _i13.Future<int>.value(0),
returnValue: _i12.Future<int>.value(0),
)
as _i13.Future<int>);
as _i12.Future<int>);
@override
_i13.Future<int> addExerciseSubmission() =>
_i12.Future<int> addExerciseSubmission() =>
(super.noSuchMethod(
Invocation.method(#addExerciseSubmission, []),
returnValue: _i13.Future<int>.value(0),
returnValue: _i12.Future<int>.value(0),
)
as _i13.Future<int>);
as _i12.Future<int>);
@override
_i13.Future<void> addImages(int? exerciseId) =>
_i12.Future<void> addImages(int? exerciseId) =>
(super.noSuchMethod(
Invocation.method(#addImages, [exerciseId]),
returnValue: _i13.Future<void>.value(),
returnValueForMissingStub: _i13.Future<void>.value(),
returnValue: _i12.Future<void>.value(),
returnValueForMissingStub: _i12.Future<void>.value(),
)
as _i13.Future<void>);
as _i12.Future<void>);
@override
_i13.Future<bool> validateLanguage(String? input, String? languageCode) =>
_i12.Future<bool> validateLanguage(String? input, String? languageCode) =>
(super.noSuchMethod(
Invocation.method(#validateLanguage, [input, languageCode]),
returnValue: _i13.Future<bool>.value(false),
returnValue: _i12.Future<bool>.value(false),
)
as _i13.Future<bool>);
as _i12.Future<bool>);
@override
void addListener(_i14.VoidCallback? listener) => super.noSuchMethod(
void addListener(_i13.VoidCallback? listener) => super.noSuchMethod(
Invocation.method(#addListener, [listener]),
returnValueForMissingStub: null,
);
@override
void removeListener(_i14.VoidCallback? listener) => super.noSuchMethod(
void removeListener(_i13.VoidCallback? listener) => super.noSuchMethod(
Invocation.method(#removeListener, [listener]),
returnValueForMissingStub: null,
);
@@ -327,33 +322,30 @@ class MockWgerBaseProvider extends _i1.Mock implements _i2.WgerBaseProvider {
}
@override
_i3.AuthProvider get auth =>
(super.noSuchMethod(
Invocation.getter(#auth),
returnValue: _FakeAuthProvider_1(this, Invocation.getter(#auth)),
)
as _i3.AuthProvider);
@override
_i4.Client get client =>
_i3.Client get client =>
(super.noSuchMethod(
Invocation.getter(#client),
returnValue: _FakeClient_2(this, Invocation.getter(#client)),
returnValue: _FakeClient_1(this, Invocation.getter(#client)),
)
as _i4.Client);
as _i3.Client);
@override
set auth(_i3.AuthProvider? value) => super.noSuchMethod(
Invocation.setter(#auth, value),
returnValueForMissingStub: null,
);
@override
set client(_i4.Client? value) => super.noSuchMethod(
set client(_i3.Client? value) => super.noSuchMethod(
Invocation.setter(#client, value),
returnValueForMissingStub: null,
);
@override
String getAppNameHeaderValue() =>
(super.noSuchMethod(
Invocation.method(#getAppNameHeaderValue, []),
returnValue: _i6.dummyValue<String>(
this,
Invocation.method(#getAppNameHeaderValue, []),
),
)
as String);
@override
Map<String, String> getDefaultHeaders({
bool? includeAuth = false,
@@ -381,7 +373,7 @@ class MockWgerBaseProvider extends _i1.Mock implements _i2.WgerBaseProvider {
[path],
{#id: id, #objectMethod: objectMethod, #query: query},
),
returnValue: _FakeUri_3(
returnValue: _FakeUri_2(
this,
Invocation.method(
#makeUrl,
@@ -393,7 +385,7 @@ class MockWgerBaseProvider extends _i1.Mock implements _i2.WgerBaseProvider {
as Uri);
@override
_i13.Future<dynamic> fetch(
_i12.Future<dynamic> fetch(
Uri? uri, {
int? maxRetries = 3,
Duration? initialDelay = const Duration(milliseconds: 250),
@@ -411,12 +403,12 @@ class MockWgerBaseProvider extends _i1.Mock implements _i2.WgerBaseProvider {
#language: language,
},
),
returnValue: _i13.Future<dynamic>.value(),
returnValue: _i12.Future<dynamic>.value(),
)
as _i13.Future<dynamic>);
as _i12.Future<dynamic>);
@override
_i13.Future<List<dynamic>> fetchPaginated(
_i12.Future<List<dynamic>> fetchPaginated(
Uri? uri, {
String? language,
Duration? timeout = const Duration(seconds: 15),
@@ -427,46 +419,46 @@ class MockWgerBaseProvider extends _i1.Mock implements _i2.WgerBaseProvider {
[uri],
{#language: language, #timeout: timeout},
),
returnValue: _i13.Future<List<dynamic>>.value(<dynamic>[]),
returnValue: _i12.Future<List<dynamic>>.value(<dynamic>[]),
)
as _i13.Future<List<dynamic>>);
as _i12.Future<List<dynamic>>);
@override
_i13.Future<Map<String, dynamic>> post(
_i12.Future<Map<String, dynamic>> post(
Map<String, dynamic>? data,
Uri? uri,
) =>
(super.noSuchMethod(
Invocation.method(#post, [data, uri]),
returnValue: _i13.Future<Map<String, dynamic>>.value(
returnValue: _i12.Future<Map<String, dynamic>>.value(
<String, dynamic>{},
),
)
as _i13.Future<Map<String, dynamic>>);
as _i12.Future<Map<String, dynamic>>);
@override
_i13.Future<Map<String, dynamic>> patch(
_i12.Future<Map<String, dynamic>> patch(
Map<String, dynamic>? data,
Uri? uri,
) =>
(super.noSuchMethod(
Invocation.method(#patch, [data, uri]),
returnValue: _i13.Future<Map<String, dynamic>>.value(
returnValue: _i12.Future<Map<String, dynamic>>.value(
<String, dynamic>{},
),
)
as _i13.Future<Map<String, dynamic>>);
as _i12.Future<Map<String, dynamic>>);
@override
_i13.Future<_i4.Response> deleteRequest(String? url, int? id) =>
_i12.Future<_i3.Response> deleteRequest(String? url, int? id) =>
(super.noSuchMethod(
Invocation.method(#deleteRequest, [url, id]),
returnValue: _i13.Future<_i4.Response>.value(
_FakeResponse_4(
returnValue: _i12.Future<_i3.Response>.value(
_FakeResponse_3(
this,
Invocation.method(#deleteRequest, [url, id]),
),
),
)
as _i13.Future<_i4.Response>);
as _i12.Future<_i3.Response>);
}

View File

@@ -3,15 +3,15 @@
// Do not manually edit this file.
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i6;
import 'dart:async' as _i5;
import 'dart:ui' as _i8;
import 'package:http/http.dart' as _i3;
import 'package:image_picker/image_picker.dart' as _i7;
import 'package:http/http.dart' as _i2;
import 'package:image_picker/image_picker.dart' as _i6;
import 'package:mockito/mockito.dart' as _i1;
import 'package:wger/models/gallery/image.dart' as _i5;
import 'package:wger/providers/auth.dart' as _i2;
import 'package:wger/providers/gallery.dart' as _i4;
import 'package:mockito/src/dummies.dart' as _i7;
import 'package:wger/models/gallery/image.dart' as _i4;
import 'package:wger/providers/gallery.dart' as _i3;
// ignore_for_file: type=lint
// ignore_for_file: avoid_redundant_argument_values
@@ -28,68 +28,50 @@ import 'package:wger/providers/gallery.dart' as _i4;
// ignore_for_file: subtype_of_sealed_class
// ignore_for_file: invalid_use_of_internal_member
class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider {
_FakeAuthProvider_0(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeClient_0 extends _i1.SmartFake implements _i2.Client {
_FakeClient_0(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeClient_1 extends _i1.SmartFake implements _i3.Client {
_FakeClient_1(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeUri_1 extends _i1.SmartFake implements Uri {
_FakeUri_1(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeUri_2 extends _i1.SmartFake implements Uri {
_FakeUri_2(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeResponse_3 extends _i1.SmartFake implements _i3.Response {
_FakeResponse_3(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeResponse_2 extends _i1.SmartFake implements _i2.Response {
_FakeResponse_2(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
/// A class which mocks [GalleryProvider].
///
/// See the documentation for Mockito's code generation for more information.
class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
class MockGalleryProvider extends _i1.Mock implements _i3.GalleryProvider {
MockGalleryProvider() {
_i1.throwOnMissingStub(this);
}
@override
List<_i5.Image> get images =>
List<_i4.Image> get images =>
(super.noSuchMethod(
Invocation.getter(#images),
returnValue: <_i5.Image>[],
returnValue: <_i4.Image>[],
)
as List<_i5.Image>);
as List<_i4.Image>);
@override
set images(List<_i5.Image>? value) => super.noSuchMethod(
set images(List<_i4.Image>? value) => super.noSuchMethod(
Invocation.setter(#images, value),
returnValueForMissingStub: null,
);
@override
_i2.AuthProvider get auth =>
(super.noSuchMethod(
Invocation.getter(#auth),
returnValue: _FakeAuthProvider_0(this, Invocation.getter(#auth)),
)
as _i2.AuthProvider);
@override
_i3.Client get client =>
_i2.Client get client =>
(super.noSuchMethod(
Invocation.getter(#client),
returnValue: _FakeClient_1(this, Invocation.getter(#client)),
returnValue: _FakeClient_0(this, Invocation.getter(#client)),
)
as _i3.Client);
as _i2.Client);
@override
set auth(_i2.AuthProvider? value) => super.noSuchMethod(
Invocation.setter(#auth, value),
returnValueForMissingStub: null,
);
@override
set client(_i3.Client? value) => super.noSuchMethod(
set client(_i2.Client? value) => super.noSuchMethod(
Invocation.setter(#client, value),
returnValueForMissingStub: null,
);
@@ -105,40 +87,51 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
);
@override
_i6.Future<void> fetchAndSetGallery() =>
_i5.Future<void> fetchAndSetGallery() =>
(super.noSuchMethod(
Invocation.method(#fetchAndSetGallery, []),
returnValue: _i6.Future<void>.value(),
returnValueForMissingStub: _i6.Future<void>.value(),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
)
as _i6.Future<void>);
as _i5.Future<void>);
@override
_i6.Future<void> addImage(_i5.Image? image, _i7.XFile? imageFile) =>
_i5.Future<void> addImage(_i4.Image? image, _i6.XFile? imageFile) =>
(super.noSuchMethod(
Invocation.method(#addImage, [image, imageFile]),
returnValue: _i6.Future<void>.value(),
returnValueForMissingStub: _i6.Future<void>.value(),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
)
as _i6.Future<void>);
as _i5.Future<void>);
@override
_i6.Future<void> editImage(_i5.Image? image, _i7.XFile? imageFile) =>
_i5.Future<void> editImage(_i4.Image? image, _i6.XFile? imageFile) =>
(super.noSuchMethod(
Invocation.method(#editImage, [image, imageFile]),
returnValue: _i6.Future<void>.value(),
returnValueForMissingStub: _i6.Future<void>.value(),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
)
as _i6.Future<void>);
as _i5.Future<void>);
@override
_i6.Future<void> deleteImage(_i5.Image? image) =>
_i5.Future<void> deleteImage(_i4.Image? image) =>
(super.noSuchMethod(
Invocation.method(#deleteImage, [image]),
returnValue: _i6.Future<void>.value(),
returnValueForMissingStub: _i6.Future<void>.value(),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
)
as _i6.Future<void>);
as _i5.Future<void>);
@override
String getAppNameHeaderValue() =>
(super.noSuchMethod(
Invocation.method(#getAppNameHeaderValue, []),
returnValue: _i7.dummyValue<String>(
this,
Invocation.method(#getAppNameHeaderValue, []),
),
)
as String);
@override
Map<String, String> getDefaultHeaders({
@@ -167,7 +160,7 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
[path],
{#id: id, #objectMethod: objectMethod, #query: query},
),
returnValue: _FakeUri_2(
returnValue: _FakeUri_1(
this,
Invocation.method(
#makeUrl,
@@ -179,7 +172,7 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
as Uri);
@override
_i6.Future<dynamic> fetch(
_i5.Future<dynamic> fetch(
Uri? uri, {
int? maxRetries = 3,
Duration? initialDelay = const Duration(milliseconds: 250),
@@ -197,12 +190,12 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
#language: language,
},
),
returnValue: _i6.Future<dynamic>.value(),
returnValue: _i5.Future<dynamic>.value(),
)
as _i6.Future<dynamic>);
as _i5.Future<dynamic>);
@override
_i6.Future<List<dynamic>> fetchPaginated(
_i5.Future<List<dynamic>> fetchPaginated(
Uri? uri, {
String? language,
Duration? timeout = const Duration(seconds: 15),
@@ -213,45 +206,45 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
[uri],
{#language: language, #timeout: timeout},
),
returnValue: _i6.Future<List<dynamic>>.value(<dynamic>[]),
returnValue: _i5.Future<List<dynamic>>.value(<dynamic>[]),
)
as _i6.Future<List<dynamic>>);
as _i5.Future<List<dynamic>>);
@override
_i6.Future<Map<String, dynamic>> post(Map<String, dynamic>? data, Uri? uri) =>
_i5.Future<Map<String, dynamic>> post(Map<String, dynamic>? data, Uri? uri) =>
(super.noSuchMethod(
Invocation.method(#post, [data, uri]),
returnValue: _i6.Future<Map<String, dynamic>>.value(
returnValue: _i5.Future<Map<String, dynamic>>.value(
<String, dynamic>{},
),
)
as _i6.Future<Map<String, dynamic>>);
as _i5.Future<Map<String, dynamic>>);
@override
_i6.Future<Map<String, dynamic>> patch(
_i5.Future<Map<String, dynamic>> patch(
Map<String, dynamic>? data,
Uri? uri,
) =>
(super.noSuchMethod(
Invocation.method(#patch, [data, uri]),
returnValue: _i6.Future<Map<String, dynamic>>.value(
returnValue: _i5.Future<Map<String, dynamic>>.value(
<String, dynamic>{},
),
)
as _i6.Future<Map<String, dynamic>>);
as _i5.Future<Map<String, dynamic>>);
@override
_i6.Future<_i3.Response> deleteRequest(String? url, int? id) =>
_i5.Future<_i2.Response> deleteRequest(String? url, int? id) =>
(super.noSuchMethod(
Invocation.method(#deleteRequest, [url, id]),
returnValue: _i6.Future<_i3.Response>.value(
_FakeResponse_3(
returnValue: _i5.Future<_i2.Response>.value(
_FakeResponse_2(
this,
Invocation.method(#deleteRequest, [url, id]),
),
),
)
as _i6.Future<_i3.Response>);
as _i5.Future<_i2.Response>);
@override
void addListener(_i8.VoidCallback? listener) => super.noSuchMethod(

View File

@@ -23,7 +23,6 @@ import 'package:wger/models/gallery/image.dart' as gallery;
import 'package:wger/providers/gallery.dart';
import '../other/base_provider_test.mocks.dart';
import '../utils.dart';
void main() {
group('test gallery provider', () {
@@ -47,7 +46,11 @@ void main() {
),
);
final galleryProvider = GalleryProvider(testAuthProvider, [], client);
final galleryProvider = GalleryProvider(
serverUrl: 'https://localhost',
token: 'FooBar',
client: client,
);
await galleryProvider.fetchAndSetGallery();
@@ -74,7 +77,11 @@ void main() {
),
);
final galleryProvider = GalleryProvider(testAuthProvider, [], client);
final galleryProvider = GalleryProvider(
serverUrl: 'https://localhost',
token: 'FooBar',
client: client,
);
final image = gallery.Image(
id: 58,

View File

@@ -3,15 +3,15 @@
// Do not manually edit this file.
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i6;
import 'dart:async' as _i5;
import 'dart:ui' as _i8;
import 'package:http/http.dart' as _i3;
import 'package:image_picker/image_picker.dart' as _i7;
import 'package:http/http.dart' as _i2;
import 'package:image_picker/image_picker.dart' as _i6;
import 'package:mockito/mockito.dart' as _i1;
import 'package:wger/models/gallery/image.dart' as _i5;
import 'package:wger/providers/auth.dart' as _i2;
import 'package:wger/providers/gallery.dart' as _i4;
import 'package:mockito/src/dummies.dart' as _i7;
import 'package:wger/models/gallery/image.dart' as _i4;
import 'package:wger/providers/gallery.dart' as _i3;
// ignore_for_file: type=lint
// ignore_for_file: avoid_redundant_argument_values
@@ -28,68 +28,50 @@ import 'package:wger/providers/gallery.dart' as _i4;
// ignore_for_file: subtype_of_sealed_class
// ignore_for_file: invalid_use_of_internal_member
class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider {
_FakeAuthProvider_0(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeClient_0 extends _i1.SmartFake implements _i2.Client {
_FakeClient_0(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeClient_1 extends _i1.SmartFake implements _i3.Client {
_FakeClient_1(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeUri_1 extends _i1.SmartFake implements Uri {
_FakeUri_1(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeUri_2 extends _i1.SmartFake implements Uri {
_FakeUri_2(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeResponse_3 extends _i1.SmartFake implements _i3.Response {
_FakeResponse_3(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeResponse_2 extends _i1.SmartFake implements _i2.Response {
_FakeResponse_2(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
/// A class which mocks [GalleryProvider].
///
/// See the documentation for Mockito's code generation for more information.
class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
class MockGalleryProvider extends _i1.Mock implements _i3.GalleryProvider {
MockGalleryProvider() {
_i1.throwOnMissingStub(this);
}
@override
List<_i5.Image> get images =>
List<_i4.Image> get images =>
(super.noSuchMethod(
Invocation.getter(#images),
returnValue: <_i5.Image>[],
returnValue: <_i4.Image>[],
)
as List<_i5.Image>);
as List<_i4.Image>);
@override
set images(List<_i5.Image>? value) => super.noSuchMethod(
set images(List<_i4.Image>? value) => super.noSuchMethod(
Invocation.setter(#images, value),
returnValueForMissingStub: null,
);
@override
_i2.AuthProvider get auth =>
(super.noSuchMethod(
Invocation.getter(#auth),
returnValue: _FakeAuthProvider_0(this, Invocation.getter(#auth)),
)
as _i2.AuthProvider);
@override
_i3.Client get client =>
_i2.Client get client =>
(super.noSuchMethod(
Invocation.getter(#client),
returnValue: _FakeClient_1(this, Invocation.getter(#client)),
returnValue: _FakeClient_0(this, Invocation.getter(#client)),
)
as _i3.Client);
as _i2.Client);
@override
set auth(_i2.AuthProvider? value) => super.noSuchMethod(
Invocation.setter(#auth, value),
returnValueForMissingStub: null,
);
@override
set client(_i3.Client? value) => super.noSuchMethod(
set client(_i2.Client? value) => super.noSuchMethod(
Invocation.setter(#client, value),
returnValueForMissingStub: null,
);
@@ -105,40 +87,51 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
);
@override
_i6.Future<void> fetchAndSetGallery() =>
_i5.Future<void> fetchAndSetGallery() =>
(super.noSuchMethod(
Invocation.method(#fetchAndSetGallery, []),
returnValue: _i6.Future<void>.value(),
returnValueForMissingStub: _i6.Future<void>.value(),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
)
as _i6.Future<void>);
as _i5.Future<void>);
@override
_i6.Future<void> addImage(_i5.Image? image, _i7.XFile? imageFile) =>
_i5.Future<void> addImage(_i4.Image? image, _i6.XFile? imageFile) =>
(super.noSuchMethod(
Invocation.method(#addImage, [image, imageFile]),
returnValue: _i6.Future<void>.value(),
returnValueForMissingStub: _i6.Future<void>.value(),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
)
as _i6.Future<void>);
as _i5.Future<void>);
@override
_i6.Future<void> editImage(_i5.Image? image, _i7.XFile? imageFile) =>
_i5.Future<void> editImage(_i4.Image? image, _i6.XFile? imageFile) =>
(super.noSuchMethod(
Invocation.method(#editImage, [image, imageFile]),
returnValue: _i6.Future<void>.value(),
returnValueForMissingStub: _i6.Future<void>.value(),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
)
as _i6.Future<void>);
as _i5.Future<void>);
@override
_i6.Future<void> deleteImage(_i5.Image? image) =>
_i5.Future<void> deleteImage(_i4.Image? image) =>
(super.noSuchMethod(
Invocation.method(#deleteImage, [image]),
returnValue: _i6.Future<void>.value(),
returnValueForMissingStub: _i6.Future<void>.value(),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
)
as _i6.Future<void>);
as _i5.Future<void>);
@override
String getAppNameHeaderValue() =>
(super.noSuchMethod(
Invocation.method(#getAppNameHeaderValue, []),
returnValue: _i7.dummyValue<String>(
this,
Invocation.method(#getAppNameHeaderValue, []),
),
)
as String);
@override
Map<String, String> getDefaultHeaders({
@@ -167,7 +160,7 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
[path],
{#id: id, #objectMethod: objectMethod, #query: query},
),
returnValue: _FakeUri_2(
returnValue: _FakeUri_1(
this,
Invocation.method(
#makeUrl,
@@ -179,7 +172,7 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
as Uri);
@override
_i6.Future<dynamic> fetch(
_i5.Future<dynamic> fetch(
Uri? uri, {
int? maxRetries = 3,
Duration? initialDelay = const Duration(milliseconds: 250),
@@ -197,12 +190,12 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
#language: language,
},
),
returnValue: _i6.Future<dynamic>.value(),
returnValue: _i5.Future<dynamic>.value(),
)
as _i6.Future<dynamic>);
as _i5.Future<dynamic>);
@override
_i6.Future<List<dynamic>> fetchPaginated(
_i5.Future<List<dynamic>> fetchPaginated(
Uri? uri, {
String? language,
Duration? timeout = const Duration(seconds: 15),
@@ -213,45 +206,45 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
[uri],
{#language: language, #timeout: timeout},
),
returnValue: _i6.Future<List<dynamic>>.value(<dynamic>[]),
returnValue: _i5.Future<List<dynamic>>.value(<dynamic>[]),
)
as _i6.Future<List<dynamic>>);
as _i5.Future<List<dynamic>>);
@override
_i6.Future<Map<String, dynamic>> post(Map<String, dynamic>? data, Uri? uri) =>
_i5.Future<Map<String, dynamic>> post(Map<String, dynamic>? data, Uri? uri) =>
(super.noSuchMethod(
Invocation.method(#post, [data, uri]),
returnValue: _i6.Future<Map<String, dynamic>>.value(
returnValue: _i5.Future<Map<String, dynamic>>.value(
<String, dynamic>{},
),
)
as _i6.Future<Map<String, dynamic>>);
as _i5.Future<Map<String, dynamic>>);
@override
_i6.Future<Map<String, dynamic>> patch(
_i5.Future<Map<String, dynamic>> patch(
Map<String, dynamic>? data,
Uri? uri,
) =>
(super.noSuchMethod(
Invocation.method(#patch, [data, uri]),
returnValue: _i6.Future<Map<String, dynamic>>.value(
returnValue: _i5.Future<Map<String, dynamic>>.value(
<String, dynamic>{},
),
)
as _i6.Future<Map<String, dynamic>>);
as _i5.Future<Map<String, dynamic>>);
@override
_i6.Future<_i3.Response> deleteRequest(String? url, int? id) =>
_i5.Future<_i2.Response> deleteRequest(String? url, int? id) =>
(super.noSuchMethod(
Invocation.method(#deleteRequest, [url, id]),
returnValue: _i6.Future<_i3.Response>.value(
_FakeResponse_3(
returnValue: _i5.Future<_i2.Response>.value(
_FakeResponse_2(
this,
Invocation.method(#deleteRequest, [url, id]),
),
),
)
as _i6.Future<_i3.Response>);
as _i5.Future<_i2.Response>);
@override
void addListener(_i8.VoidCallback? listener) => super.noSuchMethod(

View File

@@ -5,10 +5,10 @@
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i5;
import 'package:http/http.dart' as _i3;
import 'package:http/http.dart' as _i2;
import 'package:mockito/mockito.dart' as _i1;
import 'package:wger/providers/auth.dart' as _i2;
import 'package:wger/providers/base_provider.dart' as _i4;
import 'package:mockito/src/dummies.dart' as _i4;
import 'package:wger/providers/base_provider.dart' as _i3;
// ignore_for_file: type=lint
// ignore_for_file: avoid_redundant_argument_values
@@ -25,58 +25,51 @@ import 'package:wger/providers/base_provider.dart' as _i4;
// ignore_for_file: subtype_of_sealed_class
// ignore_for_file: invalid_use_of_internal_member
class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider {
_FakeAuthProvider_0(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeClient_0 extends _i1.SmartFake implements _i2.Client {
_FakeClient_0(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeClient_1 extends _i1.SmartFake implements _i3.Client {
_FakeClient_1(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeUri_1 extends _i1.SmartFake implements Uri {
_FakeUri_1(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeUri_2 extends _i1.SmartFake implements Uri {
_FakeUri_2(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeResponse_3 extends _i1.SmartFake implements _i3.Response {
_FakeResponse_3(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeResponse_2 extends _i1.SmartFake implements _i2.Response {
_FakeResponse_2(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
/// A class which mocks [WgerBaseProvider].
///
/// See the documentation for Mockito's code generation for more information.
class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
class MockWgerBaseProvider extends _i1.Mock implements _i3.WgerBaseProvider {
MockWgerBaseProvider() {
_i1.throwOnMissingStub(this);
}
@override
_i2.AuthProvider get auth =>
(super.noSuchMethod(
Invocation.getter(#auth),
returnValue: _FakeAuthProvider_0(this, Invocation.getter(#auth)),
)
as _i2.AuthProvider);
@override
_i3.Client get client =>
_i2.Client get client =>
(super.noSuchMethod(
Invocation.getter(#client),
returnValue: _FakeClient_1(this, Invocation.getter(#client)),
returnValue: _FakeClient_0(this, Invocation.getter(#client)),
)
as _i3.Client);
as _i2.Client);
@override
set auth(_i2.AuthProvider? value) => super.noSuchMethod(
Invocation.setter(#auth, value),
returnValueForMissingStub: null,
);
@override
set client(_i3.Client? value) => super.noSuchMethod(
set client(_i2.Client? value) => super.noSuchMethod(
Invocation.setter(#client, value),
returnValueForMissingStub: null,
);
@override
String getAppNameHeaderValue() =>
(super.noSuchMethod(
Invocation.method(#getAppNameHeaderValue, []),
returnValue: _i4.dummyValue<String>(
this,
Invocation.method(#getAppNameHeaderValue, []),
),
)
as String);
@override
Map<String, String> getDefaultHeaders({
bool? includeAuth = false,
@@ -104,7 +97,7 @@ class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
[path],
{#id: id, #objectMethod: objectMethod, #query: query},
),
returnValue: _FakeUri_2(
returnValue: _FakeUri_1(
this,
Invocation.method(
#makeUrl,
@@ -178,15 +171,15 @@ class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
as _i5.Future<Map<String, dynamic>>);
@override
_i5.Future<_i3.Response> deleteRequest(String? url, int? id) =>
_i5.Future<_i2.Response> deleteRequest(String? url, int? id) =>
(super.noSuchMethod(
Invocation.method(#deleteRequest, [url, id]),
returnValue: _i5.Future<_i3.Response>.value(
_FakeResponse_3(
returnValue: _i5.Future<_i2.Response>.value(
_FakeResponse_2(
this,
Invocation.method(#deleteRequest, [url, id]),
),
),
)
as _i5.Future<_i3.Response>);
as _i5.Future<_i2.Response>);
}

View File

@@ -30,7 +30,6 @@ import 'package:provider/provider.dart';
import 'package:wger/database/ingredients/ingredients_database.dart';
import 'package:wger/l10n/generated/app_localizations.dart';
import 'package:wger/models/nutrition/nutritional_plan.dart';
import 'package:wger/providers/auth.dart';
import 'package:wger/providers/base_provider.dart';
import 'package:wger/providers/body_weight_repository.dart';
import 'package:wger/providers/nutrition.dart';
@@ -40,7 +39,7 @@ import '../../test_data/body_weight.dart';
import '../../test_data/nutritional_plans.dart';
import 'nutritional_plan_screen_test.mocks.dart';
@GenerateMocks([WgerBaseProvider, AuthProvider, http.Client, BodyWeightRepository])
@GenerateMocks([WgerBaseProvider, http.Client, BodyWeightRepository])
void main() {
late IngredientDatabase database;
late BodyWeightRepository mockRepository;
@@ -73,9 +72,6 @@ void main() {
database: database,
),
),
ChangeNotifierProvider<AuthProvider>(
create: (context) => AuthProvider(),
),
],
child: MaterialApp(
key: GlobalKey(),

View File

@@ -4,18 +4,15 @@
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i5;
import 'dart:convert' as _i9;
import 'dart:typed_data' as _i10;
import 'dart:ui' as _i8;
import 'dart:convert' as _i6;
import 'dart:typed_data' as _i7;
import 'package:http/http.dart' as _i3;
import 'package:http/http.dart' as _i2;
import 'package:mockito/mockito.dart' as _i1;
import 'package:mockito/src/dummies.dart' as _i7;
import 'package:package_info_plus/package_info_plus.dart' as _i6;
import 'package:wger/models/body_weight/weight_entry.dart' as _i12;
import 'package:wger/providers/auth.dart' as _i2;
import 'package:wger/providers/base_provider.dart' as _i4;
import 'package:wger/providers/body_weight_repository.dart' as _i11;
import 'package:mockito/src/dummies.dart' as _i4;
import 'package:wger/models/body_weight/weight_entry.dart' as _i9;
import 'package:wger/providers/base_provider.dart' as _i3;
import 'package:wger/providers/body_weight_repository.dart' as _i8;
// ignore_for_file: type=lint
// ignore_for_file: avoid_redundant_argument_values
@@ -32,63 +29,56 @@ import 'package:wger/providers/body_weight_repository.dart' as _i11;
// ignore_for_file: subtype_of_sealed_class
// ignore_for_file: invalid_use_of_internal_member
class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider {
_FakeAuthProvider_0(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeClient_0 extends _i1.SmartFake implements _i2.Client {
_FakeClient_0(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeClient_1 extends _i1.SmartFake implements _i3.Client {
_FakeClient_1(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeUri_1 extends _i1.SmartFake implements Uri {
_FakeUri_1(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeUri_2 extends _i1.SmartFake implements Uri {
_FakeUri_2(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeResponse_2 extends _i1.SmartFake implements _i2.Response {
_FakeResponse_2(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeResponse_3 extends _i1.SmartFake implements _i3.Response {
_FakeResponse_3(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeStreamedResponse_4 extends _i1.SmartFake implements _i3.StreamedResponse {
_FakeStreamedResponse_4(Object parent, Invocation parentInvocation)
class _FakeStreamedResponse_3 extends _i1.SmartFake implements _i2.StreamedResponse {
_FakeStreamedResponse_3(Object parent, Invocation parentInvocation)
: super(parent, parentInvocation);
}
/// A class which mocks [WgerBaseProvider].
///
/// See the documentation for Mockito's code generation for more information.
class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
class MockWgerBaseProvider extends _i1.Mock implements _i3.WgerBaseProvider {
MockWgerBaseProvider() {
_i1.throwOnMissingStub(this);
}
@override
_i2.AuthProvider get auth =>
(super.noSuchMethod(
Invocation.getter(#auth),
returnValue: _FakeAuthProvider_0(this, Invocation.getter(#auth)),
)
as _i2.AuthProvider);
@override
_i3.Client get client =>
_i2.Client get client =>
(super.noSuchMethod(
Invocation.getter(#client),
returnValue: _FakeClient_1(this, Invocation.getter(#client)),
returnValue: _FakeClient_0(this, Invocation.getter(#client)),
)
as _i3.Client);
as _i2.Client);
@override
set auth(_i2.AuthProvider? value) => super.noSuchMethod(
Invocation.setter(#auth, value),
returnValueForMissingStub: null,
);
@override
set client(_i3.Client? value) => super.noSuchMethod(
set client(_i2.Client? value) => super.noSuchMethod(
Invocation.setter(#client, value),
returnValueForMissingStub: null,
);
@override
String getAppNameHeaderValue() =>
(super.noSuchMethod(
Invocation.method(#getAppNameHeaderValue, []),
returnValue: _i4.dummyValue<String>(
this,
Invocation.method(#getAppNameHeaderValue, []),
),
)
as String);
@override
Map<String, String> getDefaultHeaders({
bool? includeAuth = false,
@@ -116,7 +106,7 @@ class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
[path],
{#id: id, #objectMethod: objectMethod, #query: query},
),
returnValue: _FakeUri_2(
returnValue: _FakeUri_1(
this,
Invocation.method(
#makeUrl,
@@ -190,302 +180,59 @@ class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
as _i5.Future<Map<String, dynamic>>);
@override
_i5.Future<_i3.Response> deleteRequest(String? url, int? id) =>
_i5.Future<_i2.Response> deleteRequest(String? url, int? id) =>
(super.noSuchMethod(
Invocation.method(#deleteRequest, [url, id]),
returnValue: _i5.Future<_i3.Response>.value(
_FakeResponse_3(
returnValue: _i5.Future<_i2.Response>.value(
_FakeResponse_2(
this,
Invocation.method(#deleteRequest, [url, id]),
),
),
)
as _i5.Future<_i3.Response>);
}
/// A class which mocks [AuthProvider].
///
/// See the documentation for Mockito's code generation for more information.
class MockAuthProvider extends _i1.Mock implements _i2.AuthProvider {
MockAuthProvider() {
_i1.throwOnMissingStub(this);
}
@override
Map<String, String> get metadata =>
(super.noSuchMethod(
Invocation.getter(#metadata),
returnValue: <String, String>{},
)
as Map<String, String>);
@override
_i2.AuthState get state =>
(super.noSuchMethod(
Invocation.getter(#state),
returnValue: _i2.AuthState.updateRequired,
)
as _i2.AuthState);
@override
_i3.Client get client =>
(super.noSuchMethod(
Invocation.getter(#client),
returnValue: _FakeClient_1(this, Invocation.getter(#client)),
)
as _i3.Client);
@override
bool get dataInit =>
(super.noSuchMethod(Invocation.getter(#dataInit), returnValue: false) as bool);
@override
bool get isAuth => (super.noSuchMethod(Invocation.getter(#isAuth), returnValue: false) as bool);
@override
set token(String? value) => super.noSuchMethod(
Invocation.setter(#token, value),
returnValueForMissingStub: null,
);
@override
set serverUrl(String? value) => super.noSuchMethod(
Invocation.setter(#serverUrl, value),
returnValueForMissingStub: null,
);
@override
set serverVersion(String? value) => super.noSuchMethod(
Invocation.setter(#serverVersion, value),
returnValueForMissingStub: null,
);
@override
set applicationVersion(_i6.PackageInfo? value) => super.noSuchMethod(
Invocation.setter(#applicationVersion, value),
returnValueForMissingStub: null,
);
@override
set metadata(Map<String, String>? value) => super.noSuchMethod(
Invocation.setter(#metadata, value),
returnValueForMissingStub: null,
);
@override
set state(_i2.AuthState? value) => super.noSuchMethod(
Invocation.setter(#state, value),
returnValueForMissingStub: null,
);
@override
set client(_i3.Client? value) => super.noSuchMethod(
Invocation.setter(#client, value),
returnValueForMissingStub: null,
);
@override
set dataInit(bool? value) => super.noSuchMethod(
Invocation.setter(#dataInit, value),
returnValueForMissingStub: null,
);
@override
bool get hasListeners =>
(super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false) as bool);
@override
_i5.Future<void> setServerVersion() =>
(super.noSuchMethod(
Invocation.method(#setServerVersion, []),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
)
as _i5.Future<void>);
@override
_i5.Future<void> setApplicationVersion() =>
(super.noSuchMethod(
Invocation.method(#setApplicationVersion, []),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
)
as _i5.Future<void>);
@override
_i5.Future<void> initVersions(String? serverUrl) =>
(super.noSuchMethod(
Invocation.method(#initVersions, [serverUrl]),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
)
as _i5.Future<void>);
@override
_i5.Future<bool> applicationUpdateRequired([String? version]) =>
(super.noSuchMethod(
Invocation.method(#applicationUpdateRequired, [version]),
returnValue: _i5.Future<bool>.value(false),
)
as _i5.Future<bool>);
@override
bool serverUpdateRequired([String? version]) =>
(super.noSuchMethod(
Invocation.method(#serverUpdateRequired, [version]),
returnValue: false,
)
as bool);
@override
_i5.Future<_i2.LoginActions> register({
required String? username,
required String? password,
required String? email,
required String? serverUrl,
String? locale = 'en',
}) =>
(super.noSuchMethod(
Invocation.method(#register, [], {
#username: username,
#password: password,
#email: email,
#serverUrl: serverUrl,
#locale: locale,
}),
returnValue: _i5.Future<_i2.LoginActions>.value(
_i2.LoginActions.update,
),
)
as _i5.Future<_i2.LoginActions>);
@override
_i5.Future<_i2.LoginActions> login(
String? username,
String? password,
String? serverUrl,
String? apiToken,
) =>
(super.noSuchMethod(
Invocation.method(#login, [
username,
password,
serverUrl,
apiToken,
]),
returnValue: _i5.Future<_i2.LoginActions>.value(
_i2.LoginActions.update,
),
)
as _i5.Future<_i2.LoginActions>);
@override
_i5.Future<String> getServerUrlFromPrefs() =>
(super.noSuchMethod(
Invocation.method(#getServerUrlFromPrefs, []),
returnValue: _i5.Future<String>.value(
_i7.dummyValue<String>(
this,
Invocation.method(#getServerUrlFromPrefs, []),
),
),
)
as _i5.Future<String>);
@override
_i5.Future<void> tryAutoLogin() =>
(super.noSuchMethod(
Invocation.method(#tryAutoLogin, []),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
)
as _i5.Future<void>);
@override
_i5.Future<void> logout({bool? shouldNotify = true}) =>
(super.noSuchMethod(
Invocation.method(#logout, [], {#shouldNotify: shouldNotify}),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
)
as _i5.Future<void>);
@override
String getAppNameHeader() =>
(super.noSuchMethod(
Invocation.method(#getAppNameHeader, []),
returnValue: _i7.dummyValue<String>(
this,
Invocation.method(#getAppNameHeader, []),
),
)
as String);
@override
void addListener(_i8.VoidCallback? listener) => super.noSuchMethod(
Invocation.method(#addListener, [listener]),
returnValueForMissingStub: null,
);
@override
void removeListener(_i8.VoidCallback? listener) => super.noSuchMethod(
Invocation.method(#removeListener, [listener]),
returnValueForMissingStub: null,
);
@override
void dispose() => super.noSuchMethod(
Invocation.method(#dispose, []),
returnValueForMissingStub: null,
);
@override
void notifyListeners() => super.noSuchMethod(
Invocation.method(#notifyListeners, []),
returnValueForMissingStub: null,
);
as _i5.Future<_i2.Response>);
}
/// A class which mocks [Client].
///
/// See the documentation for Mockito's code generation for more information.
class MockClient extends _i1.Mock implements _i3.Client {
class MockClient extends _i1.Mock implements _i2.Client {
MockClient() {
_i1.throwOnMissingStub(this);
}
@override
_i5.Future<_i3.Response> head(Uri? url, {Map<String, String>? headers}) =>
_i5.Future<_i2.Response> head(Uri? url, {Map<String, String>? headers}) =>
(super.noSuchMethod(
Invocation.method(#head, [url], {#headers: headers}),
returnValue: _i5.Future<_i3.Response>.value(
_FakeResponse_3(
returnValue: _i5.Future<_i2.Response>.value(
_FakeResponse_2(
this,
Invocation.method(#head, [url], {#headers: headers}),
),
),
)
as _i5.Future<_i3.Response>);
as _i5.Future<_i2.Response>);
@override
_i5.Future<_i3.Response> get(Uri? url, {Map<String, String>? headers}) =>
_i5.Future<_i2.Response> get(Uri? url, {Map<String, String>? headers}) =>
(super.noSuchMethod(
Invocation.method(#get, [url], {#headers: headers}),
returnValue: _i5.Future<_i3.Response>.value(
_FakeResponse_3(
returnValue: _i5.Future<_i2.Response>.value(
_FakeResponse_2(
this,
Invocation.method(#get, [url], {#headers: headers}),
),
),
)
as _i5.Future<_i3.Response>);
as _i5.Future<_i2.Response>);
@override
_i5.Future<_i3.Response> post(
_i5.Future<_i2.Response> post(
Uri? url, {
Map<String, String>? headers,
Object? body,
_i9.Encoding? encoding,
_i6.Encoding? encoding,
}) =>
(super.noSuchMethod(
Invocation.method(
@@ -493,8 +240,8 @@ class MockClient extends _i1.Mock implements _i3.Client {
[url],
{#headers: headers, #body: body, #encoding: encoding},
),
returnValue: _i5.Future<_i3.Response>.value(
_FakeResponse_3(
returnValue: _i5.Future<_i2.Response>.value(
_FakeResponse_2(
this,
Invocation.method(
#post,
@@ -504,14 +251,14 @@ class MockClient extends _i1.Mock implements _i3.Client {
),
),
)
as _i5.Future<_i3.Response>);
as _i5.Future<_i2.Response>);
@override
_i5.Future<_i3.Response> put(
_i5.Future<_i2.Response> put(
Uri? url, {
Map<String, String>? headers,
Object? body,
_i9.Encoding? encoding,
_i6.Encoding? encoding,
}) =>
(super.noSuchMethod(
Invocation.method(
@@ -519,8 +266,8 @@ class MockClient extends _i1.Mock implements _i3.Client {
[url],
{#headers: headers, #body: body, #encoding: encoding},
),
returnValue: _i5.Future<_i3.Response>.value(
_FakeResponse_3(
returnValue: _i5.Future<_i2.Response>.value(
_FakeResponse_2(
this,
Invocation.method(
#put,
@@ -530,14 +277,14 @@ class MockClient extends _i1.Mock implements _i3.Client {
),
),
)
as _i5.Future<_i3.Response>);
as _i5.Future<_i2.Response>);
@override
_i5.Future<_i3.Response> patch(
_i5.Future<_i2.Response> patch(
Uri? url, {
Map<String, String>? headers,
Object? body,
_i9.Encoding? encoding,
_i6.Encoding? encoding,
}) =>
(super.noSuchMethod(
Invocation.method(
@@ -545,8 +292,8 @@ class MockClient extends _i1.Mock implements _i3.Client {
[url],
{#headers: headers, #body: body, #encoding: encoding},
),
returnValue: _i5.Future<_i3.Response>.value(
_FakeResponse_3(
returnValue: _i5.Future<_i2.Response>.value(
_FakeResponse_2(
this,
Invocation.method(
#patch,
@@ -556,14 +303,14 @@ class MockClient extends _i1.Mock implements _i3.Client {
),
),
)
as _i5.Future<_i3.Response>);
as _i5.Future<_i2.Response>);
@override
_i5.Future<_i3.Response> delete(
_i5.Future<_i2.Response> delete(
Uri? url, {
Map<String, String>? headers,
Object? body,
_i9.Encoding? encoding,
_i6.Encoding? encoding,
}) =>
(super.noSuchMethod(
Invocation.method(
@@ -571,8 +318,8 @@ class MockClient extends _i1.Mock implements _i3.Client {
[url],
{#headers: headers, #body: body, #encoding: encoding},
),
returnValue: _i5.Future<_i3.Response>.value(
_FakeResponse_3(
returnValue: _i5.Future<_i2.Response>.value(
_FakeResponse_2(
this,
Invocation.method(
#delete,
@@ -582,14 +329,14 @@ class MockClient extends _i1.Mock implements _i3.Client {
),
),
)
as _i5.Future<_i3.Response>);
as _i5.Future<_i2.Response>);
@override
_i5.Future<String> read(Uri? url, {Map<String, String>? headers}) =>
(super.noSuchMethod(
Invocation.method(#read, [url], {#headers: headers}),
returnValue: _i5.Future<String>.value(
_i7.dummyValue<String>(
_i4.dummyValue<String>(
this,
Invocation.method(#read, [url], {#headers: headers}),
),
@@ -598,28 +345,28 @@ class MockClient extends _i1.Mock implements _i3.Client {
as _i5.Future<String>);
@override
_i5.Future<_i10.Uint8List> readBytes(
_i5.Future<_i7.Uint8List> readBytes(
Uri? url, {
Map<String, String>? headers,
}) =>
(super.noSuchMethod(
Invocation.method(#readBytes, [url], {#headers: headers}),
returnValue: _i5.Future<_i10.Uint8List>.value(_i10.Uint8List(0)),
returnValue: _i5.Future<_i7.Uint8List>.value(_i7.Uint8List(0)),
)
as _i5.Future<_i10.Uint8List>);
as _i5.Future<_i7.Uint8List>);
@override
_i5.Future<_i3.StreamedResponse> send(_i3.BaseRequest? request) =>
_i5.Future<_i2.StreamedResponse> send(_i2.BaseRequest? request) =>
(super.noSuchMethod(
Invocation.method(#send, [request]),
returnValue: _i5.Future<_i3.StreamedResponse>.value(
_FakeStreamedResponse_4(
returnValue: _i5.Future<_i2.StreamedResponse>.value(
_FakeStreamedResponse_3(
this,
Invocation.method(#send, [request]),
),
),
)
as _i5.Future<_i3.StreamedResponse>);
as _i5.Future<_i2.StreamedResponse>);
@override
void close() => super.noSuchMethod(
@@ -631,18 +378,18 @@ class MockClient extends _i1.Mock implements _i3.Client {
/// A class which mocks [BodyWeightRepository].
///
/// See the documentation for Mockito's code generation for more information.
class MockBodyWeightRepository extends _i1.Mock implements _i11.BodyWeightRepository {
class MockBodyWeightRepository extends _i1.Mock implements _i8.BodyWeightRepository {
MockBodyWeightRepository() {
_i1.throwOnMissingStub(this);
}
@override
_i5.Stream<List<_i12.WeightEntry>> watchAllDrift() =>
_i5.Stream<List<_i9.WeightEntry>> watchAllDrift() =>
(super.noSuchMethod(
Invocation.method(#watchAllDrift, []),
returnValue: _i5.Stream<List<_i12.WeightEntry>>.empty(),
returnValue: _i5.Stream<List<_i9.WeightEntry>>.empty(),
)
as _i5.Stream<List<_i12.WeightEntry>>);
as _i5.Stream<List<_i9.WeightEntry>>);
@override
_i5.Future<void> deleteLocalDrift(String? id) =>
@@ -654,7 +401,7 @@ class MockBodyWeightRepository extends _i1.Mock implements _i11.BodyWeightReposi
as _i5.Future<void>);
@override
_i5.Future<void> updateLocalDrift(_i12.WeightEntry? entry) =>
_i5.Future<void> updateLocalDrift(_i9.WeightEntry? entry) =>
(super.noSuchMethod(
Invocation.method(#updateLocalDrift, [entry]),
returnValue: _i5.Future<void>.value(),
@@ -663,7 +410,7 @@ class MockBodyWeightRepository extends _i1.Mock implements _i11.BodyWeightReposi
as _i5.Future<void>);
@override
_i5.Future<void> addLocalDrift(_i12.WeightEntry? entry) =>
_i5.Future<void> addLocalDrift(_i9.WeightEntry? entry) =>
(super.noSuchMethod(
Invocation.method(#addLocalDrift, [entry]),
returnValue: _i5.Future<void>.value(),

View File

@@ -28,7 +28,6 @@ import 'package:wger/database/ingredients/ingredients_database.dart';
import 'package:wger/l10n/generated/app_localizations.dart';
import 'package:wger/models/nutrition/nutritional_plan.dart';
import 'package:wger/models/user/profile.dart';
import 'package:wger/providers/auth.dart';
import 'package:wger/providers/base_provider.dart';
import 'package:wger/providers/body_weight_repository.dart';
import 'package:wger/providers/nutrition.dart';
@@ -39,9 +38,8 @@ import 'package:wger/widgets/nutrition/forms.dart';
import 'nutritional_plans_screen_test.mocks.dart';
@GenerateMocks([AuthProvider, WgerBaseProvider, http.Client, BodyWeightRepository])
@GenerateMocks([WgerBaseProvider, http.Client, BodyWeightRepository])
void main() {
final mockAuthProvider = MockAuthProvider();
final mockBaseProvider = MockWgerBaseProvider();
final client = MockClient();
late IngredientDatabase database;
@@ -63,9 +61,8 @@ void main() {
(_) async => http.Response('', 200),
);
when(mockAuthProvider.token).thenReturn('1234');
when(mockAuthProvider.serverUrl).thenReturn('http://localhost');
when(mockAuthProvider.getAppNameHeader()).thenReturn('wger app');
when(mockBaseProvider.token).thenReturn('1234');
when(mockBaseProvider.serverUrl).thenReturn('http://localhost');
return riverpod.ProviderScope(
overrides: [bodyWeightRepositoryProvider.overrideWithValue(MockBodyWeightRepository())],
@@ -91,9 +88,6 @@ void main() {
database: database,
),
),
ChangeNotifierProvider<AuthProvider>(
create: (context) => AuthProvider(),
),
ChangeNotifierProvider<UserProvider>(
create: (context) =>
UserProvider(

View File

@@ -4,18 +4,15 @@
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i5;
import 'dart:convert' as _i9;
import 'dart:typed_data' as _i10;
import 'dart:ui' as _i7;
import 'dart:convert' as _i6;
import 'dart:typed_data' as _i7;
import 'package:http/http.dart' as _i2;
import 'package:mockito/mockito.dart' as _i1;
import 'package:mockito/src/dummies.dart' as _i6;
import 'package:package_info_plus/package_info_plus.dart' as _i4;
import 'package:wger/models/body_weight/weight_entry.dart' as _i12;
import 'package:wger/providers/auth.dart' as _i3;
import 'package:wger/providers/base_provider.dart' as _i8;
import 'package:wger/providers/body_weight_repository.dart' as _i11;
import 'package:mockito/src/dummies.dart' as _i4;
import 'package:wger/models/body_weight/weight_entry.dart' as _i9;
import 'package:wger/providers/base_provider.dart' as _i3;
import 'package:wger/providers/body_weight_repository.dart' as _i8;
// ignore_for_file: type=lint
// ignore_for_file: avoid_redundant_argument_values
@@ -36,282 +33,27 @@ class _FakeClient_0 extends _i1.SmartFake implements _i2.Client {
_FakeClient_0(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeAuthProvider_1 extends _i1.SmartFake implements _i3.AuthProvider {
_FakeAuthProvider_1(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeUri_1 extends _i1.SmartFake implements Uri {
_FakeUri_1(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeUri_2 extends _i1.SmartFake implements Uri {
_FakeUri_2(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeResponse_2 extends _i1.SmartFake implements _i2.Response {
_FakeResponse_2(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeResponse_3 extends _i1.SmartFake implements _i2.Response {
_FakeResponse_3(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeStreamedResponse_4 extends _i1.SmartFake implements _i2.StreamedResponse {
_FakeStreamedResponse_4(Object parent, Invocation parentInvocation)
class _FakeStreamedResponse_3 extends _i1.SmartFake implements _i2.StreamedResponse {
_FakeStreamedResponse_3(Object parent, Invocation parentInvocation)
: super(parent, parentInvocation);
}
/// A class which mocks [AuthProvider].
///
/// See the documentation for Mockito's code generation for more information.
class MockAuthProvider extends _i1.Mock implements _i3.AuthProvider {
MockAuthProvider() {
_i1.throwOnMissingStub(this);
}
@override
Map<String, String> get metadata =>
(super.noSuchMethod(
Invocation.getter(#metadata),
returnValue: <String, String>{},
)
as Map<String, String>);
@override
_i3.AuthState get state =>
(super.noSuchMethod(
Invocation.getter(#state),
returnValue: _i3.AuthState.updateRequired,
)
as _i3.AuthState);
@override
_i2.Client get client =>
(super.noSuchMethod(
Invocation.getter(#client),
returnValue: _FakeClient_0(this, Invocation.getter(#client)),
)
as _i2.Client);
@override
bool get dataInit =>
(super.noSuchMethod(Invocation.getter(#dataInit), returnValue: false) as bool);
@override
bool get isAuth => (super.noSuchMethod(Invocation.getter(#isAuth), returnValue: false) as bool);
@override
set token(String? value) => super.noSuchMethod(
Invocation.setter(#token, value),
returnValueForMissingStub: null,
);
@override
set serverUrl(String? value) => super.noSuchMethod(
Invocation.setter(#serverUrl, value),
returnValueForMissingStub: null,
);
@override
set serverVersion(String? value) => super.noSuchMethod(
Invocation.setter(#serverVersion, value),
returnValueForMissingStub: null,
);
@override
set applicationVersion(_i4.PackageInfo? value) => super.noSuchMethod(
Invocation.setter(#applicationVersion, value),
returnValueForMissingStub: null,
);
@override
set metadata(Map<String, String>? value) => super.noSuchMethod(
Invocation.setter(#metadata, value),
returnValueForMissingStub: null,
);
@override
set state(_i3.AuthState? value) => super.noSuchMethod(
Invocation.setter(#state, value),
returnValueForMissingStub: null,
);
@override
set client(_i2.Client? value) => super.noSuchMethod(
Invocation.setter(#client, value),
returnValueForMissingStub: null,
);
@override
set dataInit(bool? value) => super.noSuchMethod(
Invocation.setter(#dataInit, value),
returnValueForMissingStub: null,
);
@override
bool get hasListeners =>
(super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false) as bool);
@override
_i5.Future<void> setServerVersion() =>
(super.noSuchMethod(
Invocation.method(#setServerVersion, []),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
)
as _i5.Future<void>);
@override
_i5.Future<void> setApplicationVersion() =>
(super.noSuchMethod(
Invocation.method(#setApplicationVersion, []),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
)
as _i5.Future<void>);
@override
_i5.Future<void> initVersions(String? serverUrl) =>
(super.noSuchMethod(
Invocation.method(#initVersions, [serverUrl]),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
)
as _i5.Future<void>);
@override
_i5.Future<bool> applicationUpdateRequired([String? version]) =>
(super.noSuchMethod(
Invocation.method(#applicationUpdateRequired, [version]),
returnValue: _i5.Future<bool>.value(false),
)
as _i5.Future<bool>);
@override
bool serverUpdateRequired([String? version]) =>
(super.noSuchMethod(
Invocation.method(#serverUpdateRequired, [version]),
returnValue: false,
)
as bool);
@override
_i5.Future<_i3.LoginActions> register({
required String? username,
required String? password,
required String? email,
required String? serverUrl,
String? locale = 'en',
}) =>
(super.noSuchMethod(
Invocation.method(#register, [], {
#username: username,
#password: password,
#email: email,
#serverUrl: serverUrl,
#locale: locale,
}),
returnValue: _i5.Future<_i3.LoginActions>.value(
_i3.LoginActions.update,
),
)
as _i5.Future<_i3.LoginActions>);
@override
_i5.Future<_i3.LoginActions> login(
String? username,
String? password,
String? serverUrl,
String? apiToken,
) =>
(super.noSuchMethod(
Invocation.method(#login, [
username,
password,
serverUrl,
apiToken,
]),
returnValue: _i5.Future<_i3.LoginActions>.value(
_i3.LoginActions.update,
),
)
as _i5.Future<_i3.LoginActions>);
@override
_i5.Future<String> getServerUrlFromPrefs() =>
(super.noSuchMethod(
Invocation.method(#getServerUrlFromPrefs, []),
returnValue: _i5.Future<String>.value(
_i6.dummyValue<String>(
this,
Invocation.method(#getServerUrlFromPrefs, []),
),
),
)
as _i5.Future<String>);
@override
_i5.Future<void> tryAutoLogin() =>
(super.noSuchMethod(
Invocation.method(#tryAutoLogin, []),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
)
as _i5.Future<void>);
@override
_i5.Future<void> logout({bool? shouldNotify = true}) =>
(super.noSuchMethod(
Invocation.method(#logout, [], {#shouldNotify: shouldNotify}),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
)
as _i5.Future<void>);
@override
String getAppNameHeader() =>
(super.noSuchMethod(
Invocation.method(#getAppNameHeader, []),
returnValue: _i6.dummyValue<String>(
this,
Invocation.method(#getAppNameHeader, []),
),
)
as String);
@override
void addListener(_i7.VoidCallback? listener) => super.noSuchMethod(
Invocation.method(#addListener, [listener]),
returnValueForMissingStub: null,
);
@override
void removeListener(_i7.VoidCallback? listener) => super.noSuchMethod(
Invocation.method(#removeListener, [listener]),
returnValueForMissingStub: null,
);
@override
void dispose() => super.noSuchMethod(
Invocation.method(#dispose, []),
returnValueForMissingStub: null,
);
@override
void notifyListeners() => super.noSuchMethod(
Invocation.method(#notifyListeners, []),
returnValueForMissingStub: null,
);
}
/// A class which mocks [WgerBaseProvider].
///
/// See the documentation for Mockito's code generation for more information.
class MockWgerBaseProvider extends _i1.Mock implements _i8.WgerBaseProvider {
class MockWgerBaseProvider extends _i1.Mock implements _i3.WgerBaseProvider {
MockWgerBaseProvider() {
_i1.throwOnMissingStub(this);
}
@override
_i3.AuthProvider get auth =>
(super.noSuchMethod(
Invocation.getter(#auth),
returnValue: _FakeAuthProvider_1(this, Invocation.getter(#auth)),
)
as _i3.AuthProvider);
@override
_i2.Client get client =>
(super.noSuchMethod(
@@ -320,18 +62,23 @@ class MockWgerBaseProvider extends _i1.Mock implements _i8.WgerBaseProvider {
)
as _i2.Client);
@override
set auth(_i3.AuthProvider? value) => super.noSuchMethod(
Invocation.setter(#auth, value),
returnValueForMissingStub: null,
);
@override
set client(_i2.Client? value) => super.noSuchMethod(
Invocation.setter(#client, value),
returnValueForMissingStub: null,
);
@override
String getAppNameHeaderValue() =>
(super.noSuchMethod(
Invocation.method(#getAppNameHeaderValue, []),
returnValue: _i4.dummyValue<String>(
this,
Invocation.method(#getAppNameHeaderValue, []),
),
)
as String);
@override
Map<String, String> getDefaultHeaders({
bool? includeAuth = false,
@@ -359,7 +106,7 @@ class MockWgerBaseProvider extends _i1.Mock implements _i8.WgerBaseProvider {
[path],
{#id: id, #objectMethod: objectMethod, #query: query},
),
returnValue: _FakeUri_2(
returnValue: _FakeUri_1(
this,
Invocation.method(
#makeUrl,
@@ -437,7 +184,7 @@ class MockWgerBaseProvider extends _i1.Mock implements _i8.WgerBaseProvider {
(super.noSuchMethod(
Invocation.method(#deleteRequest, [url, id]),
returnValue: _i5.Future<_i2.Response>.value(
_FakeResponse_3(
_FakeResponse_2(
this,
Invocation.method(#deleteRequest, [url, id]),
),
@@ -459,7 +206,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
(super.noSuchMethod(
Invocation.method(#head, [url], {#headers: headers}),
returnValue: _i5.Future<_i2.Response>.value(
_FakeResponse_3(
_FakeResponse_2(
this,
Invocation.method(#head, [url], {#headers: headers}),
),
@@ -472,7 +219,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
(super.noSuchMethod(
Invocation.method(#get, [url], {#headers: headers}),
returnValue: _i5.Future<_i2.Response>.value(
_FakeResponse_3(
_FakeResponse_2(
this,
Invocation.method(#get, [url], {#headers: headers}),
),
@@ -485,7 +232,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
Uri? url, {
Map<String, String>? headers,
Object? body,
_i9.Encoding? encoding,
_i6.Encoding? encoding,
}) =>
(super.noSuchMethod(
Invocation.method(
@@ -494,7 +241,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
{#headers: headers, #body: body, #encoding: encoding},
),
returnValue: _i5.Future<_i2.Response>.value(
_FakeResponse_3(
_FakeResponse_2(
this,
Invocation.method(
#post,
@@ -511,7 +258,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
Uri? url, {
Map<String, String>? headers,
Object? body,
_i9.Encoding? encoding,
_i6.Encoding? encoding,
}) =>
(super.noSuchMethod(
Invocation.method(
@@ -520,7 +267,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
{#headers: headers, #body: body, #encoding: encoding},
),
returnValue: _i5.Future<_i2.Response>.value(
_FakeResponse_3(
_FakeResponse_2(
this,
Invocation.method(
#put,
@@ -537,7 +284,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
Uri? url, {
Map<String, String>? headers,
Object? body,
_i9.Encoding? encoding,
_i6.Encoding? encoding,
}) =>
(super.noSuchMethod(
Invocation.method(
@@ -546,7 +293,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
{#headers: headers, #body: body, #encoding: encoding},
),
returnValue: _i5.Future<_i2.Response>.value(
_FakeResponse_3(
_FakeResponse_2(
this,
Invocation.method(
#patch,
@@ -563,7 +310,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
Uri? url, {
Map<String, String>? headers,
Object? body,
_i9.Encoding? encoding,
_i6.Encoding? encoding,
}) =>
(super.noSuchMethod(
Invocation.method(
@@ -572,7 +319,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
{#headers: headers, #body: body, #encoding: encoding},
),
returnValue: _i5.Future<_i2.Response>.value(
_FakeResponse_3(
_FakeResponse_2(
this,
Invocation.method(
#delete,
@@ -589,7 +336,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
(super.noSuchMethod(
Invocation.method(#read, [url], {#headers: headers}),
returnValue: _i5.Future<String>.value(
_i6.dummyValue<String>(
_i4.dummyValue<String>(
this,
Invocation.method(#read, [url], {#headers: headers}),
),
@@ -598,22 +345,22 @@ class MockClient extends _i1.Mock implements _i2.Client {
as _i5.Future<String>);
@override
_i5.Future<_i10.Uint8List> readBytes(
_i5.Future<_i7.Uint8List> readBytes(
Uri? url, {
Map<String, String>? headers,
}) =>
(super.noSuchMethod(
Invocation.method(#readBytes, [url], {#headers: headers}),
returnValue: _i5.Future<_i10.Uint8List>.value(_i10.Uint8List(0)),
returnValue: _i5.Future<_i7.Uint8List>.value(_i7.Uint8List(0)),
)
as _i5.Future<_i10.Uint8List>);
as _i5.Future<_i7.Uint8List>);
@override
_i5.Future<_i2.StreamedResponse> send(_i2.BaseRequest? request) =>
(super.noSuchMethod(
Invocation.method(#send, [request]),
returnValue: _i5.Future<_i2.StreamedResponse>.value(
_FakeStreamedResponse_4(
_FakeStreamedResponse_3(
this,
Invocation.method(#send, [request]),
),
@@ -631,18 +378,18 @@ class MockClient extends _i1.Mock implements _i2.Client {
/// A class which mocks [BodyWeightRepository].
///
/// See the documentation for Mockito's code generation for more information.
class MockBodyWeightRepository extends _i1.Mock implements _i11.BodyWeightRepository {
class MockBodyWeightRepository extends _i1.Mock implements _i8.BodyWeightRepository {
MockBodyWeightRepository() {
_i1.throwOnMissingStub(this);
}
@override
_i5.Stream<List<_i12.WeightEntry>> watchAllDrift() =>
_i5.Stream<List<_i9.WeightEntry>> watchAllDrift() =>
(super.noSuchMethod(
Invocation.method(#watchAllDrift, []),
returnValue: _i5.Stream<List<_i12.WeightEntry>>.empty(),
returnValue: _i5.Stream<List<_i9.WeightEntry>>.empty(),
)
as _i5.Stream<List<_i12.WeightEntry>>);
as _i5.Stream<List<_i9.WeightEntry>>);
@override
_i5.Future<void> deleteLocalDrift(String? id) =>
@@ -654,7 +401,7 @@ class MockBodyWeightRepository extends _i1.Mock implements _i11.BodyWeightReposi
as _i5.Future<void>);
@override
_i5.Future<void> updateLocalDrift(_i12.WeightEntry? entry) =>
_i5.Future<void> updateLocalDrift(_i9.WeightEntry? entry) =>
(super.noSuchMethod(
Invocation.method(#updateLocalDrift, [entry]),
returnValue: _i5.Future<void>.value(),
@@ -663,7 +410,7 @@ class MockBodyWeightRepository extends _i1.Mock implements _i11.BodyWeightReposi
as _i5.Future<void>);
@override
_i5.Future<void> addLocalDrift(_i12.WeightEntry? entry) =>
_i5.Future<void> addLocalDrift(_i9.WeightEntry? entry) =>
(super.noSuchMethod(
Invocation.method(#addLocalDrift, [entry]),
returnValue: _i5.Future<void>.value(),

View File

@@ -31,7 +31,7 @@ import 'base_provider_test.mocks.dart';
void main() {
group('test base provider', () {
test('Test the makeUrl helper', () {
final WgerBaseProvider provider = WgerBaseProvider(testAuthProvider);
final WgerBaseProvider provider = buildTestBaseProvider();
expect(
Uri.https('localhost', '/api/v2/endpoint/'),
@@ -65,8 +65,9 @@ void main() {
test('Test the makeUrl helper with sub url', () {
// Trailing slash is removed when saving the server URL
testAuthProvider.serverUrl = 'https://example.com/wger-url';
final WgerBaseProvider provider = WgerBaseProvider(testAuthProvider);
final WgerBaseProvider provider = buildTestBaseProvider(
serverUrl: 'https://example.com/wger-url',
);
expect(
Uri.https('example.com', '/wger-url/api/v2/endpoint/'),
@@ -135,7 +136,7 @@ void main() {
).thenAnswer((_) => Future.value(response3));
// Act
final WgerBaseProvider provider = WgerBaseProvider(testAuthProvider, mockHttpClient);
final WgerBaseProvider provider = buildTestBaseProvider(client: mockHttpClient);
final data = await provider.fetchPaginated(paginationUri1);
// Assert

View File

@@ -23,7 +23,6 @@ import 'package:http/http.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:wger/core/exceptions/http_exception.dart';
import 'package:wger/providers/base_provider.dart';
import '../utils.dart';
import 'base_provider.mocks.dart';
@@ -45,7 +44,7 @@ void main() {
});
// Act
final provider = WgerBaseProvider(testAuthProvider, mockClient);
final provider = buildTestBaseProvider(client: mockClient);
final result = await provider.fetch(testUri, initialDelay: const Duration(milliseconds: 1));
// Assert
@@ -67,7 +66,7 @@ void main() {
});
// Act
final provider = WgerBaseProvider(testAuthProvider, mockClient);
final provider = buildTestBaseProvider(client: mockClient);
final result = await provider.fetch(testUri, initialDelay: const Duration(milliseconds: 1));
// Assert
@@ -84,7 +83,7 @@ void main() {
).thenAnswer((_) => Future.value(Response('{"error":"bad"}', 400)));
// Act
final provider = WgerBaseProvider(testAuthProvider, mockClient);
final provider = buildTestBaseProvider(client: mockClient);
// Assert
await expectLater(
@@ -102,7 +101,7 @@ void main() {
).thenAnswer((_) => Future.error(ClientException('conn fail')));
// Act
final provider = WgerBaseProvider(testAuthProvider, mockClient);
final provider = buildTestBaseProvider(client: mockClient);
dynamic caught;
try {
await provider.fetch(testUri, initialDelay: const Duration(milliseconds: 1));
@@ -124,7 +123,7 @@ void main() {
).thenAnswer((_) => Future.value(Response('{"ok": true}', 200)));
// Act
final provider = WgerBaseProvider(testAuthProvider, mockClient);
final provider = buildTestBaseProvider(client: mockClient);
final result = await provider.fetch(testUri);
// Assert

View File

@@ -0,0 +1,69 @@
// Mocks generated by Mockito 5.4.6 from annotations
// in wger/test/routine/gym_mode/gym_mode_test.dart.
// Do not manually edit this file.
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i3;
import 'package:mockito/mockito.dart' as _i1;
import 'package:wger/models/workouts/session.dart' as _i4;
import 'package:wger/providers/workout_session_repository.dart' as _i2;
// ignore_for_file: type=lint
// ignore_for_file: avoid_redundant_argument_values
// ignore_for_file: avoid_setters_without_getters
// ignore_for_file: comment_references
// ignore_for_file: deprecated_member_use
// ignore_for_file: deprecated_member_use_from_same_package
// ignore_for_file: implementation_imports
// ignore_for_file: invalid_use_of_visible_for_testing_member
// ignore_for_file: must_be_immutable
// ignore_for_file: prefer_const_constructors
// ignore_for_file: unnecessary_parenthesis
// ignore_for_file: camel_case_types
// ignore_for_file: subtype_of_sealed_class
// ignore_for_file: invalid_use_of_internal_member
/// A class which mocks [WorkoutSessionRepository].
///
/// See the documentation for Mockito's code generation for more information.
class MockWorkoutSessionRepository extends _i1.Mock implements _i2.WorkoutSessionRepository {
MockWorkoutSessionRepository() {
_i1.throwOnMissingStub(this);
}
@override
_i3.Stream<List<_i4.WorkoutSession>> watchAllDrift() =>
(super.noSuchMethod(
Invocation.method(#watchAllDrift, []),
returnValue: _i3.Stream<List<_i4.WorkoutSession>>.empty(),
)
as _i3.Stream<List<_i4.WorkoutSession>>);
@override
_i3.Future<void> deleteLocalDrift(String? id) =>
(super.noSuchMethod(
Invocation.method(#deleteLocalDrift, [id]),
returnValue: _i3.Future<void>.value(),
returnValueForMissingStub: _i3.Future<void>.value(),
)
as _i3.Future<void>);
@override
_i3.Future<void> editLocalDrift(_i4.WorkoutSession? session) =>
(super.noSuchMethod(
Invocation.method(#editLocalDrift, [session]),
returnValue: _i3.Future<void>.value(),
returnValueForMissingStub: _i3.Future<void>.value(),
)
as _i3.Future<void>);
@override
_i3.Future<void> addLocalDrift(_i4.WorkoutSession? session) =>
(super.noSuchMethod(
Invocation.method(#addLocalDrift, [session]),
returnValue: _i3.Future<void>.value(),
returnValueForMissingStub: _i3.Future<void>.value(),
)
as _i3.Future<void>);
}

View File

@@ -5,10 +5,10 @@
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i5;
import 'package:http/http.dart' as _i3;
import 'package:http/http.dart' as _i2;
import 'package:mockito/mockito.dart' as _i1;
import 'package:wger/providers/auth.dart' as _i2;
import 'package:wger/providers/base_provider.dart' as _i4;
import 'package:mockito/src/dummies.dart' as _i4;
import 'package:wger/providers/base_provider.dart' as _i3;
// ignore_for_file: type=lint
// ignore_for_file: avoid_redundant_argument_values
@@ -25,58 +25,51 @@ import 'package:wger/providers/base_provider.dart' as _i4;
// ignore_for_file: subtype_of_sealed_class
// ignore_for_file: invalid_use_of_internal_member
class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider {
_FakeAuthProvider_0(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeClient_0 extends _i1.SmartFake implements _i2.Client {
_FakeClient_0(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeClient_1 extends _i1.SmartFake implements _i3.Client {
_FakeClient_1(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeUri_1 extends _i1.SmartFake implements Uri {
_FakeUri_1(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeUri_2 extends _i1.SmartFake implements Uri {
_FakeUri_2(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeResponse_3 extends _i1.SmartFake implements _i3.Response {
_FakeResponse_3(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeResponse_2 extends _i1.SmartFake implements _i2.Response {
_FakeResponse_2(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
/// A class which mocks [WgerBaseProvider].
///
/// See the documentation for Mockito's code generation for more information.
class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
class MockWgerBaseProvider extends _i1.Mock implements _i3.WgerBaseProvider {
MockWgerBaseProvider() {
_i1.throwOnMissingStub(this);
}
@override
_i2.AuthProvider get auth =>
(super.noSuchMethod(
Invocation.getter(#auth),
returnValue: _FakeAuthProvider_0(this, Invocation.getter(#auth)),
)
as _i2.AuthProvider);
@override
_i3.Client get client =>
_i2.Client get client =>
(super.noSuchMethod(
Invocation.getter(#client),
returnValue: _FakeClient_1(this, Invocation.getter(#client)),
returnValue: _FakeClient_0(this, Invocation.getter(#client)),
)
as _i3.Client);
as _i2.Client);
@override
set auth(_i2.AuthProvider? value) => super.noSuchMethod(
Invocation.setter(#auth, value),
returnValueForMissingStub: null,
);
@override
set client(_i3.Client? value) => super.noSuchMethod(
set client(_i2.Client? value) => super.noSuchMethod(
Invocation.setter(#client, value),
returnValueForMissingStub: null,
);
@override
String getAppNameHeaderValue() =>
(super.noSuchMethod(
Invocation.method(#getAppNameHeaderValue, []),
returnValue: _i4.dummyValue<String>(
this,
Invocation.method(#getAppNameHeaderValue, []),
),
)
as String);
@override
Map<String, String> getDefaultHeaders({
bool? includeAuth = false,
@@ -104,7 +97,7 @@ class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
[path],
{#id: id, #objectMethod: objectMethod, #query: query},
),
returnValue: _FakeUri_2(
returnValue: _FakeUri_1(
this,
Invocation.method(
#makeUrl,
@@ -178,15 +171,15 @@ class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
as _i5.Future<Map<String, dynamic>>);
@override
_i5.Future<_i3.Response> deleteRequest(String? url, int? id) =>
_i5.Future<_i2.Response> deleteRequest(String? url, int? id) =>
(super.noSuchMethod(
Invocation.method(#deleteRequest, [url, id]),
returnValue: _i5.Future<_i3.Response>.value(
_FakeResponse_3(
returnValue: _i5.Future<_i2.Response>.value(
_FakeResponse_2(
this,
Invocation.method(#deleteRequest, [url, id]),
),
),
)
as _i5.Future<_i3.Response>);
as _i5.Future<_i2.Response>);
}

View File

@@ -5,10 +5,10 @@
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i5;
import 'package:http/http.dart' as _i3;
import 'package:http/http.dart' as _i2;
import 'package:mockito/mockito.dart' as _i1;
import 'package:wger/providers/auth.dart' as _i2;
import 'package:wger/providers/base_provider.dart' as _i4;
import 'package:mockito/src/dummies.dart' as _i4;
import 'package:wger/providers/base_provider.dart' as _i3;
// ignore_for_file: type=lint
// ignore_for_file: avoid_redundant_argument_values
@@ -25,58 +25,51 @@ import 'package:wger/providers/base_provider.dart' as _i4;
// ignore_for_file: subtype_of_sealed_class
// ignore_for_file: invalid_use_of_internal_member
class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider {
_FakeAuthProvider_0(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeClient_0 extends _i1.SmartFake implements _i2.Client {
_FakeClient_0(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeClient_1 extends _i1.SmartFake implements _i3.Client {
_FakeClient_1(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeUri_1 extends _i1.SmartFake implements Uri {
_FakeUri_1(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeUri_2 extends _i1.SmartFake implements Uri {
_FakeUri_2(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeResponse_3 extends _i1.SmartFake implements _i3.Response {
_FakeResponse_3(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeResponse_2 extends _i1.SmartFake implements _i2.Response {
_FakeResponse_2(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
/// A class which mocks [WgerBaseProvider].
///
/// See the documentation for Mockito's code generation for more information.
class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
class MockWgerBaseProvider extends _i1.Mock implements _i3.WgerBaseProvider {
MockWgerBaseProvider() {
_i1.throwOnMissingStub(this);
}
@override
_i2.AuthProvider get auth =>
(super.noSuchMethod(
Invocation.getter(#auth),
returnValue: _FakeAuthProvider_0(this, Invocation.getter(#auth)),
)
as _i2.AuthProvider);
@override
_i3.Client get client =>
_i2.Client get client =>
(super.noSuchMethod(
Invocation.getter(#client),
returnValue: _FakeClient_1(this, Invocation.getter(#client)),
returnValue: _FakeClient_0(this, Invocation.getter(#client)),
)
as _i3.Client);
as _i2.Client);
@override
set auth(_i2.AuthProvider? value) => super.noSuchMethod(
Invocation.setter(#auth, value),
returnValueForMissingStub: null,
);
@override
set client(_i3.Client? value) => super.noSuchMethod(
set client(_i2.Client? value) => super.noSuchMethod(
Invocation.setter(#client, value),
returnValueForMissingStub: null,
);
@override
String getAppNameHeaderValue() =>
(super.noSuchMethod(
Invocation.method(#getAppNameHeaderValue, []),
returnValue: _i4.dummyValue<String>(
this,
Invocation.method(#getAppNameHeaderValue, []),
),
)
as String);
@override
Map<String, String> getDefaultHeaders({
bool? includeAuth = false,
@@ -104,7 +97,7 @@ class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
[path],
{#id: id, #objectMethod: objectMethod, #query: query},
),
returnValue: _FakeUri_2(
returnValue: _FakeUri_1(
this,
Invocation.method(
#makeUrl,
@@ -178,15 +171,15 @@ class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
as _i5.Future<Map<String, dynamic>>);
@override
_i5.Future<_i3.Response> deleteRequest(String? url, int? id) =>
_i5.Future<_i2.Response> deleteRequest(String? url, int? id) =>
(super.noSuchMethod(
Invocation.method(#deleteRequest, [url, id]),
returnValue: _i5.Future<_i3.Response>.value(
_FakeResponse_3(
returnValue: _i5.Future<_i2.Response>.value(
_FakeResponse_2(
this,
Invocation.method(#deleteRequest, [url, id]),
),
),
)
as _i5.Future<_i3.Response>);
as _i5.Future<_i2.Response>);
}

View File

@@ -5,10 +5,10 @@
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i5;
import 'package:http/http.dart' as _i3;
import 'package:http/http.dart' as _i2;
import 'package:mockito/mockito.dart' as _i1;
import 'package:wger/providers/auth.dart' as _i2;
import 'package:wger/providers/base_provider.dart' as _i4;
import 'package:mockito/src/dummies.dart' as _i4;
import 'package:wger/providers/base_provider.dart' as _i3;
// ignore_for_file: type=lint
// ignore_for_file: avoid_redundant_argument_values
@@ -25,58 +25,51 @@ import 'package:wger/providers/base_provider.dart' as _i4;
// ignore_for_file: subtype_of_sealed_class
// ignore_for_file: invalid_use_of_internal_member
class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider {
_FakeAuthProvider_0(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeClient_0 extends _i1.SmartFake implements _i2.Client {
_FakeClient_0(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeClient_1 extends _i1.SmartFake implements _i3.Client {
_FakeClient_1(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeUri_1 extends _i1.SmartFake implements Uri {
_FakeUri_1(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeUri_2 extends _i1.SmartFake implements Uri {
_FakeUri_2(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeResponse_3 extends _i1.SmartFake implements _i3.Response {
_FakeResponse_3(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeResponse_2 extends _i1.SmartFake implements _i2.Response {
_FakeResponse_2(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
/// A class which mocks [WgerBaseProvider].
///
/// See the documentation for Mockito's code generation for more information.
class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
class MockWgerBaseProvider extends _i1.Mock implements _i3.WgerBaseProvider {
MockWgerBaseProvider() {
_i1.throwOnMissingStub(this);
}
@override
_i2.AuthProvider get auth =>
(super.noSuchMethod(
Invocation.getter(#auth),
returnValue: _FakeAuthProvider_0(this, Invocation.getter(#auth)),
)
as _i2.AuthProvider);
@override
_i3.Client get client =>
_i2.Client get client =>
(super.noSuchMethod(
Invocation.getter(#client),
returnValue: _FakeClient_1(this, Invocation.getter(#client)),
returnValue: _FakeClient_0(this, Invocation.getter(#client)),
)
as _i3.Client);
as _i2.Client);
@override
set auth(_i2.AuthProvider? value) => super.noSuchMethod(
Invocation.setter(#auth, value),
returnValueForMissingStub: null,
);
@override
set client(_i3.Client? value) => super.noSuchMethod(
set client(_i2.Client? value) => super.noSuchMethod(
Invocation.setter(#client, value),
returnValueForMissingStub: null,
);
@override
String getAppNameHeaderValue() =>
(super.noSuchMethod(
Invocation.method(#getAppNameHeaderValue, []),
returnValue: _i4.dummyValue<String>(
this,
Invocation.method(#getAppNameHeaderValue, []),
),
)
as String);
@override
Map<String, String> getDefaultHeaders({
bool? includeAuth = false,
@@ -104,7 +97,7 @@ class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
[path],
{#id: id, #objectMethod: objectMethod, #query: query},
),
returnValue: _FakeUri_2(
returnValue: _FakeUri_1(
this,
Invocation.method(
#makeUrl,
@@ -178,15 +171,15 @@ class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
as _i5.Future<Map<String, dynamic>>);
@override
_i5.Future<_i3.Response> deleteRequest(String? url, int? id) =>
_i5.Future<_i2.Response> deleteRequest(String? url, int? id) =>
(super.noSuchMethod(
Invocation.method(#deleteRequest, [url, id]),
returnValue: _i5.Future<_i3.Response>.value(
_FakeResponse_3(
returnValue: _i5.Future<_i2.Response>.value(
_FakeResponse_2(
this,
Invocation.method(#deleteRequest, [url, id]),
),
),
)
as _i5.Future<_i3.Response>);
as _i5.Future<_i2.Response>);
}

View File

@@ -16,11 +16,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:wger/providers/auth.dart';
import 'package:http/http.dart' as http;
import 'package:wger/providers/base_provider.dart';
import 'other/base_provider_test.mocks.dart';
// Test Auth provider
final AuthProvider testAuthProvider = AuthProvider(MockClient())
..token = 'FooBar'
..serverUrl = 'https://localhost';
/// Builds a [WgerBaseProvider] pre-configured for tests with a fixed server
/// URL and API token. Pass a mocked [http.Client] to intercept requests.
WgerBaseProvider buildTestBaseProvider({
http.Client? client,
String serverUrl = 'https://localhost',
String token = 'FooBar',
}) {
return WgerBaseProvider(
serverUrl: serverUrl,
token: token,
client: client,
);
}

View File

@@ -23,7 +23,6 @@ import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:provider/provider.dart';
import 'package:wger/l10n/generated/app_localizations.dart';
import 'package:wger/providers/auth.dart';
import 'package:wger/providers/body_weight_repository.dart';
import 'package:wger/providers/nutrition.dart';
import 'package:wger/providers/user.dart';
@@ -72,9 +71,6 @@ void main() {
ChangeNotifierProvider<UserProvider>(
create: (context) => mockUserProvider,
),
ChangeNotifierProvider<AuthProvider>(
create: (context) => AuthProvider(),
),
],
child: MaterialApp(
locale: Locale(locale),