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

Flutter研修【ミクシィ22新卒技術研修】

 Flutter研修【ミクシィ22新卒技術研修】

22新卒技術研修で実施したFlutter研修の講義資料です。
動画:https://youtu.be/oQCJZFqDwIo

ハンズオン用リポジトリ
https://github.com/mixigroup/2022BeginnerTrainingFlutter

MIXI ENGINEERS

April 28, 2022
Tweet

More Decks by MIXI ENGINEERS

Other Decks in Programming

Transcript

  1. ͓඼ॻ͖ ʙ'MVUUFSͱ͸ ʙ'MVUUFSDSFBUFͰΞϓϦΛ࡞ͬͯΈΑ͏ ʙٳܜ ʙDSFBUF͞ΕͨΞϓϦΛݟ͍ͯ͜͏ *OUSPEVDUJPO 4UBUF ʙϥϯν 5FYU'JFME ը໘ભҠ

    ʙ(SBQI2-äͱ͸ʁ ʙ(SBQI2-Λ৮ͬͯΈΑ͏ (SBQI2-2VFSZ (SBQI2-.VUBUJPO ʙνʔϜͰνϟϨϯδʂ8PSEMFΛ࡞ͬͯΈΑ͏ʂ ʙΫϩʔδϯά
  2. ࣄલ४උ J04ಈ͔͍ͨ͠ਓɹ "OESPJEಈ͔͍ͨ͠ਓɹ w 9DPEFͷΠϯετʔϧ͓Αͼղౚ w Πϯετʔϧ͸"QQ4UPSFͰ͸ͳ͘EFWFMPQFSαΠτ͔Βམͱͯ͘͠Δ͜ͱΛ͓קΊ w IUUQTEFWFMPQFSBQQMFDPNEPXOMPBENPSF w

    ࣄલʹ"QQMF*%͕ඞཁ w ձࣾͷϝʔϧΞυϨεͰΞΧ΢ϯτΛ࡞੒ w "OESPJE4UVEJPͷΠϯετʔϧ͓Αͼղౚ w Ұ୴ىಈ͠ͳ͍ͱ fl VUUFSEPDUPSͨ͠ͱ͖ʹ6OBCMFUPMPDBUF"OESPJE4%,ͷΤϥʔʹͳΔ
  3. ࣮ߦ࣌ʹOVMMͷΤϥʔͰ མͪΔ͜ͱ͸ͳ͘ͳΔ ʢEBSUYͷ৔߹͸ίϯύΠϧ࣌ʹΤϥʔʹͳΔʣ /VMM4BGFUZͬͯʁ BʹOVMM͸୅ೖͰ͖ͳ͍ جຊOVMMΛड͚෇͚ͳ͍ͷͰ ࢖͍͍ͨ࣌͸ Λ͚ͭΔ int a

    = 100; int? b = null; a = null; // Τϥʔ print(a + b); // Τϥʔ if (b != null) { print(a + b); } print(a + (b ?? 0)); C͕OVMMͷ࣌͸ආ͚ ͯ͘ΕΔͷͰ҆৺ EBSU΍/VMM4BGFUZͳݴޠͷ৔߹
  4. ࣮ߦ࣌ʹOVMMͷΤϥʔͰ མͪΔ͜ͱ͸ͳ͘ͳΔ ʢEBSUYͷ৔߹͸ίϯύΠϧ࣌ʹΤϥʔʹͳΔʣ /VMM4BGFUZͬͯʁ BʹOVMM͸୅ೖͰ͖ͳ͍ جຊOVMMΛड͚෇͚ͳ͍ͷͰ ࢖͍͍ͨ࣌͸ Λ͚ͭΔ int a

    = 100; int? b = null; a = null; // Τϥʔ print(a + b); // Τϥʔ if (b != null) { print(a + b); } print(a + (b ?? 0)); C͕OVMMͷ࣌͸ආ͚ ͯ͘ΕΔͷͰ҆৺ EBSU΍/VMM4BGFUZͳݴޠͷ৔߹ C͕OVMMͩͬͨΒ Λ࢖͏ͱ͍͏ҙຯ
  5. ࣮ߦ࣌ʹOVMMͷΤϥʔͰ མͪΔ͜ͱ͸ͳ͘ͳΔ ʢEBSUYͷ৔߹͸ίϯύΠϧ࣌ʹΤϥʔʹͳΔʣ /VMM4BGFUZͬͯʁ BʹOVMM͸୅ೖͰ͖ͳ͍ جຊOVMMΛड͚෇͚ͳ͍ͷͰ ࢖͍͍ͨ࣌͸ Λ͚ͭΔ int a

    = 100; int? b = null; a = null; // Τϥʔ print(a + b); // Τϥʔ if (b != null) { print(a + b); } print(a + (b ?? 0)); C͕OVMMͷ࣌͸ආ͚ ͯ͘ΕΔͷͰ҆৺ EBSU΍/VMM4BGFUZͳݴޠͷ৔߹ C͕OVMMͩͬͨΒ Λ࢖͏ͱ͍͏ҙຯ ઈରOVMM͡Όͳ͍ʂͬͯ৔߹͸ ɹɹͱॻ͘͜ͱ΋Ͱ͖Δ b!
  6. label = UILabel() label.text = “Babu~” label.textColor = .black label.textAlignment

    = .center view.addSubview(label) Text( “Babu~", style: TextStyle(color: Colors.black), textAlign: TextAlign.center, ), ໋ྩతʢ4XJGUʣ એݴత6*ͬͯʁ એݴతʢ%BSUʣ ϥϕϧΛ࡞Εʂ ϥϕϧͷςΩετ͸όϒʙͰ͋Εʂ ৭͸ࠇͰ͋ΕʂਅΜதدͤͰ͋Εʂ ͦͷϥϕϧΛ7JFXʹ௥Ճͤ͑ʂ
  7. label = UILabel() label.text = “Babu~” label.textColor = .black label.textAlignment

    = .center view.addSubview(label) Text( “Babu~", style: TextStyle(color: Colors.black), textAlign: TextAlign.center, ), ໋ྩతʢ4XJGUʣ એݴత6*ͬͯʁ એݴతʢ%BSUʣ զ͸όϒʙͱ͍͏ࠇ৭ͷ ਅΜதدͤςΩετͰ͋Δʂ
  8. ΞϓϦΛ࡞ͬͯΈΑ͏ $ flutter create <<ϓϩδΣΫτͷ໊લ>> $ cd <<ϓϩδΣΫτͷ໊લ>> $ open

    iOS/Runner.xcworkspace // ios ͷਓͷΈ $ flutter run "OESPJEͷਓ͸࣮ػબ୒΋͘͠͸ "OESPJEελδΦ্ཱͪ͛ͯΤϛϡબ୒ ϓϩδΣΫτ໊͸ΞϯμόʔͰܨ͕ͳ͍ͱ ʰzϓϩδΣΫτ໊zJTOPUBWBMJE%BSUQBDLBHFOBNFʱ ͬͯΤϥʔుౖ͍ͯΒΕΔ
  9. *OUSPEVDUJPO IUUQTHJUIVCDPNNJYJHSPVQ#FHJOOFS5SBJOJOH'MVUUFSQVMM w ϓϩδΣΫτʢσΟϨΫτϦʣߏ੒ʹ͍ͭͯ w NBJO ͷྲྀΕ΍DMBTTͷઆ໌ w 5FYUͷத਎Λม͑ͯΈͨΓ͢Δ w

    )PU3FMPBE3FTUBSUͱ͸ʁʢผϖʔδͰઆ໌ʣ w .Z)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USBJOUT X I*O fi OJUZ  MBZFS0 ff TFU-BZFSGF%&5"$)&% ɽɽɽ
  12. $PMVNOͷதʹ(SJE7JFXΛೖΕΔͱ͖͸஫ҙʂ w (SJE7JFX΋޿͕Ζ͏ͱͯ͘͠Δੑ࣭Λ࣋ͭͷͰΤϥʔʹͳΓ·͢ 5IFGPMMPXJOH3FOEFS0CKFDUXBTCFJOHQSPDFTTFEXIFOUIFFYDFQUJPOXBT fi SFE 3FOEFS7JFXQPSUCEEF/&&%4-":065 /&&%41"*/5/&&%4$0.104*5*/(#*5461%"5& OFFETDPNQPTJUJOH DSFBUPS7JFXQPSUˡ*HOPSF1PJOUFS<(MPCBM,FZCC>ˡ4FNBOUJDTˡ-JTUFOFSˡ

    @(FTUVSF4FNBOUJDTˡ 3BX(FTUVSF%FUFDUPS<-BCFMFE(MPCBM,FZ3BX(FTUVSF%FUFDUPS4UBUF>ˡ-JTUFOFSˡ @4DSPMMBCMF4DPQF ˡ@4DSPMM4FNBOUJDT<(MPCBM,FZFGC>ˡ/PUJ fi DBUJPO-JTUFOFS4DSPMM.FUSJDT/PUJ fi DBUJPOˡ 4DSPMMBCMFˡ1SJNBSZ4DSPMM$POUSPMMFSˡl QBSFOU%BUBOPOF DBOVTFTJ[F  DPOTUSBJOUT#PY$POTUSBJOUT X I*O fi OJUZ  MBZFS0 ff TFU-BZFSGF%&5"$)&% ɽɽɽ *O fi OJUZʂʂ
  13. 5SZഒʹ͠Α͏ղઆ w ৽͍͠4UBUFΛఆٛ w ഒ͢ΔϝιουΛఆٛ w ഒ͢ΔϝιουΛݺͿϘλϯΛ௥Ճ void _twice() {

    setState(() { _counter2 = _counter2 * 2; }); } TextButton( onPressed: () { _twice(); },
  14. ը໘ભҠ " .BUFSJBM"QQ͕͍࣋ͬͯΔ/BWJHBUPSΛ࢖ͬͯը໘ભҠ͢Δ " # .BUFSJBM1BHF3PVUF Navigator.push( context, MaterialPageRoute<void>( builder:

    (BuildContext context) => B(), ), ); Navigator.pop(conte 8JEHFU ࠓճ͸4FDPOE1BHF Λ .BUFSJBM1BHF3PVUFʹ౉ͯ͠ 3PVUFΛ࡞ΓɼͦΕΛදࣔ
  15. .BUFSJBM"QQʹ͋Β͔͡Ί3PVUFΛొ࿥͓ͯ͜͠͏ʂ return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.pink,

    ), initialRoute: '/', routes: <String, WidgetBuilder>{ '/': (BuildContext context) => const FirstPage(), '/second': (BuildContext context) => const SecondPage(), }, ); ͜ΕͰݺ΂ΔΑ͏ʹͳΔʂ Navigator.pushNamed(context, "/second");
  16. (SBQI2-ͱ3&45ͷൺֱ 3&45 (SBQI2- User: { “Name” : “kuno”, “Company” :

    “mixi”, “Sex” : “f”, “Web” : “kunoayana.com”, } query getUser(userId: userId) { User { name company } } (&5BQJVTFST\VTFS*E^ ໊લͱձ໊͚ࣾͩ ཉ͍͠ͷʹ͜ͷ"1*ͩͱଞͷ৘ใ·Ͱ Ҿͬு͖ͬͯͪΌ͏ʜ ࠓඞཁͳσʔλ͚ͩ औಘͰ͖Δʂ
  17. w (SBQI2-Λ'MVUUFSͰ࢖͏ͨΊͷϥΠϒϥϦΛೖΕΑ͏ w λʔϛφϧͰ w IUUQTQVCEFWQBDLBHFTHSBQIRM w ·ͣ2VFSZݺͿͨΊͷϝιουΛੜ΍ͦ͏ w ϝιουͷதͰ2VFSZΛݺΜͰΈΑ͏ʂ

    w 3FBENFͷίϐϖͰେৎ෉ʂ w ϢʔβҰཡΫΤϦͰड͚औͬͨσʔλΛදࣔͯ͠ΈΑ͏ʂ w ωοτϫʔΫ͸EFWUPPMͰݟΕΔʂʢผϖʔδͰઆ໌ʣ (SBQI2-2VFSZΛ࢖ͬͯΈΑ͏ʂ  fl VUUFSQVCBEEHSBQIRM
  18. #VJME$POUFYUͬͯͳ͋ʹʁ ͦ΋ͦ΋8JEHFU͸ӈਤͷΑ͏ʹπϦʔঢ়ʹͳ͍ͬͯΔ #VJME$POUFYU͸݂ےͷ͜ͱͰ૆ઌͷ৘ใʹΞΫηε͢Δ͜ͱ͕Ͱ͖Δ ˞௚ܥͷ૆ઌ͔͠ḷΕͳ͍ʂ ˞ͭͷ8JEHFUͷΠϯελϯεʹରͯ͠ ɹͭͷ#VJME$POUFYU͕ϖΞͷؔ܎ʹͳ͍ͬͯΔʂ 5IFNF PSBOHF 8JEHFU" 5IFNF

    QJOL 8JEHFU$ .BUFSJBM"QQ 5IFNF CMVF 4DB ff PME ࣮ߦ݁Ռʢ࣮૷͸ͪ͜Βʣ 8JEHFU# 3PX $PMVNO ͸ࣗ෼ͷ݂ےΛͨͲͬͯ ૆ઌʹ͋Δ5IFNFΛݟ͚͖͍ͭͯͯΔ Theme.of(context) 8JEHFU#ͷ݂ےΛḷͬͨΒ ͜͜ͷ5IFNF͕ݟ͔ͭͬͨʂ