From c7abf7d1871e53ed37ea66108b643fa2ecc46fdb Mon Sep 17 00:00:00 2001 From: Jeho Date: Wed, 11 Sep 2024 10:37:42 +0900 Subject: [PATCH] Separating the public/private code. --- CHANGELOG.md | 5 +- analysis_options.yaml | 176 ++++++++++++++++++++++++ example/lib/main.dart | 8 +- example/pubspec.lock | 33 ++--- example/test/widget_test.dart | 5 +- lib/number_pagination.dart | 34 ++--- lib/{ => src}/control_button.dart | 14 +- lib/{ => src}/number_button.dart | 24 ++-- lib/src/number_page_container.dart | 20 +++ lib/{ => src}/page_number_provider.dart | 4 +- pubspec.lock | 40 ++++-- pubspec.yaml | 5 +- 12 files changed, 282 insertions(+), 86 deletions(-) create mode 100644 analysis_options.yaml rename lib/{ => src}/control_button.dart (81%) rename lib/{ => src}/number_button.dart (84%) create mode 100644 lib/src/number_page_container.dart rename lib/{ => src}/page_number_provider.dart (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ba2fa0..8154d04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ +## 1.0.8 +- Separating the public/private code. + ## 1.0.7 -- Add topics of pub.dev +- Add topics of pub.dev. ## 1.0.6 - Update minimum supported SDK version (>=3.0.0) diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..37c0c10 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,176 @@ +include: package:flutter_lints/flutter.yaml + +linter: + rules: + - always_declare_return_types + - always_put_control_body_on_new_line + # - always_specify_types + - annotate_overrides + - annotate_redeclares + - avoid_bool_literals_in_conditional_expressions + - avoid_double_and_int_checks + - avoid_dynamic_calls + - avoid_empty_else + - avoid_equals_and_hash_code_on_mutable_classes + - avoid_escaping_inner_quotes + - avoid_field_initializers_in_const_classes + - avoid_function_literals_in_foreach_calls + - avoid_init_to_null + - avoid_js_rounded_ints + - avoid_null_checks_in_equality_operators + - avoid_print + - avoid_redundant_argument_values + - avoid_relative_lib_imports + - avoid_renaming_method_parameters + - avoid_return_types_on_setters + - avoid_returning_null_for_void + - avoid_setters_without_getters + - avoid_shadowing_type_parameters + - avoid_single_cascade_in_expression_statements + - avoid_slow_async_io + - avoid_type_to_string + - avoid_types_as_parameter_names + - avoid_unnecessary_containers + - avoid_unused_constructor_parameters + - avoid_void_async + - await_only_futures + - camel_case_extensions + - camel_case_types + - cancel_subscriptions + - cast_nullable_to_non_nullable + - collection_methods_unrelated_type + - combinators_ordering + - conditional_uri_does_not_exist + - control_flow_in_finally + - curly_braces_in_flow_control_structures + - dangling_library_doc_comments + - depend_on_referenced_packages + - deprecated_consistency + - directives_ordering + - empty_catches + - empty_constructor_bodies + - empty_statements + - eol_at_end_of_file + - exhaustive_cases + - file_names + - flutter_style_todos + - hash_and_equals + - implementation_imports + - implicit_call_tearoffs + - implicit_reopen + - invalid_case_patterns + - invalid_runtime_check_with_js_interop_types + - leading_newlines_in_multiline_strings + - library_annotations + - library_names + - library_prefixes + - library_private_types_in_public_api + - literal_only_boolean_expressions + - missing_code_block_language_in_doc_comment + - missing_whitespace_between_adjacent_strings + - no_adjacent_strings_in_list + - no_default_cases + - no_duplicate_case_values + - no_leading_underscores_for_library_prefixes + - no_leading_underscores_for_local_identifiers + - no_literal_bool_comparisons + - no_logic_in_create_state + - no_self_assignments + - no_wildcard_variable_uses + - non_constant_identifier_names + - noop_primitive_operations + - null_check_on_nullable_type_parameter + - null_closures + - only_throw_errors # this does get disabled in a few places where we have legacy code that uses strings et al + - overridden_fields + - package_api_docs + - package_names + - package_prefixed_library_names + - prefer_adjacent_string_concatenation + - prefer_asserts_in_initializer_lists + - prefer_collection_literals + - prefer_conditional_assignment + - prefer_const_constructors + - prefer_const_constructors_in_immutables + - prefer_const_declarations + - prefer_const_literals_to_create_immutables + - prefer_contains + - prefer_final_fields + - prefer_final_in_for_each + - prefer_final_locals + - prefer_for_elements_to_map_fromIterable + - prefer_foreach + - prefer_function_declarations_over_variables + - prefer_generic_function_type_aliases + - prefer_if_elements_to_conditional_expressions + - prefer_if_null_operators + - prefer_initializing_formals + - prefer_inlined_adds + - prefer_interpolation_to_compose_strings + - prefer_is_empty + - prefer_is_not_empty + - prefer_is_not_operator + - prefer_iterable_whereType + - prefer_mixin + - prefer_null_aware_operators + - prefer_relative_imports + - prefer_single_quotes + - prefer_spread_collections + - prefer_typing_uninitialized_variables + - prefer_void_to_null + - provide_deprecation_message + - recursive_getters + - secure_pubspec_urls + - sized_box_for_whitespace + - sized_box_shrink_expand + - slash_for_doc_comments + - sort_child_properties_last + - sort_constructors_first + - sort_unnamed_constructors_first + - test_types_in_equals + - throw_in_finally + - tighten_type_of_initializing_formals + - type_init_formals + - type_literal_in_constant_pattern + - unnecessary_await_in_return + - unnecessary_brace_in_string_interps + - unnecessary_breaks + - unnecessary_const + - unnecessary_constructor_name + - unnecessary_getters_setters + - unnecessary_late + - unnecessary_library_directive + - unnecessary_new + - unnecessary_null_aware_assignments + - unnecessary_null_aware_operator_on_extension_on_nullable + - unnecessary_null_checks + - unnecessary_null_in_if_null_operators + - unnecessary_nullable_for_final_variable_declarations + - unnecessary_overrides + - unnecessary_parenthesis + - unnecessary_statements + - unnecessary_string_escapes + - unnecessary_string_interpolations + - unnecessary_this + - unnecessary_to_list_in_spreads + - unreachable_from_main + - unrelated_type_equality_checks + - unsafe_html + - use_build_context_synchronously + - use_colored_box + - use_enums + - use_full_hex_values_for_flutter_colors + - use_function_type_syntax_for_parameters + - use_if_null_to_convert_nulls_to_bools + - use_is_even_rather_than_modulo + - use_key_in_widget_constructors + - use_late_for_private_fields_and_variables + - use_named_constants + - use_raw_strings + - use_rethrow_when_possible + - use_setters_to_change_properties + - use_string_in_part_of_directives + - use_super_parameters + - use_test_throws_matchers + - valid_regexps + - void_checks diff --git a/example/lib/main.dart b/example/lib/main.dart index 58eeacc..fcb2549 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -2,10 +2,12 @@ import 'package:flutter/material.dart'; import 'package:number_pagination/number_pagination.dart'; void main() { - runApp(MyApp()); + runApp(const MyApp()); } class MyApp extends StatelessWidget { + const MyApp({super.key}); + @override Widget build(BuildContext context) { return MaterialApp( @@ -13,12 +15,14 @@ class MyApp extends StatelessWidget { theme: ThemeData( primarySwatch: Colors.blue, ), - home: Scaffold(body: MyHomePage()), + home: const Scaffold(body: MyHomePage()), ); } } class MyHomePage extends StatefulWidget { + const MyHomePage({super.key}); + @override State createState() => _MyHomePageState(); } diff --git a/example/pubspec.lock b/example/pubspec.lock index 81b037f..d97a1b3 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -63,26 +63,26 @@ packages: dependency: transitive description: name: leak_tracker - sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" url: "https://pub.dev" source: hosted - version: "10.0.0" + version: "10.0.5" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "3.0.5" leak_tracker_testing: dependency: transitive description: name: leak_tracker_testing - sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "3.0.1" matcher: dependency: transitive description: @@ -95,25 +95,25 @@ packages: dependency: transitive description: name: material_color_utilities - sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.8.0" + version: "0.11.1" meta: dependency: transitive description: name: meta - sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.15.0" number_pagination: dependency: "direct main" description: path: ".." relative: true source: path - version: "1.0.5" + version: "1.0.7" path: dependency: transitive description: @@ -171,10 +171,10 @@ packages: dependency: transitive description: name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" url: "https://pub.dev" source: hosted - version: "0.6.1" + version: "0.7.2" vector_math: dependency: transitive description: @@ -187,9 +187,10 @@ packages: dependency: transitive description: name: vm_service - sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" url: "https://pub.dev" source: hosted - version: "13.0.0" + version: "14.2.5" sdks: - dart: ">=3.2.0-0 <4.0.0" + dart: ">=3.3.0 <4.0.0" + flutter: ">=3.18.0-18.0.pre.54" diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart index 747db1d..f3c1285 100644 --- a/example/test/widget_test.dart +++ b/example/test/widget_test.dart @@ -5,15 +5,14 @@ // gestures. You can also use WidgetTester to find child widgets in the widget // tree, read text, and verify that the values of widget properties are correct. +import 'package:example/main.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:example/main.dart'; - void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. - await tester.pumpWidget(MyApp()); + await tester.pumpWidget(const MyApp()); // Verify that our counter starts at 0. expect(find.text('0'), findsOneWidget); diff --git a/lib/number_pagination.dart b/lib/number_pagination.dart index 32651de..b504abb 100644 --- a/lib/number_pagination.dart +++ b/lib/number_pagination.dart @@ -1,14 +1,14 @@ -library number_pagination; - import 'package:flutter/material.dart'; -import 'package:number_pagination/number_button.dart'; -import 'control_button.dart'; -import 'page_number_provider.dart'; +import 'src/control_button.dart'; +import 'src/number_button.dart'; +import 'src/number_page_container.dart'; +import 'src/page_number_provider.dart'; class NumberPagination extends StatelessWidget { /// Creates a NumberPagination - NumberPagination({ + const NumberPagination({ + super.key, required this.onPageChanged, required this.pageTotal, this.threshold = 10, @@ -118,7 +118,6 @@ class NumberPagination extends StatelessWidget { ), SizedBox(width: groupSpacing), Flexible( - fit: FlexFit.loose, child: ListenableBuilder( listenable: pageService, builder: (context, child) { @@ -183,8 +182,8 @@ class NumberPagination extends StatelessWidget { ); } - void _changePage(BuildContext context, targetPage) { - int newPage = targetPage.clamp(1, pageTotal); + void _changePage(BuildContext context, int targetPage) { + final int newPage = targetPage.clamp(1, pageTotal); if (NumberPageContainer.of(context).currentPage != newPage) { NumberPageContainer.of(context).currentPage = newPage; @@ -192,20 +191,3 @@ class NumberPagination extends StatelessWidget { } } } - -class NumberPageContainer extends InheritedWidget { - final NumberPageService pageService; - - const NumberPageContainer({required this.pageService, required super.child}); - - @override - bool updateShouldNotify(covariant NumberPageContainer oldWidget) { - return oldWidget.pageService != pageService; - } - - static NumberPageService of(BuildContext context) { - return context - .dependOnInheritedWidgetOfExactType()! - .pageService; - } -} diff --git a/lib/control_button.dart b/lib/src/control_button.dart similarity index 81% rename from lib/control_button.dart rename to lib/src/control_button.dart index 5677b55..cfde0ab 100644 --- a/lib/control_button.dart +++ b/lib/src/control_button.dart @@ -1,15 +1,9 @@ import 'package:flutter/material.dart'; class ControlButton extends StatelessWidget { - const ControlButton( - this.buttonElevation, - this.buttonRadius, - this.colorPrimary, - this.colorSub, - this.icon, - this.enabled, - this.onTap, - ); + const ControlButton(this.buttonElevation, this.buttonRadius, + this.colorPrimary, this.colorSub, this.icon, this.enabled, this.onTap, + {super.key}); final double buttonElevation; final double buttonRadius; @@ -29,7 +23,7 @@ class ControlButton extends StatelessWidget { ), surfaceTintColor: Colors.transparent, padding: EdgeInsets.zero, - minimumSize: Size(48, 48), + minimumSize: const Size(48, 48), foregroundColor: enabled ? colorPrimary : Colors.grey, backgroundColor: colorSub, disabledForegroundColor: colorPrimary, diff --git a/lib/number_button.dart b/lib/src/number_button.dart similarity index 84% rename from lib/number_button.dart rename to lib/src/number_button.dart index ef31205..3760adb 100644 --- a/lib/number_button.dart +++ b/lib/src/number_button.dart @@ -1,17 +1,17 @@ import 'package:flutter/material.dart'; -import 'number_pagination.dart'; +import 'number_page_container.dart'; class NumberButton extends StatelessWidget { const NumberButton( - this.number, - this.buttonElevation, - this.buttonRadius, - this.colorPrimary, - this.colorSub, - this.fontSize, - this.fontFamily, - this.onSelect, - ); + this.number, + this.buttonElevation, + this.buttonRadius, + this.colorPrimary, + this.colorSub, + this.fontSize, + this.fontFamily, + this.onSelect, + {super.key}); final int number; final double buttonElevation; @@ -38,7 +38,7 @@ class NumberButton extends StatelessWidget { borderRadius: BorderRadius.circular(buttonRadius), ), padding: EdgeInsets.zero, - minimumSize: Size(48, 48), + minimumSize: const Size(48, 48), foregroundColor: number == NumberPageContainer.of(context).currentPage ? colorSub @@ -52,7 +52,7 @@ class NumberButton extends StatelessWidget { onSelect(context, number); }, child: Text( - '${number}', + '$number', style: TextStyle( fontSize: fontSize, fontFamily: fontFamily, diff --git a/lib/src/number_page_container.dart b/lib/src/number_page_container.dart new file mode 100644 index 0000000..cb372c1 --- /dev/null +++ b/lib/src/number_page_container.dart @@ -0,0 +1,20 @@ +import 'package:flutter/material.dart'; + +import 'page_number_provider.dart'; + +class NumberPageContainer extends InheritedWidget { + + const NumberPageContainer({super.key, required this.pageService, required super.child}); + final NumberPageService pageService; + + @override + bool updateShouldNotify(covariant NumberPageContainer oldWidget) { + return oldWidget.pageService != pageService; + } + + static NumberPageService of(BuildContext context) { + return context + .dependOnInheritedWidgetOfExactType()! + .pageService; + } +} diff --git a/lib/page_number_provider.dart b/lib/src/page_number_provider.dart similarity index 100% rename from lib/page_number_provider.dart rename to lib/src/page_number_provider.dart index faddd2a..df090a0 100644 --- a/lib/page_number_provider.dart +++ b/lib/src/page_number_provider.dart @@ -1,10 +1,10 @@ import 'package:flutter/material.dart'; class NumberPageService with ChangeNotifier { - int _currentPage = -1; - int _previousPage = -1; NumberPageService(this._currentPage); + int _currentPage = -1; + int _previousPage = -1; set currentPage(int n) { _previousPage = _currentPage; diff --git a/pubspec.lock b/pubspec.lock index 203ecd5..6c70b99 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -54,6 +54,14 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_lints: + dependency: "direct dev" + description: + name: flutter_lints + sha256: "3f41d009ba7172d5ff9be5f6e6e6abb4300e263aab8866d2a0842ed2a70f8f0c" + url: "https://pub.dev" + source: hosted + version: "4.0.0" flutter_test: dependency: "direct dev" description: flutter @@ -63,18 +71,18 @@ packages: dependency: transitive description: name: leak_tracker - sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" + sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" url: "https://pub.dev" source: hosted - version: "10.0.4" + version: "10.0.5" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" + sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" url: "https://pub.dev" source: hosted - version: "3.0.3" + version: "3.0.5" leak_tracker_testing: dependency: transitive description: @@ -83,6 +91,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.1" + lints: + dependency: transitive + description: + name: lints + sha256: "976c774dd944a42e83e2467f4cc670daef7eed6295b10b36ae8c85bcbf828235" + url: "https://pub.dev" + source: hosted + version: "4.0.0" matcher: dependency: transitive description: @@ -95,18 +111,18 @@ packages: dependency: transitive description: name: material_color_utilities - sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.8.0" + version: "0.11.1" meta: dependency: transitive description: name: meta - sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.dev" source: hosted - version: "1.12.0" + version: "1.15.0" path: dependency: transitive description: @@ -164,10 +180,10 @@ packages: dependency: transitive description: name: test_api - sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" + sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" url: "https://pub.dev" source: hosted - version: "0.7.0" + version: "0.7.2" vector_math: dependency: transitive description: @@ -180,10 +196,10 @@ packages: dependency: transitive description: name: vm_service - sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" + sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" url: "https://pub.dev" source: hosted - version: "14.2.1" + version: "14.2.5" sdks: dart: ">=3.3.0 <4.0.0" flutter: ">=3.18.0-18.0.pre.54" diff --git a/pubspec.yaml b/pubspec.yaml index a9d1158..dcd63c0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: number_pagination description: Pagination using numbers, similar to the classic web-style pagination. Explore pages by numbers, not infinite scrolling! -version: 1.0.7 +version: 1.0.8 homepage: https://github.com/xpwmaosldk/number_pagination screenshots: @@ -21,8 +21,9 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter + flutter_lints: ^4.0.0 -flutter: +# flutter: topics: - page