feat: refactor

This commit is contained in:
Niels Gorter 2024-10-23 09:35:02 +02:00
parent ed8b5b401a
commit 1d7d9dd541
31 changed files with 413 additions and 256 deletions

View file

@ -1,9 +0,0 @@
include: package:flutter_iconica_analysis/analysis_options.yaml
# Possible to overwrite the rules from the package
analyzer:
exclude:
linter:
rules:

View file

@ -1,28 +0,0 @@
name: example
description: "Flutter_start example app"
publish_to: "none"
environment:
sdk: ">=3.2.5 <4.0.0"
dependencies:
flutter:
sdk: flutter
go_router: any
flutter_start:
path: ../
flutter_introduction_shared_preferences:
hosted: https://forgejo.internal.iconica.nl/api/packages/internal/pub/
version: ^5.0.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
flutter_iconica_analysis:
git:
url: https://github.com/Iconica-Development/flutter_iconica_analysis
ref: 6.0.0
flutter:
uses-material-design: true

View file

@ -1,6 +0,0 @@
export 'package:flutter_introduction/flutter_introduction.dart';
export 'package:flutter_introduction_shared_preferences/flutter_introduction_shared_preferences.dart';
export 'package:flutter_start/src/models/start_configuration.dart';
export 'package:flutter_start/src/routes.dart';
export 'package:flutter_start/src/user_stories/flutter_start_userstory_go_router.dart';
export 'package:flutter_start/src/user_stories/flutter_start_userstory_navigator.dart';

View file

@ -1,46 +0,0 @@
// SPDX-FileCopyrightText: 2023 Iconica
//
// SPDX-License-Identifier: BSD-3-Clause
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
/// Builds a screen with a fade transition.
///
/// The [context] parameter is the [BuildContext] in which this widget is built.
/// The [state] parameter is the [GoRouterState] that contains
/// the current routing state.
/// The [child] parameter is the widget that will be displayed on the screen.
///
/// Returns a [CustomTransitionPage] with a fade transition.
CustomTransitionPage buildScreenWithFadeTransition<T>({
required BuildContext context,
required GoRouterState state,
required Widget child,
}) =>
CustomTransitionPage<T>(
key: state.pageKey,
child: child,
transitionsBuilder: (context, animation, secondaryAnimation, child) =>
FadeTransition(opacity: animation, child: child),
);
/// Builds a screen without any transition.
///
/// The [context] parameter is the [BuildContext] in which this widget is built.
/// The [state] parameter is the [GoRouterState] that contains
/// the current routing state.
/// The [child] parameter is the widget that will be displayed on the screen.
///
/// Returns a [CustomTransitionPage] without any transition.
CustomTransitionPage buildScreenWithoutTransition<T>({
required BuildContext context,
required GoRouterState state,
required Widget child,
}) =>
CustomTransitionPage<T>(
key: state.pageKey,
child: child,
transitionsBuilder: (context, animation, secondaryAnimation, child) =>
child,
);

View file

@ -1,5 +0,0 @@
mixin StartUserStoryRoutes {
static const String splashScreen = '/splashScreen';
static const String introduction = '/introduction';
static const String home = '/home';
}

View file

@ -1,123 +0,0 @@
// SPDX-FileCopyrightText: 2023 Iconica
//
// SPDX-License-Identifier: BSD-3-Clause
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_introduction/flutter_introduction.dart';
import 'package:flutter_introduction_shared_preferences/flutter_introduction_shared_preferences.dart';
import 'package:flutter_start/src/go_router.dart';
import 'package:flutter_start/src/models/start_configuration.dart';
import 'package:flutter_start/src/routes.dart';
import 'package:flutter_start/src/services/killswitch_service.dart';
import 'package:flutter_start/src/widgets/default_splash_screen.dart';
import 'package:go_router/go_router.dart';
List<GoRoute> getStartStoryRoutes({
StartUserStoryConfiguration? configuration =
const StartUserStoryConfiguration(),
}) =>
<GoRoute>[
GoRoute(
path: StartUserStoryRoutes.splashScreen,
pageBuilder: (context, state) {
var go = context.go;
var isAllowedToPassThrough = false;
String? routeAfterSplash;
Future<void> splashLoadingMethod() async {
await Future.wait<void>(
[
Future.delayed(
Duration.zero,
() async {
if (configuration!.useKillswitch) {
var killswitchService = configuration.killswitchService ??
DefaultKillswitchService();
isAllowedToPassThrough =
await killswitchService.isKillswitchActive();
}
if (context.mounted)
routeAfterSplash = await configuration.splashScreenFuture
?.call(context) ??
configuration.homeScreenRoute;
},
),
Future.delayed(
Duration(
seconds: configuration!.minimumSplashScreenDuration,
),
() async {},
),
],
);
if (configuration.useKillswitch && isAllowedToPassThrough) return;
if ((!configuration.showIntroduction) && context.mounted) {
return go(
routeAfterSplash ?? StartUserStoryRoutes.home,
);
}
return go(StartUserStoryRoutes.introduction);
}
if (configuration!.splashScreenBuilder == null) {
unawaited(splashLoadingMethod());
}
return buildScreenWithoutTransition(
context: context,
state: state,
child: configuration.splashScreenBuilder?.call(
context,
() async => splashLoadingMethod(),
) ??
Scaffold(
backgroundColor: configuration.splashScreenBackgroundColor,
body: Center(
child:
configuration.splashScreenCenterWidget?.call(context) ??
defaultSplashScreen(context),
),
),
);
},
),
GoRoute(
path: StartUserStoryRoutes.introduction,
pageBuilder: (context, state) {
var introduction = Introduction(
service: configuration!.introductionService ??
IntroductionService(
SharedPreferencesIntroductionDataProvider(),
),
navigateTo: () {
context.go(
configuration.homeScreenRoute ?? StartUserStoryRoutes.home,
);
},
options: configuration.introductionOptionsBuilder?.call(context) ??
const IntroductionOptions(),
physics: configuration.introductionScrollPhysics,
child: configuration.introductionFallbackScreen,
);
return buildScreenWithoutTransition(
context: context,
state: state,
child: PopScope(
canPop: configuration.canPopFromIntroduction,
child: configuration.introductionBuilder?.call(
context,
introduction,
) ??
Scaffold(
body: introduction,
),
),
);
},
),
];

39
melos.yaml Normal file
View file

@ -0,0 +1,39 @@
name: flutter_start
packages:
- packages/**
command:
version:
branch: master
scripts:
lint:all:
run: dart run melos run analyze && dart run melos run format-check
description: Run all static analysis checks.
get:
run: |
melos exec -c 1 -- "flutter pub get"
melos exec --scope="*example*" -c 1 -- "flutter pub get"
upgrade:
run: melos exec -c 1 -- "flutter pub upgrade"
create:
# run create in the example folder of flutter_chat_view
run: melos exec --scope="*example*" -c 1 -- "flutter create ."
analyze:
run: |
dart run melos exec -c 1 -- \
flutter analyze --fatal-infos
description: Run `flutter analyze` for all packages.
format:
run: dart run melos exec dart format .
description: Run `dart format` for all packages.
format-check:
run: dart run melos exec dart format . --set-exit-if-changed
description: Run `dart format` checks for all packages.

View file

@ -21,7 +21,7 @@ class Home extends StatelessWidget {
@override
Widget build(BuildContext context) => NavigatorStartUserStory(
configuration: config,
// configuration: config,
onComplete: (context) async {
await Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context) => const HomeEntry()),
@ -30,17 +30,34 @@ class Home extends StatelessWidget {
);
}
List<GoRoute> getStartRoutes() => getStartStoryRoutes(
configuration: config,
);
StartUserStoryConfiguration config = StartUserStoryConfiguration(
// showIntroduction: false,
introductionService: MyIntroductionService(),
splashScreenBuilder: (context, onFinish) => SplashScreen(
onFinish: onFinish,
),
);
class MyIntroductionService implements IntroductionService {
@override
Future<void> onComplete() {
// TODO: implement onComplete
throw UnimplementedError();
}
@override
Future<void> onSkip() {
// TODO: implement onSkip
throw UnimplementedError();
}
@override
Future<bool> shouldShow() {
// TODO: implement shouldShow
throw UnimplementedError();
}
}
class SplashScreen extends StatefulWidget {
const SplashScreen({
required this.onFinish,

View file

@ -0,0 +1,53 @@
name: example
description: "Flutter_start example app"
publish_to: "none"
environment:
sdk: ">=3.2.5 <4.0.0"
dependencies:
flutter:
sdk: flutter
go_router: any
flutter_start:
path: ../flutter_start/
flutter_introduction_shared_preferences:
git:
url: https://github.com/Iconica-Development/flutter_introduction.git
path: packages/flutter_introduction_shared_preferences
ref: 5.0.0
# hosted: https://forgejo.internal.iconica.nl/api/packages/internal/pub/
# version: ^5.0.0
dependency_overrides:
flutter_data_interface:
git:
url: https://github.com/Iconica-Development/flutter_data_interface.git
ref: 1.0.1
flutter_introduction_interface:
git:
url: https://github.com/Iconica-Development/flutter_introduction.git
path: packages/flutter_introduction_interface
ref: 5.0.0
flutter_introduction_service:
git:
url: https://github.com/Iconica-Development/flutter_introduction.git
path: packages/flutter_introduction_service
ref: 5.0.0
flutter_introduction_widget:
git:
url: https://github.com/Iconica-Development/flutter_introduction.git
path: packages/flutter_introduction_widget
ref: 5.0.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
flutter_iconica_analysis:
git:
url: https://github.com/Iconica-Development/flutter_iconica_analysis
ref: 6.0.0
flutter:
uses-material-design: true

29
packages/flutter_start/.gitignore vendored Normal file
View file

@ -0,0 +1,29 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/
# IntelliJ related
*.iml
*.ipr
*.iws
.idea/
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
build/

View file

@ -0,0 +1,3 @@
## 0.0.1
* TODO: Describe initial release.

View file

@ -0,0 +1 @@
TODO: Add your license here.

View file

@ -0,0 +1,39 @@
<!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.
For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/tools/pub/writing-package-pages).
For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/to/develop-packages).
-->
TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.
## Features
TODO: List what your package can do. Maybe include images, gifs, or videos.
## Getting started
TODO: List prerequisites and provide or point to information on how to
start using the package.
## Usage
TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.
```dart
const like = 'sample';
```
## Additional information
TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.

View file

@ -0,0 +1,4 @@
include: package:flutter_lints/flutter.yaml
# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options

View file

@ -0,0 +1,4 @@
export 'package:flutter_introduction/flutter_introduction.dart';
export 'package:flutter_introduction_shared_preferences/flutter_introduction_shared_preferences.dart';
export 'src/models/start_configuration.dart';
export 'src/user_stories/flutter_start_userstory_navigator.dart';

View file

@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_introduction/flutter_introduction.dart';
import 'package:flutter_start/src/services/killswitch_service.dart';
import '../services/killswitch_service.dart';
/// An immutable class that represents the configuration for
/// starting a user story.

View file

@ -1,9 +1,9 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_start/flutter_start.dart';
import 'package:flutter_start/src/services/killswitch_service.dart';
import 'package:flutter_start/src/widgets/default_splash_screen.dart';
import '../../flutter_start.dart';
import '../services/killswitch_service.dart';
import '../widgets/default_splash_screen.dart';
/// Initial screen of the user story.
///

View file

@ -0,0 +1,63 @@
name: flutter_start
description: "Flutter_start is a package that allows you to jumpstart your application with a splashScreen, introduction and a home."
version: 4.2.1
# publish_to: https://forgejo.internal.iconica.nl/api/packages/internal/pub
publish_to: 'none'
environment:
sdk: ">=3.2.5 <4.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ">=1.0.2 <2.0.0"
go_router: ">=14.2.0 <15.0.0"
http: ">=1.2.1 <2.0.0"
package_info_plus: ">=8.0.0 <9.0.0"
flutter_introduction:
git:
url: https://github.com/Iconica-Development/flutter_introduction.git
path: packages/flutter_introduction
ref: 5.0.0
# hosted: https://forgejo.internal.iconica.nl/api/packages/internal/pub
# version: "^5.0.0"
flutter_introduction_shared_preferences:
git:
url: https://github.com/Iconica-Development/flutter_introduction.git
path: packages/flutter_introduction_shared_preferences
ref: 5.0.0
# hosted: https://forgejo.internal.iconica.nl/api/packages/internal/pub/
# version: ^5.0.0
dependency_overrides:
flutter_data_interface:
git:
url: https://github.com/Iconica-Development/flutter_data_interface.git
ref: 1.0.1
flutter_introduction_interface:
git:
url: https://github.com/Iconica-Development/flutter_introduction.git
path: packages/flutter_introduction_interface
ref: 5.0.0
flutter_introduction_service:
git:
url: https://github.com/Iconica-Development/flutter_introduction.git
path: packages/flutter_introduction_service
ref: 5.0.0
flutter_introduction_widget:
git:
url: https://github.com/Iconica-Development/flutter_introduction.git
path: packages/flutter_introduction_widget
ref: 5.0.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter_iconica_analysis:
git:
url: https://github.com/Iconica-Development/flutter_iconica_analysis
ref: 6.0.0
flutter:
uses-material-design: true

View file

@ -0,0 +1,29 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/
# IntelliJ related
*.iml
*.ipr
*.iws
.idea/
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
build/

View file

@ -0,0 +1,3 @@
## 0.0.1
* TODO: Describe initial release.

View file

@ -0,0 +1 @@
TODO: Add your license here.

View file

@ -0,0 +1,39 @@
<!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.
For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/tools/pub/writing-package-pages).
For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/to/develop-packages).
-->
TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.
## Features
TODO: List what your package can do. Maybe include images, gifs, or videos.
## Getting started
TODO: List prerequisites and provide or point to information on how to
start using the package.
## Usage
TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.
```dart
const like = 'sample';
```
## Additional information
TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.

View file

@ -0,0 +1,4 @@
include: package:flutter_lints/flutter.yaml
# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options

View file

@ -0,0 +1,7 @@
library start_repository_interface;
/// A Calculator.
class Calculator {
/// Returns [value] plus 1.
int addOne(int value) => value + 1;
}

View file

@ -0,0 +1,54 @@
name: start_repository_interface
description: "A new Flutter package project."
version: 0.0.1
homepage:
environment:
sdk: ^3.5.3
flutter: ">=1.17.0"
dependencies:
flutter:
sdk: flutter
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^4.0.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter packages.
flutter:
# To add assets to your package, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#
# For details regarding assets in packages, see
# https://flutter.dev/to/asset-from-package
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/to/resolution-aware-images
# To add custom fonts to your package, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.dev/to/font-from-package

View file

@ -0,0 +1,12 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:start_repository_interface/start_repository_interface.dart';
void main() {
test('adds one to input values', () {
final calculator = Calculator();
expect(calculator.addOne(2), 3);
expect(calculator.addOne(-7), -6);
expect(calculator.addOne(0), 1);
});
}

View file

@ -1,33 +1,6 @@
name: flutter_start
description: "Flutter_start is a package that allows you to jumpstart your application with a splashScreen, introduction and a home."
version: 4.2.1
publish_to: https://forgejo.internal.iconica.nl/api/packages/internal/pub
name: flutter_start_workspace
environment:
sdk: ">=3.2.5 <4.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ">=1.0.2 <2.0.0"
go_router: ">=14.2.0 <15.0.0"
http: ">=1.2.1 <2.0.0"
package_info_plus: ">=8.0.0 <9.0.0"
flutter_introduction:
hosted: https://forgejo.internal.iconica.nl/api/packages/internal/pub
version: "^5.0.0"
flutter_introduction_shared_preferences:
hosted: https://forgejo.internal.iconica.nl/api/packages/internal/pub/
version: ^5.0.0
sdk: ">=3.1.0 <4.0.0"
dev_dependencies:
flutter_test:
sdk: flutter
flutter_iconica_analysis:
git:
url: https://github.com/Iconica-Development/flutter_iconica_analysis
ref: 6.0.0
flutter:
uses-material-design: true
melos: ^6.1.0