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

[DroidconKE]Accelerate Flutter Apps Development

[DroidconKE]Accelerate Flutter Apps Development

This is my presentation file on DroidconKE 2019.

#Droidcon
#DroidconKE
#Flutter
#mobile

Kenichi Kambara

August 08, 2019
Tweet

More Decks by Kenichi Kambara

Other Decks in Technology

Transcript

  1. About me • Mobile App Development • Technical Speeches •

    Droidcon UK/FR/NL/ES/SH • Devoxx UA • GDG DevFest Pisa • Developers Summit • Android Bazaar and Conference • StackOverflow DevDays • Cloud Days • Google I/O Extended Tokyo 2018 •Technical Writings •[Official] NTT TechnoCross •[Private] iplatform.org Kenichi Kambara (@korodroid)
  2.   Cross-Platform Activity (StackOverflow) Number of StackOverflow question views

    tagged with each of four popular UI frameworks over time (https://bit.ly/2A0tzuK)
  3.   Cross-Platform Activity (StackOverflow) Number of StackOverflow question views

    tagged with each of four popular UI frameworks over time (https://bit.ly/2A0tzuK)
  4. 1. Has known a bit about “Flutter”? 2. Has developed

    “Hello Flutter”? 3. Has developed any Flutter apps? 4. Has published any Flutter apps? ? Questions
  5. Very similar to Java/Java Script import 'package:flutter/material.dart'; void main() {

    runApp( Center( child: Text( ‘Hello, Flutter', textDirection: TextDirection.ltr, ), ), ); }   3. Dart
  6. Very similar to Java/Java Script import 'package:flutter/material.dart'; void main() {

    runApp( Center( child: Text( ‘Hello, Flutter', textDirection: TextDirection.ltr, ), ), ); }   3. Dart
  7. Very similar to Java/Java Script import 'package:flutter/material.dart'; void main() {

    runApp( Center( child: Text( ‘Hello, Flutter', textDirection: TextDirection.ltr, ), ), ); }   3. Dart
  8. Very similar to Java/Java Script import 'package:flutter/material.dart'; void main() {

    runApp( Center( child: Text( ‘Hello, Flutter', textDirection: TextDirection.ltr, ), ), ); }   3. Dart
  9. Very similar to Java/Java Script import 'package:flutter/material.dart'; void main() {

    runApp( Center( child: Text( ‘Hello, Flutter', textDirection: TextDirection.ltr, ), ), ); }   3. Dart Note: Optional “new”, “const” from Dart 2.x
  10. Simple Flutter Material App import 'package:flutter/material.dart'; void main() => runApp(MyApp());

    class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Welcome to Flutter', home: Scaffold( appBar: AppBar( title: Text(‘My First Flutter'), ), body: Center( child: Text(‘Hello, Flutter'), ), ), ); } } change to the below code (<project>/libs/main.dart)  
  11. Simple Flutter Material App import 'package:flutter/material.dart'; void main() => runApp(MyApp());

    class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Welcome to Flutter', home: Scaffold( appBar: AppBar( title: Text(‘My First Flutter'), ), body: Center( child: Text(‘Hello, Flutter'), ), ), ); } }   Writing Dart code for Layout ( LayoutXML, StoryBoard)
  12. Simple Flutter Material App import 'package:flutter/material.dart'; void main() => runApp(MyApp());

    class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Welcome to Flutter', home: Scaffold( appBar: AppBar( title: Text(‘My First Flutter'), ), body: Center( child: Text(‘Hello, Flutter'), ), ), ); } } change to the below code (<project>/libs/main.dart)  
  13. StatefulWidget (Dynamic Screen Update) class MyApp extends StatelessWidget { @override

    Widget build(BuildContext context) { return MaterialApp( home: MyHomePage(title: ‘My First Flutter'), ); } } class MyHomePage extends StatefulWidget { MyHomePage({Key key, this.title}) : super(key: key); final String title; @override _MyHomePageState createState() =>_MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { int _counter = 0; void _incrementCounter() { setState(() { _counter++; }); } … Note: State (Manage Widget Status)  
  14. 1. User Interface 2. IDE & Tools 3. Coding 4.

    Productivity Tips for Speed Up
  15. Text Column Dropdown Button Text Field Raised Button Dropdown Button

    Text Field Scaffold AppBar Body
 (Container) Top-Down Approach  
  16. Building UI   Dart Coding GUI Tool Mix-use Difficulty

    WorkLoad Customizability 3 Approaches
  17. Implementing with Dart   •Implicit Widget •No need AnimationController

    (using setState()) •Customization: Moderate
 •Transition Widget •Requires AnimationController •Customization: Middle •Explicit Widget •Requires AnimationController •Customization: High Implicit Widget Transition Widget
  18. Code Sample (Implicit Widget)   body: Center( child: AnimatedOpacity(

    opacity: _visible ? 1.0 : 0.0, duration: Duration(milliseconds: 2000), child: Image.asset('images/chara.png')), ), floatingActionButton: FloatingActionButton( onPressed: () { setState(() { _visible = !_visible; }); }, tooltip: ‘Switch Opacity', child: Icon(Icons.flip), ),
  19. Flare   Adding Flare package into Flutter Project dependencies:

    flutter: sdk: flutter # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^0.1.2 ## Flare flare_flutter: pubspec.yaml
  20. Flare   Importing Flare data (*.flr) and Coding return

    Scaffold( appBar: AppBar( title: Text(widget.title), ), body: Center( child: FlareActor( "assets/sample.flr", animation: "sample01", fit: BoxFit.contain, )), ); } main.dart
  21. Stateless Widget   class MainPage extends StatelessWidget { @override

    Widget build(BuildContext context) { return Container(); } }
  22. Stateful Widget   class SubPage extends StatefulWidget { @override

    _SubPageState createState() => _SubPageState(); } class _SubPageState extends State<SubPage> { @override Widget build(BuildContext context) { return Container(); } }
  23. Animation   class AnimPage extends StatefulWidget { @override _AnimPageState

    createState() => _AnimPageState(); } class _AnimPageState extends State<AnimPage> with SingleTickerProviderStateMixin { AnimationController _controller; @override void initState() { _controller = AnimationController(vsync: this); super.initState(); } @override void dispose() { _controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Container(); } }
  24. Sample Code using Packages import 'package:shared_preferences/shared_preferences.dart'; _saveSampleData(String value) async {


    SharedPreferences prefs = await SharedPreferences.getInstance();
 await prefs.setString('key1', value);
 } (3)  
  25. Recommended Packages •http •HTTP Client •Easy to implement REST
 •firebase

    •lol Firebase!!! •Easy to add Firebase features •share •Contents share (Similar to Android/iOS) •e.g. Share to SNS  
  26. Flutter 1.5 Overview   •Bug fixed (in Flutter 1.2)

    •Material & Cupertino Widget Sets •In-App Purchases Supports •Dart 2.3 •Flutter for Web
  27. Flutter 1.5 Overview •Bug fixed (in Flutter 1.2) •Material &

    Cupertino Widget Sets •In-App Purchases Supports •Dart 2.3 •Flutter for Web  
  28. Steps for “Hello Flutter for Web” 1. Upgrading Flutter
 $

    flutter upgrade 2. Cloning “Flutter for Web”
 $ git clone https://github.com/flutter/flutter_web.git 3. Moving to “Hello World (Flutter for Web)”
 $ cd examples/hello_world/ 4. Adding some tools (webdev/dart) to PATH
 $ export PATH=“$PATH”:<MY_FLUTTER_PATH>/.pub_cache/bin
 $ export PATH=“$PATH":<MY_FLUTTER_PATH>/bin/cache/dart-sdk/bin 5. Updating our project
 $ pub get 6. RUN!!!
 $ webdev serve  
  29. AndroidX support for new apps [How to Create a Flutter

    Project includes AndroidX (Default: Disable)] $ flutter create --androidx myapp  
  30. How to migrate a Flutter app to AndroidX [Use Android

    Studio to migrate your app] 1. Import your Flutter app into Android Studio 2. On Android Studio, Refactor > Migrate to AndroidX Recommended [Manually migrate your app] ref. https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility Not Recommended  
  31. [- Flutter 1.5] Supporting 64-bit app [Creating both 32-bit and

    64-bit apps (2 .apk)] $ flutter build apk --release —target-platform=android-arm $ flutter build apk --release —target-platform=android-arm64 [Uploading 2 .apk] 2 apks -> Google Play Store  
  32. [Flutter 1.7 - ] Supporting 64-bit app [Creating Android app

    bundle (1 .aab)] $ flutter build appbundle [Uploading 1 .aab] 1 aab -> Google Play Store  
  33. Please let me know if you have any requests 


    such as technical speeches, technical writings and so on. Facebook:http://fb.com/kanbara.kenichi Twitter:@korodroid LinkedIn:http://www.linkedin.com/in/korodroid Thank you so much