在Flutter工程基礎(chǔ)上怎么集成及運(yùn)行小程序-創(chuàng)新互聯(lián)

這篇文章主要講解了“在Flutter工程基礎(chǔ)上怎么集成及運(yùn)行小程序”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“在Flutter工程基礎(chǔ)上怎么集成及運(yùn)行小程序”吧!

在張掖等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站制作、成都網(wǎng)站制作 網(wǎng)站設(shè)計(jì)制作按需定制制作,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站設(shè)計(jì),成都全網(wǎng)營(yíng)銷推廣,外貿(mào)網(wǎng)站制作,張掖網(wǎng)站建設(shè)費(fèi)用合理。

新建 Flutter 樣例工程

Flutter 的安裝

本文將使用 Flutter1.12.hotfix8 穩(wěn)定版作為開發(fā)環(huán)境。

  • 下載 FlutterSDK

  • 配置 PATH 環(huán)境路徑

  • flutter doctor 檢查環(huán)境

新建 Flutter 工程

flutter create --template=app --org=com.finogeeks.flutter --project-name=mini_flutter -i objc -a java ./mini_flutte

執(zhí)行以上命令后,正常將會(huì)提示以下信息

All done![?] Flutter: is fully installed. (Channel stable, v1.12.13+hotfix.8, on Mac OS X 10.15.3 19D76, locale zh-Hans-CN)[?] Android toolchain - develop for Android devices: is fully installed. (Android SDK version 29.0.3)[?] Xcode - develop for iOS and macOS: is fully installed. (Xcode 11.3.1)[?] Android Studio: is fully installed. (version 3.6)[!] IntelliJ IDEA Ultimate Edition: is partially installed; more components are available. (version 2019.3.3)[?] VS Code: is fully installed. (version 1.42.1)[!] Proxy Configuration: is partially installed; more components are available.[?] Connected device: is fully installed. (1 available)Run "flutter doctor" for information about installing additional components.In order to run your application, type:
  $ cd mini_flutte
  $ flutter run
Your application code is in mini_flutter/lib/main.dart.

注意!flutter 需要依賴本地安裝對(duì)應(yīng)的 iOS,Android 開發(fā)工具,即需要安裝 Xcode 和 AndroidStudio。具體安裝使用方法這里不贅述。

這里我們用 VSCode+Xcode 作為開發(fā)組合環(huán)境,如果要正常調(diào)試需要確保以下三個(gè)檢查項(xiàng)目是正常的。

[?] Xcode - develop for iOS and macOS: is fully installed. (Xcode 11.3.1)

Flutter: is fully installed. (Channel stable, v1.12.13+hotfix.8, on Mac OS X 10.15.3 19D76, locale zh-Hans-CN)

VS Code: is fully installed. (version 1.42.1)

[!] Proxy Configuration: is partially installed; more components are available.

集成小程序解析引擎

這里我們采用凡泰免費(fèi)社區(qū)版的小程序解析引擎,只需要 10 行代碼量不到即可完成小程序集成。

  1. 引入小程序引擎插件。在 pubspec.yaml 文件中引入小程序 Flutter 插件

mop: ^0.2.0

2.在 main.dart 文件中增加以下小程序引擎初始化方法。Mop.instance.initialize這里需要用到 sdkkey 和 secret??梢灾苯釉?https://mp.finogeeks.com免費(fèi)注冊(cè)獲取。注冊(cè)使用方法可以參考 接入指引

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> init() async {
    if (Platform.isIOS) {
      final res = await Mop.instance.initialize(
          '22LyZEib0gLTQdU3MUauAYEY1h9s9YXzmGuSgQrin7UA', '9e05fa0015d7dbfa',
          apiServer: 'https://mp.finogeeks.com', apiPrefix: '/api/v1/mop');
      print(res);
    } else if (Platform.isAndroid) {
      final res = await Mop.instance.initialize(
          '22LyZEib0gLTQdU3MUauAYEY1h9s9YXzmGuSgQrin7UA', '9e05fa0015d7dbfa',
          apiServer: 'https://mp.finogeeks.com', apiPrefix: '/api/v1/mop');
      print(res);
    }
    if (!mounted) return;
  }

3、在主界面上增加三個(gè)按鈕來(lái)打開小程序

  Center(
    child: Container(
      padding: EdgeInsets.only(
        top: 20,
      ),
      child: Column(
        children: <Widget>[
          Container(
            width: 140,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.all(Radius.circular(5)),
              gradient: LinearGradient(
                colors: const [Color(0xFF12767e), Color(0xFF0dabb8)],
                stops: const [0.0, 1.0],
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter,
              ),
            ),
            child: FlatButton(
              onPressed: () {
                Mop.instance.openApplet('5e3c147a188211000141e9b1',
                    path: 'pages/index/index', query: '');
              },
              child: Text(
                '打開畫圖小程序',
                style: TextStyle(color: Colors.white),
              ),
            ),
          ),
          SizedBox(height: 30),
          Container(
            width: 140,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.all(Radius.circular(5)),
              gradient: LinearGradient(
                colors: const [Color(0xFF12767e), Color(0xFF0dabb8)],
                stops: const [0.0, 1.0],
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter,
              ),
            ),
            child: FlatButton(
              onPressed: () {
                Mop.instance.openApplet('5e4d123647edd60001055df1');
              },
              child: Text(
                '打開官方小程序',
                style: TextStyle(color: Colors.white),
              ),
            ),
          ),
          SizedBox(height: 30),
          Container(
            width: 140,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.all(Radius.circular(5)),
              gradient: LinearGradient(
                colors: const [Color(0xFF12767e), Color(0xFF0dabb8)],
                stops: const [0.0, 1.0],
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter,
              ),
            ),
            child: FlatButton(
              onPressed: () {
                Mop.instance.openApplet('5e637a18cbfae4000170fa7a');
              },
              child: Text(
                '我的對(duì)賬單',
                style: TextStyle(color: Colors.white),
              ),
            ),
          ),
        ],
      ),
    ),
  )

4、運(yùn)行 Flutter 程序

  • 在代碼根目錄執(zhí)行 flutter devices 查看本機(jī)安裝的模擬器。

  • 執(zhí)行 flutter run --debug 運(yùn)行示例,運(yùn)行效果之如本文最前面所展示的圖示。

感謝各位的閱讀,以上就是“在Flutter工程基礎(chǔ)上怎么集成及運(yùn)行小程序”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)在Flutter工程基礎(chǔ)上怎么集成及運(yùn)行小程序這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

分享標(biāo)題:在Flutter工程基礎(chǔ)上怎么集成及運(yùn)行小程序-創(chuàng)新互聯(lián)
標(biāo)題路徑:http://www.muchs.cn/article8/dhceip.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計(jì)動(dòng)態(tài)網(wǎng)站、企業(yè)網(wǎng)站制作、企業(yè)建站標(biāo)簽優(yōu)化、網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)