Skip to content
This repository was archived by the owner on Apr 19, 2022. It is now read-only.

FrankBeu/staples

Repository files navigation

staples

a flutter-application for managing provisions

RESULT

./doc/BDD.png

run

disable null safety

flutter run  --no-sound-null-safety

update bloc

log

setup

create/copy nix-shell related files

nix .dir-locals.el .envrc shell.nix

ignore .direnv

flutter

flutter create --project-name staples .

Testing

https://www.youtube.com/channel/UCT-_RvXQ3TxFIoDT-WrnJLw/videos

add testing dependecies

flutter pub add -d bdd_widget_test
flutter pub add -d build_runner
flutter pub add -d golden_toolkit

BDD

Gherkin
be careful
fail
When I enter {'EAN-13'} text into {0} text field

will result in i_enter_text_into_text_field.dart

import 'package:flutter_test/flutter_test.dart';

Future<void> iEnterTextIntoTextField(WidgetTester tester, dynamic param1, dynamic param2) async {
  throw UnimplementedError();
}
success
When I enter {'EAN-13'} into {0} input field

^ ^^^ will result in i_enter_into_input_field.dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

/// Example: When I enter {'text'} into {1} input field
Future<void> iEnterIntoInputField(
  WidgetTester tester,
  String text,
  int index,
) async {
  final textField = find.byType(TextField).at(index);

  await tester.enterText(textField, text);
}
step-definitions in

~/.pub-cache/hosted/pub.dartlang.org/bdd_widget_test-1.2.1/lib/step/i_enter_into_input_field.dart

generate tests (steps have to be updated manually)
oneShot
flutter pub run build_runner build
only tests
flutter pub run build_runner build test
continuously
flutter pub run build_runner watch --delete-conflicting-outputs

Mocks

Mock dependencies using Mockito | Flutter

https://docs.flutter.dev/cookbook/testing/unit/mocking#3-create-a-test-file-with-a-mock-httpclient

mockito
flutter pub add -d mockito
mockito | Dart Package

https://pub.dev/packages/mockito

golden

https://medium.com/flutter-community/flutter-golden-tests-compare-widgets-with-snapshots-27f83f266cea https://pub.dev/packages/golden_toolkit

Add launch.json
to display golden-CodeLense
generate/update goldens
flutter test --update-goldens
flutter test --update-goldens --tags=golden
flutter test --update-goldens <PATH_TO_TEST_FILE>

Architecture

clean architecture

https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html

Flutter Clean Architecture & TDD Course - Reso Coder

https://resocoder.com/flutter-clean-architecture-tdd/

Flutter Clean Architecture Series — Part 1 | by AbdulMuaz Aqeel | Medium

https://devmuaz.medium.com/flutter-clean-architecture-series-part-1-d2d4c2e75c47 https://devmuaz.medium.com/flutter-clean-architecture-series-part-2-bcdf9d38fe41 https://devmuaz.medium.com/flutter-clean-architecture-series-part-3-cdfbcb8d449b https://github.com/devmuaz/flutter_clean_architecture/tree/part1_setup

Reflecting architecture and domain in code – @hgraca

https://herbertograca.com/2019/06/05/reflecting-architecture-and-domain-in-code/

A Flutter BLoC + Clean Architecture journey to release the #1st Idean Flutter app | by Etienne Cadic | Ideas by Idean | Medium

https://medium.com/ideas-by-idean/a-flutter-bloc-clean-architecture-journey-to-release-the-1st-idean-flutter-app-db218021a804

split layers into packages

at projectRoot: lib presentation layer: All the UI stuff, widgets and design utils data layer: All the input data stuff (from async sources) core useful to share code between layers domain layer: the business layer, manipulating pure entities through usecases.

create directory-tree

in lib and test

do not use verticalPartitioning (one tree for each feature)
mkdir -p config/{routes,themes} \
         core/utils \
         data/{datasources/{local,remote},models,repositories} \
         domain/{entities,repositories,usecases} \
         presentation/{bloc,views,widgets}
mkdir -p config core data/{datasources/{local,remote},models,repositories} domain/{entities,repositories,usecases} presentation/{bloc,views,widgets}

Dependencies

serviceLocator

flutter pub add get_it
DependencyInjection
  • State “TODO” from [2021-11-29 Mon 18:31]
https://pub.dev/packages/injectable
flutter pub add injectable
flutter pub add -d injectable_generator
use buildrunner

stateManagement

flutter pub add flutter_bloc

valueEquality

flutter pub add equatable
Dart Equatable Package: Simplify Equality Comparisons | by Felix Angelov | Flutter Community | Medium

https://medium.com/flutter-community/dart-equatable-package-simplify-equality-comparisons-1a96a3fc4864

functionalProgramming

flutter pub add dartz

remote

flutter pub add data_connection_checker
flutter pub add http

cache

flutter pub add shared_preferences

Routing

Navigator1.0 examples not working - use Navigator2.0 instead

Navigation

https://bloclibrary.dev/#/recipesflutternavigation?id=navigation-20

flutter pub add flow_builder

Navigating Navigator 2.0 with Flow Builder

https://verygood.ventures/blog/navigator-with-flow-builder

Feature: Products

DOMAIN

EAN-13
International Article Number - Wikipedia

https://en.wikipedia.org/wiki/International_Article_Number

difference GTIN - EAN
GTIN GlobalTradeItemNumber. GTIN is the series of numbers associated with a barcode. GTIN codes are part of larger global data structures that help identify a company’s unique product. UPC, EAN, and ISBN are all GTINs. GTIN is the number encoded into either a UPC, EAN, or ISBN barcode.
run only specified tests

https://pub.dev/packages/test#tagging-tests because bdd-Tests are generated, they cannot be tagged. Tag unit tests instead

NOT-WORKING annotations

The annotation ‘Tags’ can only be used on libraries (lsp)

@Tags(['unit', 'FEATURE-NAME'])
flutter test -t unit products
use test-parameter instead
test('should ...',
    () async {
  when()
      .thenAnswer();

  // act
  final result = await actor()

  // assert
  expect();
  verify();
  verifyNoMoreInteractions();
}, tags: ['unit', 'product']);
usage
flutter test -t unit,product
flutter test -t "(unit) && !(product)"
tests
empty test-files will break the run
configuration
test/configuration.md at master · dart-lang/test
  • State “TODO” from [2021-12-01 Wed 18:26]
https://github.com/dart-lang/test/blob/master/pkgs/test/doc/configuration.md#configuring-tags
generate entity

the main dataProvider will be ecoinform.de roughly base the entity on the provided data

example

./doc/productTarget.html

use categories-tree
item
class Item extends Product {

  //...
  final Date bb; // BestBefore(End)
  final int _priceInCent;

  double get price(int priceInCent) => double(priceInCent/100);
  int set _priceInCent(num price) => price is int ? price : price * 100;
  //...
}
TDD
mocks
have to be generated automatically because of nullSafty https://github.com/dart-lang/mockito/blob/master/NULL_SAFETY_README.md
  1. import mockito
    import 'package:mockito/annotations.dart';
    import 'package:mockito/mockito.dart';
        
  2. annotate
    @GenerateMocks([ProductRepository])
        
  3. generate mocks
    flutter pub run build_runner build
        
  4. import generated mocks
    import 'getAllProducts_test.mocks.dart'
        
  5. use

DATA

DAO

DataAccessObject

Floor
floor | Flutter Package

https://pub.dev/packages/floor

flutter pub add floor
flutter pub add sqflite
flutter pub add floor_generator -d

TODOS

localization

google/app-resource-bundle

https://github.com/google/app-resource-bundle

Flutter ARB file (.arb) - Localizely

https://localizely.com/flutter-arb/

A Localization and Translation Software Tool | Lokalise

https://lokalise.com/

staticLinting??

Code Quality and Code Security | SonarQube

https://www.sonarqube.org/

testReporting

Flutter Test Reports : Current state of art | by Etienne Cadic | Ideas by Idean | Medium

https://medium.com/ideas-by-idean/flutter-test-reports-in-cis-current-state-of-art-8968b0c8dd4a

persistence

floor | Flutter Package

https://pub.dev/packages/floor

apiCalls

retrofit | Dart Package

https://pub.dev/packages/retrofit

hooks

flutter_hooks | Flutter Package

https://pub.dev/packages/flutter_hooks

storeFetchedImages

where??

how to test local state

sourceOfTruth for

syncing??

would you like to send or fetch data diffing??

[#A] The Software Architecture Chronicles – @hgraca

https://herbertograca.com/2017/07/03/the-software-architecture-chronicles/

hgraca/explicit-architecture-php: This repository is a demo of Explicit Architecture, using the Symfony Demo Application.

https://github.com/hgraca/explicit-architecture-php

WORKFLOW

create FEATURE.feature

start by defining a BDD-Feature

TDD

write test first

mocks

generate mocks automatically
by implementing the nec dependencies
annotate with

NAME_test.dart

@GenerateMocks([http.Client])
treat compilation-errors of missing mockées as usual
DEPRECATED generate mocks manually

always start at the innermost center

Entities - have no dependencies

DOMAIN

TDD

DATA

TDD

PRESENTATION

BLoC

TDD

register for DI

Presentation

create a dummy first

Placeholder class - widgets library - Dart API

https://api.flutter.dev/flutter/widgets/Placeholder-class.html

Widgets

BDD

Pages

BDD

secure UI with goldenTests

after FEATURE.feature passes