Android Studio中配置Flutter插件,创建小项目“hello world”

这篇具有很好参考价值的文章主要介绍了Android Studio中配置Flutter插件,创建小项目“hello world”。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

一、下载Flutter SDK

打开官网https://flutter.io/setup-windows/下载Flutter sdk并解压到一目录
Android Studio中配置Flutter插件,创建小项目“hello world”,Flutter,android studio,flutter,配置,hello world
Android Studio中配置Flutter插件,创建小项目“hello world”,Flutter,android studio,flutter,配置,hello world
Android Studio中配置Flutter插件,创建小项目“hello world”,Flutter,android studio,flutter,配置,hello world

二、Android studio中安装Flutter插件

Android studio中安装Flutter插件,File - Settins - Plugins -查找到Flutter - install,在安装Flutter插件时会自动提示下载Dart插件,只要同意即可,重启as后再次查看会显示如图所示效果:
Android Studio中配置Flutter插件,创建小项目“hello world”,Flutter,android studio,flutter,配置,hello world
Android Studio中配置Flutter插件,创建小项目“hello world”,Flutter,android studio,flutter,配置,hello world

图中标红代表Dart插件安装完成
Android Studio中配置Flutter插件,创建小项目“hello world”,Flutter,android studio,flutter,配置,hello world
Android Studio中配置Flutter插件,创建小项目“hello world”,Flutter,android studio,flutter,配置,hello world

配置FlutterDart路径
Android Studio中打开设置,在Languages & Frameworks中可以看到多了FlutterDart两个选项,按照下图配置自己的 FlutterDart路径即可:

三、创建Flutter小项目

Android Studio中配置Flutter插件,创建小项目“hello world”,Flutter,android studio,flutter,配置,hello world
Android Studio中配置Flutter插件,创建小项目“hello world”,Flutter,android studio,flutter,配置,hello world
Android Studio中配置Flutter插件,创建小项目“hello world”,Flutter,android studio,flutter,配置,hello world

Android Studio中配置Flutter插件,创建小项目“hello world”,Flutter,android studio,flutter,配置,hello world

Android Studio中配置Flutter插件,创建小项目“hello world”,Flutter,android studio,flutter,配置,hello world
Android Studio中配置Flutter插件,创建小项目“hello world”,Flutter,android studio,flutter,配置,hello world
main.dart代码:

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // TRY THIS: Try running your application with "flutter run". You'll see
        // the application has a purple toolbar. Then, without quitting the app,
        // try changing the seedColor in the colorScheme below to Colors.green
        // and then invoke "hot reload" (save your changes or press the "hot
        // reload" button in a Flutter-supported IDE, or press "r" if you used
        // the command line to start the app).
        //
        // Notice that the counter didn't reset back to zero; the application
        // state is not lost during the reload. To reset the state, use hot
        // restart instead.
        //
        // This works for code too, not just values: Most code changes can be
        // tested with just a hot reload.
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      // This call to setState tells the Flutter framework that something has
      // changed in this State, which causes it to rerun the build method below
      // so that the display can reflect the updated values. If we changed
      // _counter without calling setState(), then the build method would not be
      // called again, and so nothing would appear to happen.
      _counter++;
    });
  }

  
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // TRY THIS: Try changing the color here to a specific color (to
        // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
        // change color while the other colors stay the same.
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: Column(
          // Column is also a layout widget. It takes a list of children and
          // arranges them vertically. By default, it sizes itself to fit its
          // children horizontally, and tries to be as tall as its parent.
          //
          // Column has various properties to control how it sizes itself and
          // how it positions its children. Here we use mainAxisAlignment to
          // center the children vertically; the main axis here is the vertical
          // axis because Columns are vertical (the cross axis would be
          // horizontal).
          //
          // TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
          // action in the IDE, or press "p" in the console), to see the
          // wireframe for each widget.
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

运行程序效果,如下图:

Android Studio中配置Flutter插件,创建小项目“hello world”,Flutter,android studio,flutter,配置,hello world

提供简化的代码:

import 'package:flutter/material.dart';

void main() {
  return runApp(const Root());
}

class Root extends StatelessWidget {
  const Root({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "daylight",
      home: Scaffold(
        appBar: AppBar(title: const Text("daylight")),
        body: const Center(
          child: Text("hello world"),
        ),
      ),
    );
  }
}

运行程序效果,如下图:文章来源地址https://www.toymoban.com/news/detail-758709.html

Android Studio中配置Flutter插件,创建小项目“hello world”,Flutter,android studio,flutter,配置,hello world

到了这里,关于Android Studio中配置Flutter插件,创建小项目“hello world”的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Android Studio 2022.1.1创建项目的Gradle配置

    今天使用Android Studio建了一个新项目,遇到了不少问题,网上也找了不少解决方案都无效(可能Studio版本、项目版本等都不一样,解决办法也不一样吧),最后问题解决,总结梳理以下几点: Android Studio版本:2022.1.1 Gradle版本:7.5 Android Gradle Plugin Version:7.4.2 JDK版本:Java 1

    2024年02月06日
    浏览(35)
  • Eclipse 创建 Hello World 工程

    Download and install the Eclipse IDE. Eclipse - double click - Launch 单击蓝色方框 (右上角) 最大化 IDE File - New - C Project - Finish Project name:工程名 Use default location:勾选此项,项目默认创建在 eclipse workspace 目录下。如果不勾选,那么在 Location 处可以选择项目位置。如果已经有了项目目录,

    2024年02月20日
    浏览(30)
  • Visual Studio 2022 CMake C++ Hello World

    C++自学精简教程 目录(必读) Visual Studio 2022 安装​​​​​​​ 什么是CMake CMake是跨平台的C/C++工程构建工具。 我们知道, 在Windows上用Visual Studio开发C/C++代码,工程文件是用.vcxproj文件来组织的; 在Linux上用gcc/g++开发C/C++代码,工程文件是用Makefile文件来组织的; 很多时候我

    2024年02月16日
    浏览(41)
  • 【小黑嵌入式系统第八课】初识PSoC Creator™开发——关于PSoC Creator&下载、创建项目、单片机中的hello world(点亮一个led)

    上一课: 【小黑嵌入式系统第七课】PSoC® 5LP 开发套件(CY8CKIT-050B )——PSoC® 5LP主芯片、I/O系统、GPIO控制LED流水灯的实现 下一课: 【小黑嵌入式系统第九课】PSoC 5LP第一个实验——LED、字符型LCD显示实验 本课程主要介绍了 PSoC® 5LP, 一个基于 ARM® Cortex®-M3 的可编程片上系

    2024年02月03日
    浏览(43)
  • 用Visual Studio编写C++程序,输出Hello World

    1.创建新项目 必须是空项目  2.保存路径 自己选择合适的地方。 3.创建文件 进来之后一片空白,虽然我们已经建立了项目,但是项目都是由一个或多个文件组成的(相当于文件夹),这个项目里面还没有文件,所以需要在项目中创建文件。 右键点击“源文件”,选择添加-新

    2024年02月06日
    浏览(31)
  • 【Flutter】使用Android Studio 创建第一个flutter应用。

    首先下载好 flutter sdk和 Android Studio。 FlutterSDK下载 Android Studio官网 我的是 windows。 查看flutter安装环境。 如果没有,自己在环境变量的path添加下flutter安装路径。 在将 Path 变量更新后,打开一个新的控制台窗口,然后执行下面的命令。如果它提示有任何的平台相关依赖,那么

    2024年02月10日
    浏览(53)
  • 创建第一个Servlet程序“hello world“(创建流程+页面出错情况)

    目录 🐲 1. 动态页面之Servlet 🐲 2. 写第一个Servlet的程序:\\\"hello world!\\\" 🦄 2.1 创建项目 🦄 2.2 引入Servlet依赖 🦄 2.3 创建目录结构 🦄 2.4 编写代码  🦄 2.5 打包程序 🦄 2.6 部署程序 🦄 2.7 验证程序 🐲3. 创建Servlet流程简化 🐲4. 工作原理流程分析 🐲5. 访问页面出错 HTTP服务器

    2023年04月11日
    浏览(33)
  • Python程序员Visual Studio Code指南2 Hello World

    Visual Studio Code的Python 扩展提供了对Python语言的支持,包括语法着色、代码补全、过滤、调试、代码导航和代码格式化等功能,以及Jupyter Notebook支持等Python特有的功能。您可以在Visual Studio Code的扩展视图中安装Python扩展。与从扩展市场安装的任何扩展一样,你可以在设置编辑

    2024年02月12日
    浏览(28)
  • 创建React Native的第一个hello world工程

    需要安装好node、npm环境 如果之前没有安装过 react-native-cli 脚手架的,可以按照下述步骤直接安装。如果已经安装过的,但是在使用这个脚手架初始化工程的时候遇到下述报错的话 也可以先直接卸载 正常安装过程: 安装 react-native-cli 安装 react-native 安装完成之后,可以用脚手

    2024年02月07日
    浏览(34)
  • Android中AIDL的简单使用(Hello world)

    AIDL:Android Interface Definition Language(Android接口定义语言) 作用:跨进程通讯。如A应用调用B应用提供的接口 A应用创建aidl接口,并且创建一个Service来实现这个接口(在onBind方法里面return我们这个接口的实例)。 把A应用创建的aidl文件原封不动的搬至B应用中(注意包名类名都

    2024年02月11日
    浏览(39)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包