`

flutter main.dart原始文件

 
阅读更多
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or press Run > Flutter Hot Reload in a Flutter IDE). Notice that the
        // counter didn't reset back to zero; the application is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  // 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;

  @override
  _MyHomePageState 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++;
    });
  }

  @override
  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(
        // 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.
          //
          // Invoke "debug painting" (press "p" in the console, choose the
          // "Toggle Debug Paint" action from the Flutter Inspector in Android
          // Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
          // to see the wireframe for each widget.
          //
          // 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).
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

 

分享到:
评论

相关推荐

    twitter.dart:Dart中的Twitter API库

    它的语法简洁明了,易于学习,并且具有强大的工具链,如Dart SDK和Flutter框架。 2. **Twitter API**:Twitter API是一组允许开发者通过HTTP请求访问Twitter服务的接口,包括获取用户信息、发布和检索推文、管理...

    Flutter全套面试题含解析.docx

    Dart是一种高效的、可移植的、易学的编程语言,特别适合构建跨平台的应用程序,如Flutter框架。其主要特性包括: 1. **Productive(生产力高)**:Dart语法简洁明了,拥有强大的工具链,如Dart SDK和IntelliJ IDEA...

    KLOTZEN:KLOTZEN App和WebApp

    应用程序的主要入口点是main.dart ,然后是app/app.dart 。 建立Android APK和appbundle flutter build appbundle flutter build apk 该应用可能在您的Android设备上,但未完全安装。 要完全删除它,请将设备连接到...

    flutter_starter

    GetX Flutter Firebase身份验证示例 更新:版本2.0.0更改为新的语言选项,并添加了null安全性。 GetX是Flutter的一个相对较新的软件包,它提供了使Flutter开发更简单的... 这是我的main.dart原始代码与GetX的代码。

    Dart语言中文教程1

    - `main()` 函数是 Dart 应用的入口点,每个 Dart 程序都需要有一个 `main()` 函数。 4. **运算符**: - Dart 支持算术、比较、逻辑、位和移位运算符,如 `+`、`-`、`*`、`==`、`&&`、`|` 等。 - 还有类型检查...

    Flutter实战1

    - 编译错误:更新Dart和Flutter到最新版本。 #### 四、Dart语言简介 1. **Dart语言特点**: - Dart是一种面向对象的编程语言,支持函数式编程特性。 - Dart语言简洁、易于学习,同时具备静态类型检查能力。 - ...

    React:原始ChainReaction的重制(https:github.comgabybarskyChainReaction1)

    连锁React原始ChainReaction的重制( ) 用Flutter的力量制成!入门该项目是Flutter应用程序的起点。... 结合使用XCode Simulator和iPhone 11 Max Pro进行测试要在终端中执行运行, flutter run lib/main_rev2.dart

    flutter_instd:第一个颤振应用

    在Flutter项目中,我们通常会有一个`main.dart`文件作为入口点,这也是“flutter_instd-main”压缩包中的主要文件。这个文件会包含`main()`函数,它是程序的起点。在这里,我们会初始化Flutter应用,并定义路由和...

    dustr:Dart-锈-颤振兼容性

    杜斯特使用dustr ,您可以将此锈代码称为: #[derive(FFIShim)]...} dustr是一种二进制文件,用于分析rust代码以生成其dart绑定。 必须使用库中的过程宏来标记rust代码。 这些程序宏围绕原始数据结构/功能生成与FFI兼容

    ui_practice:从sigma和实践中获取设计

    2. Dart源代码:如果是使用Flutter进行开发,会包含`.dart`文件,这些代码将实现UI设计的功能。 3. 资源文件:如图像、图标、字体等,用于构建UI。 4. README或README.md:通常包含项目介绍、安装指南、使用方法等...

    coin_application

    在Dart中,通常会有一个名为`main.dart`的文件,这里应该是整个应用的起点,它定义了程序运行时的第一行代码。用户通过命令行运行这个脚本,从而启动应用。这个目录下的代码通常是直接与用户交互的部分,负责处理...

    speed_of_img_endec:图像编码和图像解码的速度

    Dart提供了dart:io库,虽然原生不包含图像处理功能,但可以通过引入第三方库,如image或flutter_image_compress,实现图像编码。这些库通常会封装C/C++的图像处理库,如libjpeg或libpng,以利用其高性能。 解码则是...

Global site tag (gtag.js) - Google Analytics