
原文
https://medium.com/flutterdevs/flutter-app-for-desktop-d949f4d20cdb
代碼
https://github.com/flutter-devs/flutter_app_for_desktop
參考
正文
了解如何設(shè)置運行桌面上的應(yīng)用程序在您的 Flutter 應(yīng)用程序

在 Flutter 中,F(xiàn)lutter 應(yīng)用程序屏幕上的每個組件都是一個小工具。屏幕的透視圖完全依賴于用于構(gòu)建應(yīng)用程序的小部件的選擇和分組。此外,應(yīng)用程序代碼的結(jié)構(gòu)是一個小部件樹。
在這個博客中,我們將了解如何在桌面上運行 Flutter 應(yīng)用程序,以及設(shè)置這個應(yīng)用程序的要求是什么?.我們將看到一步一步的流程,并創(chuàng)建一個應(yīng)用程序來理解桌面應(yīng)用程序的構(gòu)建過程。
Flutter :
“ Flutter 是谷歌的 UI 工具包,它可以幫助你在創(chuàng)紀錄的時間內(nèi)用一個代碼庫為移動設(shè)備、網(wǎng)絡(luò)和桌面構(gòu)建漂亮的本地組合應(yīng)用程序?!?/p>
它是免費和開源的。它最初是由谷歌發(fā)展而來,目前由 ECMA 標準監(jiān)管。 Flutter 應(yīng)用程序利用 Dart 編程語言來制作應(yīng)用程序。這個 dart 編程和其他編程語言有一些相同的亮點,比如 Kotlin 和 Swift,并且可以被轉(zhuǎn)換成 JavaScript 代碼。
Flutter 的好處:
Flutter 為我們提供了在多個平臺上運行應(yīng)用程序的機會。比如,網(wǎng)絡(luò),桌面,Android/iOS。市場上有許多語言可以在多種平臺上運行應(yīng)用程序。但與其他語言相比,flutter 在不同平臺上運行應(yīng)用程序所需的時間更少。因為 flutter 不像其他語言那樣使用 mediator 橋來運行應(yīng)用程序。因此,在不同的平臺上運行應(yīng)用程序時, Flutter 速度很快。下面是一些關(guān)鍵點
所有平臺中相同的用戶界面和業(yè)務(wù)邏輯。
減少代碼和開發(fā)時間。
類似于本地應(yīng)用程序的性能。
自定義,動畫 UI 可用于任何復(fù)雜的小部件。
自己的渲染圖形引擎,即 skia。
簡單的平臺專用邏輯實現(xiàn)。
超越手機的潛在能力。
Flutter 平臺特定的標準:
特定于 Android 平臺
特定于 iOS 平臺
特定于 Web 平臺
桌面平臺專用
為桌面平臺上運行的應(yīng)用程序設(shè)置特定:
首先,創(chuàng)建您的 Flutter 項目
然后將你的頻道切換到貝塔 Flutter 頻道。因為它涵蓋了桌面支持,在 Beta 版本中可以使用,并且在 Beta 頭條大新聞中可以使用這個命令。
> flutter channel beta Flutter
轉(zhuǎn)到 flutter 文檔,點擊窗口設(shè)置選項,閱讀文檔。
https://flutter.dev/docs/get-started/install/windows#windows-setup
- 然后使用這個命令啟用你的窗口。
> flutter config — enable-windows-desktop
查看下面的文檔
https://flutter.dev/docs/get-started/install/windows#windows-setup
啟用窗口后 重新啟動 android studio 。
重新啟動 android studio 之后,現(xiàn)在使用下面的命令創(chuàng)建 windows 支持目錄。
> flutter create.
- 現(xiàn)在安裝 visual studio 去這個鏈接。
https://visualstudio.microsoft.com/downloads/
- 在 visual studio 安裝后,你終于可以在桌面上運行你的應(yīng)用了。選擇桌面設(shè)備在你的
android studio和運行應(yīng)用程序。
實施方案:
現(xiàn)在我正在設(shè)計一個在桌面上測試的頁面。你可以在桌面上運行任何應(yīng)用程序。我在這里展示的只是這個應(yīng)用程序的最后一個頁面代碼實現(xiàn),它是代碼片段。如果你想查看完整的代碼,請訪問下面給出的 Github 鏈接。
在這個網(wǎng)頁上,我正在設(shè)計一個課程列表卡與圖像和文字為購買課程列表。
import 'package:e_learning_app/constants/constants.dart';
import 'package:e_learning_app/model/Courses_items_model.dart';
import 'package:e_learning_app/model/read_blog_model.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'dart:io' show Platform;
class ReadScreenView extends StatefulWidget {
const ReadScreenView({Key? key}) : super(key: key);
@override
_ReadScreenViewState createState() => _ReadScreenViewState();
}
class _ReadScreenViewState extends State<ReadScreenView> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: _buildBody(),
);
}
Widget _buildBody() {
return Container(
height: MediaQuery._of_(context).size.height,
child: Stack(
children: [
Container(
height: MediaQuery._of_(context).size.height,
_//color: Colors.cyan,_ child: Container(
margin: EdgeInsets.only(bottom: 350),
height: 250,
decoration: BoxDecoration(
color: Color(0xffff9b57),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(40),
bottomRight: Radius.circular(40))),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: EdgeInsets.only(
left: 20,
right: 20,
top: 30),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
InkWell(
onTap:(){
Navigator._pop_(context);
},
child: Container(
_//margin: EdgeInsets.only(right: 25,top: 10),_ height: 30,
width: 30,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: Color(0xfff3ac7c),
),
child: Icon(
Icons._arrow_back_,
color: Colors._white_,
size: 20,
),
),
),
Container(
_// margin: EdgeInsets.only(right: 25,top: 10),_ height: 30,
width: 30,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: Color(0xfff3ac7c),
),
child: Icon(
Icons._menu_,
color: Colors._white_,
size: 20,
),
),
])),
Container(
padding: EdgeInsets.only(left: 20, right: 20, top: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
child: Text(
"Purchase Courses",
style: TextStyle(
color: Colors._white_,
fontSize: 20,
_//fontWeight: FontWeight.bold_ ),
),
),
SizedBox(
height: 5,
),
Container(
child: Text(
"Categories",
style: TextStyle(
color: Colors._white_,
fontSize: 12,
_//fontWeight: FontWeight.bold_ ),
),
),
],
),
),
Container(
padding: EdgeInsets.only(left: 20, top: 16),
height: 140,
alignment: Alignment._center_,
_//color: Colors.orange,_ child: ListView.builder(
scrollDirection: Axis.horizontal,
shrinkWrap: true,
itemCount: readBlogList.length,
itemBuilder: (BuildContext context, int index) {
return _buildCategorySection(readBlogList[index]);
}),
),
],
),
),
),
Positioned(
top: 260,
left: 0,
right: 0,
bottom: 0,
child: SizedBox(
height: MediaQuery._of_(context).size.height - 260,
width: MediaQuery._of_(context).size.width,
child: Container(
_//color: Colors.yellow,_ padding: EdgeInsets.only(left: 4, right: 4),
width: MediaQuery._of_(context).size.width,
child: ListView.builder(
_//physics: NeverScrollableScrollPhysics(),_ scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: readBlogList.length,
itemBuilder: (BuildContext context, int index) {
return _buildPurchaseCourses(readBlogList[index]);
}),
),
),
),
Positioned(
bottom: 0,
child: Container(
padding:
EdgeInsets.only(left: 20, right: 20, top: 10, bottom: 10),
height: 70,
width: MediaQuery._of_(context).size.width,
color: Colors._white_,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Purchase Courses",
style: TextStyle(
color: Colors._black_,
fontSize: 14,
_//fontWeight: FontWeight.bold_ ),
),
Text(
"5",
style: TextStyle(
color: Colors._red_,
fontSize: 20,
_//fontWeight: FontWeight.bold_ ),
),
],
),
Container(
height: 40,
width: 130,
margin: EdgeInsets.only(bottom: 10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Color(0xffdc4651)),
child: Container(
padding: EdgeInsets.only(left: 20, right: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Category",
style: TextStyle(color: Colors._white_),
),
Icon(Icons._arrow_drop_down_, color: Colors._white_)
],
),
),
)
],
),
),
),
],
),
);
}
Widget _buildCategorySection(ReadBlogModel readBlogList) {
return Container(
height: 50,
width: 110,
child: Card(
color: Colors._white_,
child: Column(
_//mainAxisAlignment: MainAxisAlignment.spaceBetween,_ children: [
Container(
height: 90,
child: ClipRRect(
borderRadius: BorderRadius.only(topLeft: Radius.circular(5),topRight: Radius.circular(5)),
child: Image.network(
readBlogList.image!,
fit: BoxFit.fill,
height: 50,
width: 110,
),
)),
Container(
padding: EdgeInsets.all(5),
child: Text(
"Categories",
style: TextStyle(
color: Colors._black_,
fontSize: 12,
_//fontWeight: FontWeight.bold_ ),
),
),
],
),
),
);
}
Widget _buildPurchaseCourses(ReadBlogModel readBlogList) {
return Container(
margin: EdgeInsets.only(left: 10, right: 10),
_//padding: EdgeInsets.only(left: 10,right: 20),_ height: 80,
child: Card(
child: Container(
padding: EdgeInsets.only(left: 10, right: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
height: 40,
width: 40,
child: ClipRRect(
child: Image.network(
readBlogList.image!,
fit: BoxFit.fill,
),
borderRadius: BorderRadius.circular(8),
),
),
_//SizedBox(width: 20,),_ Container(
padding: EdgeInsets.only(right: 120),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
readBlogList.title!,
style: TextStyle(
fontSize: 12,
_//fontWeight: FontWeight.bold_ ),
),
Text(
readBlogList.subTitle!,
style: TextStyle(
fontSize: 12,
_//fontWeight: FontWeight.bold_ ),
),
],
),
),
_// SizedBox(width: 130,),_ Container(
height: 30,
width: 30,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Color(0xfffee8db),
),
child: Icon(
Icons._done_,
color: Color(0xffdd8e8d),
size: 16,
),
)
],
),
),
));
}
}
當(dāng)我們運行應(yīng)用程序,我們應(yīng)該得到屏幕的輸出像下面的屏幕視頻。

結(jié)語:
在本文中,我已經(jīng)簡單地解釋了桌面應(yīng)用程序的設(shè)置。
GitHub Link:
https://github.com/flutter-devs/flutter_app_for_desktop
? 貓哥
微信群 ducafecat
往期
開源
GetX Quick Start
https://github.com/ducafecat/getx_quick_start
新聞客戶端
https://github.com/ducafecat/flutter_learn_news
strapi 手冊譯文
微信討論群 ducafecat
系列集合
譯文
https://ducafecat.tech/categories/%E8%AF%91%E6%96%87/
開源項目
https://ducafecat.tech/categories/%E5%BC%80%E6%BA%90/
Dart 編程語言基礎(chǔ)
https://space.bilibili.com/404904528/channel/detail?cid=111585
Flutter 零基礎(chǔ)入門
https://space.bilibili.com/404904528/channel/detail?cid=123470
Flutter 實戰(zhàn)從零開始 新聞客戶端
https://space.bilibili.com/404904528/channel/detail?cid=106755
Flutter 組件開發(fā)
https://space.bilibili.com/404904528/channel/detail?cid=144262
Flutter Bloc
https://space.bilibili.com/404904528/channel/detail?cid=177519
Flutter Getx4
https://space.bilibili.com/404904528/channel/detail?cid=177514
Docker Yapi
https://space.bilibili.com/404904528/channel/detail?cid=130578