Slide 1

Slide 1 text

΍΍complexͳBLoC΁ͷରԠ Hiroki Matsue Jan 30th, 2019 Flutter Meetup Tokyo #7

Slide 2

Slide 2 text

Hiroki Matsue (@macs_6)

Slide 3

Slide 3 text

IIJmio޲͚ʮΈ͓εΠονʯ (Flutter੡)

Slide 4

Slide 4 text

analysis͸࢝Ίʹઃఆ͠Α͏ omit_local_variable_types༗ޮʹ͠·͠ΐ͏ https://www.dartlang.org/guides/language/effective-dart/design#avoid-type-annotating- initialized-local-variables

Slide 5

Slide 5 text

લճ͸Dart೉ಡԽͷ࿩

Slide 6

Slide 6 text

ࠓճ͸BLoCͷ࿩

Slide 7

Slide 7 text

BLoCͷ͓͞Β͍

Slide 8

Slide 8 text

Business Logic Componentsύλʔϯ

Slide 9

Slide 9 text

Google I/O '18: https://www.youtube.com/watch? v=RS36gBEp8OI

Slide 10

Slide 10 text

Google I/O '18: https://www.youtube.com/watch? v=RS36gBEp8OI

Slide 11

Slide 11 text

Google I/O '18: https://www.youtube.com/watch? v=RS36gBEp8OI

Slide 12

Slide 12 text

ϓϩτλΠϓҎ߱ͷϑΣʔζ͸ɺBLoC ΍Reduxಋೖ͓ͯ͘͠ͱ҆৺

Slide 13

Slide 13 text

ը໘1ͭʹBLoC1ͭͷγϯϓϧͳ ঢ়ଶ؅ཧͷ৔߹

Slide 14

Slide 14 text

buttonͦΕͧΕʹLoading΍ErrorΛ දݱ͍ͨ͠ (ΞΠςϜҰཡ͔Β1ͭΛ͓ؾʹೖΓɺΧʔυʹೖΕΔɺetc)

Slide 15

Slide 15 text

͜Μͳ࣌

Slide 16

Slide 16 text

αϯϓϧ࣮૷Ͱͷ૝ఆσʔλߏ଄ - ܖ໿1 - sim1 - sim2 - ... - ܖ໿2 - ... - ...

Slide 17

Slide 17 text

·ͣܖ໿ͱSIM2ͭͷBLoCΛܨ͙ You should avoid having one BLoC as a parameter of another BLoC. Instead, plug only the required outputs to the applicable inputs. This helps avoid tight coupling. https://medium.com/flutter-io/build-reactive-mobile-apps-in-flutter-companion- article-13950959e381 _bloc = SimBloc(widget.sim); // ܖ໿BLoCͷstreamΛSIMBLoC͕listen _subscription = widget.simsStream.listen(_bloc.sims.add);

Slide 18

Slide 18 text

ܨ͍ͩΒ2ͭ໨ͷBLoC಺ʹࢦఆͨ͠ SIMΛॲཧ͢ΔϩδοΫΛॻ͘

Slide 19

Slide 19 text

class SimBloc { SimBloc(Sim sim) { _simController.stream .map((list) => list.firstWhere((s) => s == sim, orElse: () => null)) .listen((sim) { if (sim == null) { log(errorMessage); // print log and send error to Sentry return; } _simSubject.add(SimState( switchingStatus: SimSwitchingStatus.fulfilled, isEnabled: sim.isEnabled, usage: sim.inMonthUsage(), )); ...

Slide 20

Slide 20 text

ࢀߟ: filiph/state_experiments@github (ಛʹbloc_complexपΓ)

Slide 21

Slide 21 text

BLoCಋೖͯ͠ྑ͔ͬͨ͜ͱ • ϘλϯͷΑ͏ͳ୯ҐͰͷঢ়ଶΛ؅ཧ͠΍͘͢ͳͬͨ • ςετ͕ॻ͖΍͘͢ͳͬͨ

Slide 22

Slide 22 text

Έ͓εΠονɺੋඇ͝ར༻͍ͩ͘͞

Slide 23

Slide 23 text

Thanks