Skip to content

Commit

Permalink
Merge branch 'main' into null-safety
Browse files Browse the repository at this point in the history
  • Loading branch information
elianortega committed Apr 6, 2021
2 parents c7eb14c + 6f345d3 commit ab46d25
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 35 deletions.
30 changes: 14 additions & 16 deletions lib/src/features/jokes/logic/jokes_provider.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:dio/dio.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:network_manager/network_manager.dart';

import 'package:network_manager/network_manager.dart';
import 'package:jokes/jokes.dart';

import '../../../core/env/environment_config.dart';
Expand All @@ -12,29 +12,27 @@ export 'jokes_state.dart';
part 'jokes_state_notifier.dart';

/// Provider to use the JokesStateNotifier
// * Logic holder / StateNotifier
final jokesNotifierProvider = StateNotifierProvider<JokesNotifier, JokesState>(
(ref) => JokesNotifier(getJoke: ref.watch(getJokeProvider)),
);

/// Repositories Providers
final repositoryProvider = Provider<IJokesRepository>(
(ref) {
final apiUrl = EnvironmentConfig.apiUrl;

return JokesRepository(
networkManager: NetworkManager(DataConnectionChecker()),
remoteDataSource: DioDataSource(
client: Dio(),
url: '$apiUrl/joke/Programming,Pun',
),
);
},
// * Repository
final jokesRepositoryProvider = Provider<IJokesRepository>(
(_) => JokesRepository(
networkManager: NetworkManager(DataConnectionChecker()),
remoteDataSource: DioDataSource(
client: Dio(),
url: '${EnvironmentConfig.apiUrl}/joke/Programming',
),
),
);

/// Use Cases Providers
// * Use cases

final getJokeProvider = Provider<GetJoke>(
(ref) {
final repository = ref.watch(repositoryProvider);
final repository = ref.watch(jokesRepositoryProvider);
return GetJoke(repository: repository);
},
);
19 changes: 9 additions & 10 deletions lib/src/features/jokes/views/joke_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,28 @@ import '../logic/jokes_provider.dart';
import 'joke_page.i18n.dart';
import 'widgets.dart';

///Keys for testing
const contentSpacing = SizedBox(height: 50);

/// * Keys for testing
final getJokeButtonKey = UniqueKey();
final loadingIndicatorKey = UniqueKey();

class JokePage extends StatelessWidget {
/// Static method to return the widget as a PageRoute
static Route go() => MaterialPageRoute<void>(builder: (_) => JokePage());

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(kAppTitle.i18n), elevation: 0),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const SizedBox(height: 5),
const Spacer(),
const JokeConsumer(),
contentSpacing,
const _GetJokeButton(),
contentSpacing,
const Spacer(),
AppVersion(),
const SizedBox(height: 5),
contentSpacing,
],
),
),
Expand Down Expand Up @@ -60,13 +61,11 @@ class _Message extends StatelessWidget {

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);

return Padding(
padding: const EdgeInsets.all(20),
child: Text(
message,
style: theme.textTheme.headline5,
style: Theme.of(context).textTheme.headline5,
textAlign: TextAlign.center,
),
);
Expand Down
6 changes: 3 additions & 3 deletions packages/jokes/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ include: package:very_good_analysis/analysis_options.yaml

# For lint rules and documentation, see http://dart-lang.github.io/linter/lints.
# Uncomment to specify additional rules.
# linter:
# rules:
# - camel_case_types
linter:
rules:
public_member_api_docs: false

analyzer:
exclude:
Expand Down
9 changes: 8 additions & 1 deletion packages/jokes/lib/src/data/models/flags_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ class FlagsModel implements Flags {
final bool? sexist;

@override
List<Object> get props => [];
List<Object?> get props => [
explicit,
nsfw,
political,
racist,
religious,
sexist,
];

@override
bool get stringify => true;
Expand Down
11 changes: 10 additions & 1 deletion packages/jokes/lib/src/data/models/joke_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ class JokeModel implements Joke {
final String? type;

@override
List<Object> get props => [];
List<Object?> get props => [
category,
delivery,
flags,
id,
lang,
safe,
setup,
type,
];

@override
bool get stringify => true;
Expand Down
9 changes: 5 additions & 4 deletions test/jokes/views/joke_page_test.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:dartz/dartz.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'package:errors/errors.dart';
import 'package:jokes/jokes.dart';
import 'package:mocktail/mocktail.dart';

import '../../../lib/src/app.dart';
import '../../../lib/src/features/jokes/logic/jokes_provider.dart';
import '../../../lib/src/features/jokes/views/joke_page.dart';
import '../../../lib/src/features/jokes/views/joke_page.i18n.dart';
import 'package:flutter_jokes/src/app.dart';
import 'package:flutter_jokes/src/features/jokes/logic/jokes_provider.dart';
import 'package:flutter_jokes/src/features/jokes/views/joke_page.dart';
import 'package:flutter_jokes/src/features/jokes/views/joke_page.i18n.dart';

class MockGetJoke extends Mock implements GetJoke {}

Expand Down

0 comments on commit ab46d25

Please sign in to comment.