`

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 simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
primarySwatch: Colors.blue,
        // This makes the visual density adapt to the platform that you run
        // the app on. For desktop platforms, the controls will be smaller and
        // closer together (more dense) than on mobile platforms.
visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      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.
);
  }
}
分享到:
评论

相关推荐

    Breakout示例 游戏(Flame/Box2D/Flutter)_Dart_代码_下载

    3. `main.dart`:应用程序的入口点,初始化Flutter应用和Flame游戏。 4. `game`目录:可能包含游戏的特定组件,如玩家控制、砖块、球的类。 5. `assets`目录:可能包含游戏的图像资源。 通过研究这个项目,开发者...

    flutter_crashlytics,:package:flutter插件用于crashlytics集成.zip

    为了初始化Firebase和Crashlytics,你需要在你的主入口文件(如`main.dart`)中添加以下代码: ```dart import 'package:firebase_core/firebase_core.dart'; import 'package:flutter_crashlytics/flutter_...

    Flutter上的App初始启用屏幕示例

    本篇文章将深入探讨如何在Flutter上实现App的初始启用屏幕。 首先,我们需要理解Flutter的基本概念。Flutter是由Google开发的一个开源跨平台移动应用开发框架,它使用Dart编程语言,并以其快速热重载、丰富的自定义...

    flutter mqtt

    1. `main.dart`文件:这是应用程序的入口点,包含初始化MQTT客户端、连接服务器、订阅和发布消息的逻辑。 2. `mqtt_service.dart`文件:封装了与MQTT相关的操作,如连接、断开、订阅和发布,方便其他页面调用。 3. `...

    Flutter 国际化demo

    然后,在`main.dart`文件中,你需要初始化`MaterialApp`或`CupertinoApp`,并指定使用的本地化。这通常在`runApp`方法中完成。以下是如何设置`LocalizationsDelegates`和`SupportedLocales`的示例: ```dart import...

    这是一个使用Flutter和SignalR的实时聊天示例。_Dart_C#_下载.zip

    1. `main.dart` 文件:这是Flutter应用的入口点,其中初始化了MaterialApp,并导航到聊天屏幕。 2. `chat_screen.dart`:这是聊天界面的实现,包含输入框、发送按钮和聊天消息列表。StatefulWidget用于管理状态,当...

    flutter_app.7z

    - `lib`: 存放源代码,包括`main.dart`入口文件和其他业务逻辑文件。 - `android`: Android平台相关的配置和源码。 - `ios`: iOS平台的相关配置和源码。 - `pubspec.yaml`: 项目配置文件,包含依赖管理、应用元数据...

    Flutter完整开发实战详解 PDF

    1. 介绍了如何创建Flutter项目,包括初始化、编写main.dart文件、布局设计等。 2. 遍及各种Widget的使用,如Container、Text、Image等,以及布局系统,如Row、Column、Stack等。 3. 讨论了状态管理和数据绑定,如...

    flutter_app.zip

    3. `main.dart`:这是应用程序的入口点,通常包含了初始化Flutter应用、设置MaterialApp或CupertinoApp(根据目标平台)以及其他应用级别的配置。 4. `widgets` 文件夹(如果存在):可能包含自定义的可重用组件。...

    Flutter材料组件代码实验室_Dart_C++_下载.zip

    2. **Flutter框架**:学习如何搭建Flutter项目,包括main.dart文件的结构、初始化应用、路由管理和状态管理。 3. **材料组件**:深入理解Material部件库,如AppBar、BottomNavigationBar、Card、Dialog、...

    track-map_flutter-dev.zip

    1. `lib` 目录:包含项目的源代码,尤其是 `main.dart` 文件,这是 Flutter 应用的入口点,会包含初始化地图和追踪逻辑的代码。 2. `pubspec.yaml`:项目配置文件,列出了所有依赖的 Flutter 插件和库,比如可能有 `...

    关于Flutter页面保持的最优解方案代码

    在`main.dart`中,通常会定义应用的主入口点以及`MaterialApp`或`CupertinoApp`,在这里可以设置自定义的路由管理策略。例如,你可以使用`onGenerateRoute`来处理页面间的导航,并在其中保留状态。你可以为每个路由...

    dart代码-dart学习

    本文将围绕“dart代码-dart学习”这个主题,深入讲解Dart语言的关键特性、语法以及如何通过`main.dart`和`README.txt`这两个文件进行学习。 Dart语言特点: 1. **静态类型**:Dart支持静态类型,可以提供编译时的...

    hello_world_Flutter_web_demo.zip

    在Flutter Web项目中,开发者需要借助`flutter create`命令初始化项目,然后在`main.dart`中编写应用的基本结构,如`MaterialApp`或`WidgetsApp`。通过`runApp`函数启动应用,并在`web`目录下生成适用于Web的编译...

    Flutter基础学习PDF

    你会学到如何创建新的Flutter项目,理解`main.dart`文件中的主要组件,如`StatefulWidget`和` StatelessWidget`,以及如何使用`build`方法构建用户界面。 4. **Flutter Widget框架**(06章节):Flutter的核心是...

    Flutter+getx+config示例

    然后,在`main.dart`文件中初始化配置: ```dart import 'package:flutter/material.dart'; import 'config.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); await initializeConfig();...

    first_flutter_demo

    - `lib/main.dart`:这是你的应用的入口文件,通常在这里定义`main()`函数,它是程序的起点。 - `pubspec.yaml`:配置文件,包含了项目的元数据和依赖项。 3. `main.dart`文件分析: - `MaterialApp`:这是...

    Flutter插件提供短信代码自动填充支持_Java_Dart_下载.zip

    在Flutter中,插件是用于与原生平台交互的桥梁,它由两部分组成:Dart代码(在Flutter环境中运行)和原生代码(分别在iOS的Objective-C或Swift,以及Android的Java或Kotlin中运行)。在本例中,我们需要一个Java编写...

    mvvm_flutter.zip

    2. `main.dart`:项目的入口文件,通常在这里设置Provider,初始化应用的顶级组件。 3. `pubspec.yaml`:项目的配置文件,列出依赖的库和版本。 4. `.gitignore`:定义了Git应忽略的文件或目录。 5. `README.md`:...

    flutterApp搭建底层.rar

    - `lib/`:这是你的源代码目录,包含`main.dart`文件,这是应用的入口点。 - `pubspec.yaml`:这里定义了项目的元数据,包括依赖项。 - `android/` 和 `ios/`:分别包含Android和iOS平台的特定配置和源代码。 - ...

Global site tag (gtag.js) - Google Analytics