Upgrade to Pro — share decks privately, control downloads, hide ads and more …

BLoC

 BLoC

flutter meetup #2の資料です

Shinnosuke Kugimiya

May 31, 2018
Tweet

More Decks by Shinnosuke Kugimiya

Other Decks in Programming

Transcript

  1. © DMM.com #-P$ͷΨΠυϥΠϯ   JOQVUTBOEPVUQVUTBSFTJNQMF4USFBNT4JOLTPOMZ  %FQFOEFODJFTNVTUCFJOKFDUBCMFBOEQMBUGPSN BHOPTUJD 

    /PQMBUGPSNCSBODIJOHBMMPXFE  *NQMFNFOUBUJPODBOCFXIBUFWFSZPVXBOUJGZPV GPMMPXUIFQSFWJPVTSVMFT " #VUNBZ*TVHHFTUSFBDUJWFQSPHSBNNJOH
  2. © DMM.com #-P$ͷΨΠυϥΠϯ   JOQVU͸4JOLɺPVUQVU͸4USFBNͰ࣮૷͢Δ  ґଘΦϒδΣΫτ͸֎͔Β஫ೖՄೳͰɺϓϥοτ ϑΥʔϜʹґଘ͠ͳ͍΋ͷͰ͋Δ͜ͱ 

    ϓϥοτϑΥʔϜͷ෼ذ͸μϝ  dΛकͬͯΕ͹ɺ࣮૷͸ͳΜͰ΋͍͍Α  ͨͩ͠ɺ3FBDUJWF1SPHSBNNJOHͰ૊Ήͷ͕͓͢͢ΊͩΑ
  3. © DMM.com #-P$ͱ6*ͷܨ͗   &BDIDPNQMFYFOPVHIDPNQPOFOUIBTB DPSSFTQPOEJOH#-P$  $PNQPOFOUTTIPVMETFOEJOQVUTBTJTz 

    $PNQPOFOUTTIPVMETIPXPVUQVUTBTDMPTFBT QPTTJCMFUPBTJTz  "MMCSBODIJOHTIPVMECFCBTFEPOTJNQMF#-P$ CPPMFBOPVUQVUT
  4. © DMM.com #-P$ͷྫ  class CartBLoC { Sink<Product> addition; Stream<int>

    itemCount; Stream<String> totalCost; Stream<List<CartItem>> items; }
  5. © DMM.com #-P$ͷྫ  class CartBLoC { Sink<Product> addition; Stream<int>

    itemCount; Stream<String> totalCost; Stream<List<CartItem>> items; } 1SPEVDU͕௥Ճ͞ΕΔͱ
  6. © DMM.com #-P$ͷྫ  class CartBLoC { Sink<Product> addition; Stream<int>

    itemCount; Stream<String> totalCost; Stream<List<CartItem>> items; } ͦΕͧΕͷ4USFBN͔Β݁Ռ͕ྲྀΕΔ
  7. © DMM.com JOQVU΁ͷܨ͛ํ  TextField( onChanged: bloc.sink.add, decoration: InputDecoration( border:

    OutlineInputBorder(), ɹɹɹ hintText: “hint"), ) ΠϕϯτͱTJOLBEEΛόΠϯυ͢Δ͚ͩ
  8. © DMM.com PVUQVUΛ6*ʹͭͳ͛Δํ๏  StreamBuilder<String>( stream: bloc.stream, builder: (context, snapshot)

    => Container( child: Text(snapshot?.data ?? ""), ), ) 4USFBN#VJMEFS࢖͏͚ͩ
  9. © DMM.com  w #-P$͸6*ͱ.PEFMͱ*OGSBΛ෼͚Δ͜ͱͱɺΫϩε ϓϥοτϑΥʔϜͷίʔυγΣΞΛϞνϕʔγϣϯ ʹੜ·Εͨ w कΔ΂͖ΨΠυϥΠϯ͕͋Δ w

    'MVUUFSͰ͸ w JOQVUΛૹΔͱ͜ΖͰ͸TJOLBEEΛόΠϯυ͢Δ w PVUQVUΛTVCTDSJCF͢Δʹ͸4USFBN#VJMEFSΛ࢖͏ ·ͱΊ