diff --git a/lib/src/features/jokes/logic/jokes_provider.dart b/lib/src/features/jokes/logic/jokes_provider.dart index 22a89d5..466c657 100644 --- a/lib/src/features/jokes/logic/jokes_provider.dart +++ b/lib/src/features/jokes/logic/jokes_provider.dart @@ -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'; @@ -12,29 +12,27 @@ export 'jokes_state.dart'; part 'jokes_state_notifier.dart'; /// Provider to use the JokesStateNotifier +// * Logic holder / StateNotifier final jokesNotifierProvider = StateNotifierProvider( (ref) => JokesNotifier(getJoke: ref.watch(getJokeProvider)), ); -/// Repositories Providers -final repositoryProvider = Provider( - (ref) { - final apiUrl = EnvironmentConfig.apiUrl; - - return JokesRepository( - networkManager: NetworkManager(DataConnectionChecker()), - remoteDataSource: DioDataSource( - client: Dio(), - url: '$apiUrl/joke/Programming,Pun', - ), - ); - }, +// * Repository +final jokesRepositoryProvider = Provider( + (_) => JokesRepository( + networkManager: NetworkManager(DataConnectionChecker()), + remoteDataSource: DioDataSource( + client: Dio(), + url: '${EnvironmentConfig.apiUrl}/joke/Programming', + ), + ), ); -/// Use Cases Providers +// * Use cases + final getJokeProvider = Provider( (ref) { - final repository = ref.watch(repositoryProvider); + final repository = ref.watch(jokesRepositoryProvider); return GetJoke(repository: repository); }, ); diff --git a/lib/src/features/jokes/views/joke_page.dart b/lib/src/features/jokes/views/joke_page.dart index f7b897e..fecb97f 100644 --- a/lib/src/features/jokes/views/joke_page.dart +++ b/lib/src/features/jokes/views/joke_page.dart @@ -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(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, ], ), ), @@ -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, ), ); diff --git a/packages/jokes/analysis_options.yaml b/packages/jokes/analysis_options.yaml index 3dcce25..4daafde 100644 --- a/packages/jokes/analysis_options.yaml +++ b/packages/jokes/analysis_options.yaml @@ -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: diff --git a/packages/jokes/lib/src/data/models/flags_model.dart b/packages/jokes/lib/src/data/models/flags_model.dart index a14ab16..bb1715a 100644 --- a/packages/jokes/lib/src/data/models/flags_model.dart +++ b/packages/jokes/lib/src/data/models/flags_model.dart @@ -39,7 +39,14 @@ class FlagsModel implements Flags { final bool? sexist; @override - List get props => []; + List get props => [ + explicit, + nsfw, + political, + racist, + religious, + sexist, + ]; @override bool get stringify => true; diff --git a/packages/jokes/lib/src/data/models/joke_model.dart b/packages/jokes/lib/src/data/models/joke_model.dart index ada711a..9f1c370 100644 --- a/packages/jokes/lib/src/data/models/joke_model.dart +++ b/packages/jokes/lib/src/data/models/joke_model.dart @@ -48,7 +48,16 @@ class JokeModel implements Joke { final String? type; @override - List get props => []; + List get props => [ + category, + delivery, + flags, + id, + lang, + safe, + setup, + type, + ]; @override bool get stringify => true; diff --git a/test/jokes/views/joke_page_test.dart b/test/jokes/views/joke_page_test.dart index 0437ca6..9e66514 100644 --- a/test/jokes/views/joke_page_test.dart +++ b/test/jokes/views/joke_page_test.dart @@ -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 {}