發表日期:2018-11 文章編輯:小燈 瀏覽次數:2513
https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps
第一個步:
新建一個標準的APP工程testFlutterInAPP,APP目錄下面通過命令創建flutter模塊工程
flutter create -t module my_flutter
image.png編譯flutter 代碼生成Android的AAR文件
$ cd .android/ $ ./gradlew flutter:assembleDebug
AAR 文件生成到.android/Flutter/build/outputs/aar/目錄下面
添加Host APP 依賴flutter module 模塊,在setting.gradle 文件中加入
include ':app' // assumed existing content setBinding(new Binding([gradle: this])) // new evaluate(new File(// new settingsDir.parentFile, // new 'my_flutter/.android/include_flutter.groovy'// new ))
app/build.gradle 增加對flutter 工程依賴
// testFlutterInAPP/app/build.gradledependencies { implementation project(':flutter') }
構建成功后,執行Android的run啟動應用 ,點擊打開flutter 。
Java 層代碼
openFlutter.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { View flutterView = Flutter.createView( MainActivity.this, getLifecycle(), "route1" ); FrameLayout.LayoutParams layout = new FrameLayout.LayoutParams(600, 800); layout.leftMargin = 100; layout.topMargin = 200; addContentView(flutterView, layout); } });
flutter 代碼
import 'dart:ui';import 'package:flutter/material.dart';void main() => runApp(_widgetForRoute(window.defaultRouteName)); Widget _widgetForRoute(String route) { switch (route) { case 'route1': return new MyApp(); case 'route2': return new MyApp(); default: return Center( child: Text('Unknownroute1 : $route', textDirection: TextDirection.ltr), ); } return new MyApp(); } class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) { return new MaterialApp( title: 'Flutter Demo', theme: new ThemeData( primarySwatch: Colors.blue, ), home: new MyHomePage(title: 'Flutter Demo 1111' 'Home Page'), ); } }class MyHomePage extends StatefulWidget { MyHomePage({Key key, this.title}) : super(key: key);final String title;@override _MyHomePageState createState() => new _MyHomePageState(); }class _MyHomePageState extends State<MyHomePage> { int _counter = 0;void _incrementCounter() { setState(() {_counter++; }); }@override Widget build(BuildContext context) { return new Scaffold( appBar: new AppBar(title: new Text(widget.title), ), body: new Center( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ new Text( 'You have pushed the button this many times:', ), new Text( '$_counter', style: Theme.of(context).textTheme.display1, ), ], ), ), floatingActionButton: new FloatingActionButton( onPressed: _incrementCounter, tooltip: 'Increment', child: new Icon(Icons.add), ), // This trailing comma makes auto-formatting nicer for build methods. ); } }
運行 flutter 工程 ,進入my_flutter 目錄執行flutter run 命令
image.png即可啟動flutter ,r == hot reload R == hot restart
q == quit d == detach,
或者啟動Android應用調試
image.png但是,好像DEBUG無效??
連接 https://zhuanlan.zhihu.com/p/40528502
日期:2018-10 瀏覽次數:7347
日期:2018-12 瀏覽次數:4414
日期:2018-07 瀏覽次數:4949
日期:2018-12 瀏覽次數:4248
日期:2018-09 瀏覽次數:5586
日期:2018-12 瀏覽次數:10002
日期:2018-11 瀏覽次數:4888
日期:2018-07 瀏覽次數:4654
日期:2018-05 瀏覽次數:4938
日期:2018-12 瀏覽次數:4392
日期:2018-10 瀏覽次數:5217
日期:2018-12 瀏覽次數:6290
日期:2018-11 瀏覽次數:4547
日期:2018-08 瀏覽次數:4668
日期:2018-11 瀏覽次數:12727
日期:2018-09 瀏覽次數:5653
日期:2018-12 瀏覽次數:4919
日期:2018-10 瀏覽次數:4261
日期:2018-11 瀏覽次數:4606
日期:2018-12 瀏覽次數:6142
日期:2018-06 瀏覽次數:4083
日期:2018-08 瀏覽次數:5525
日期:2018-10 瀏覽次數:4528
日期:2018-12 瀏覽次數:4614
日期:2018-07 瀏覽次數:4441
日期:2018-12 瀏覽次數:4585
日期:2018-06 瀏覽次數:4473
日期:2018-11 瀏覽次數:4450
日期:2018-12 瀏覽次數:4330
日期:2018-12 瀏覽次數:5353
Copyright ? 2013-2018 Tadeng NetWork Technology Co., LTD. All Rights Reserved.