mirror of
https://github.com/flutter/samples.git
synced 2025-11-14 11:28:36 +00:00
Compass app (#2446)
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
// Copyright 2024 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:compass_app/data/repositories/activity/activity_repository.dart';
|
||||
import 'package:compass_app/domain/models/activity/activity.dart';
|
||||
import 'package:compass_app/utils/result.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../../models/activity.dart';
|
||||
import '../../models/destination.dart';
|
||||
|
||||
class FakeActivityRepository implements ActivityRepository {
|
||||
Map<String, List<Activity>> activities = {
|
||||
"DESTINATION": [kActivity],
|
||||
kDestination1.ref: [kActivity],
|
||||
};
|
||||
|
||||
@override
|
||||
Future<Result<List<Activity>>> getByDestination(String ref) {
|
||||
return SynchronousFuture(Result.ok(activities[ref]!));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// Copyright 2024 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:compass_app/data/repositories/auth/auth_repository.dart';
|
||||
import 'package:compass_app/utils/result.dart';
|
||||
|
||||
class FakeAuthRepository extends AuthRepository {
|
||||
String? token;
|
||||
|
||||
@override
|
||||
Future<bool> get isAuthenticated async => token != null;
|
||||
|
||||
@override
|
||||
Future<Result<void>> login({
|
||||
required String email,
|
||||
required String password,
|
||||
}) async {
|
||||
token = 'TOKEN';
|
||||
notifyListeners();
|
||||
return Result.ok(null);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<void>> logout() async {
|
||||
token = null;
|
||||
notifyListeners();
|
||||
return Result.ok(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// Copyright 2024 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:compass_app/data/repositories/booking/booking_repository.dart';
|
||||
import 'package:compass_app/domain/models/booking/booking.dart';
|
||||
import 'package:compass_app/domain/models/booking/booking_summary.dart';
|
||||
import 'package:compass_app/utils/result.dart';
|
||||
|
||||
class FakeBookingRepository implements BookingRepository {
|
||||
List<Booking> bookings = List.empty(growable: true);
|
||||
int sequentialId = 0;
|
||||
|
||||
@override
|
||||
Future<Result<void>> createBooking(Booking booking) async {
|
||||
final bookingWithId = booking.copyWith(id: sequentialId++);
|
||||
bookings.add(bookingWithId);
|
||||
return Result.ok(null);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<Booking>> getBooking(int id) async {
|
||||
return Result.ok(bookings[id]);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<List<BookingSummary>>> getBookingsList() async {
|
||||
return Result.ok(_createSummaries());
|
||||
}
|
||||
|
||||
List<BookingSummary> _createSummaries() {
|
||||
return bookings
|
||||
.map(
|
||||
(booking) => BookingSummary(
|
||||
id: booking.id!,
|
||||
name:
|
||||
'${booking.destination.name}, ${booking.destination.continent}',
|
||||
startDate: booking.startDate,
|
||||
endDate: booking.endDate,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<void>> delete(int id) async {
|
||||
bookings.removeWhere((booking) => booking.id == id);
|
||||
return Result.ok(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// Copyright 2024 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:compass_app/data/repositories/continent/continent_repository.dart';
|
||||
import 'package:compass_app/domain/models/continent/continent.dart';
|
||||
import 'package:compass_app/utils/result.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
class FakeContinentRepository implements ContinentRepository {
|
||||
@override
|
||||
Future<Result<List<Continent>>> getContinents() {
|
||||
return SynchronousFuture(Result.ok([
|
||||
const Continent(name: 'CONTINENT', imageUrl: 'URL'),
|
||||
const Continent(name: 'CONTINENT2', imageUrl: 'URL'),
|
||||
const Continent(name: 'CONTINENT3', imageUrl: 'URL'),
|
||||
]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// Copyright 2024 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:compass_app/data/repositories/destination/destination_repository.dart';
|
||||
import 'package:compass_app/domain/models/destination/destination.dart';
|
||||
import 'package:compass_app/utils/result.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../../models/destination.dart';
|
||||
|
||||
class FakeDestinationRepository implements DestinationRepository {
|
||||
@override
|
||||
Future<Result<List<Destination>>> getDestinations() {
|
||||
return SynchronousFuture(Result.ok([kDestination1, kDestination2]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// Copyright 2024 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:compass_app/data/repositories/itinerary_config/itinerary_config_repository.dart';
|
||||
import 'package:compass_app/domain/models/itinerary_config/itinerary_config.dart';
|
||||
import 'package:compass_app/utils/result.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
class FakeItineraryConfigRepository implements ItineraryConfigRepository {
|
||||
FakeItineraryConfigRepository({this.itineraryConfig});
|
||||
|
||||
ItineraryConfig? itineraryConfig;
|
||||
|
||||
@override
|
||||
Future<Result<ItineraryConfig>> getItineraryConfig() {
|
||||
return SynchronousFuture(
|
||||
Result.ok(itineraryConfig ?? const ItineraryConfig()));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<void>> setItineraryConfig(ItineraryConfig itineraryConfig) {
|
||||
this.itineraryConfig = itineraryConfig;
|
||||
return SynchronousFuture(Result.ok(null));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// Copyright 2024 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:compass_app/data/repositories/user/user_repository.dart';
|
||||
import 'package:compass_app/domain/models/user/user.dart';
|
||||
import 'package:compass_app/utils/result.dart';
|
||||
|
||||
import '../../models/user.dart';
|
||||
|
||||
class FakeUserRepository implements UserRepository {
|
||||
@override
|
||||
Future<Result<User>> getUser() async {
|
||||
return Result.ok(user);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user