第001例-Helloworld-(学习Flutter第1天)

在这里插入图片描述

1. 创建项目

使用命令创建项目

flutter create example001_helloworld

(AndroidStudio中创建,我这老是卡住)

  example001_hellworld/android/app/src/debug/AndroidManifest.xml (created)
  example001_hellworld/android/gradle/wrapper/gradle-wrapper.properties
  (created)
  example001_hellworld/android/gradle.properties (created)
  example001_hellworld/android/.gitignore (created)
  example001_hellworld/android/settings.gradle (created)
  example001_hellworld/android/app/build.gradle (created)
  example001_hellworld/android/app/src/main/kotlin/com/example/example001_hellwo
  rld/MainActivity.kt (created)
  example001_hellworld/android/build.gradle (created)
  example001_hellworld/android/example001_hellworld_android.iml (created)
  example001_hellworld/pubspec.yaml (created)
  example001_hellworld/README.md (created)
  example001_hellworld/ios/Runner/Runner-Bridging-Header.h (created)
  example001_hellworld/ios/Runner/AppDelegate.swift (created)
  example001_hellworld/ios/Runner.xcodeproj/project.pbxproj (created)
  example001_hellworld/lib/main.dart (created)
  example001_hellworld/.idea/runConfigurations/main_dart.xml (created)
  example001_hellworld/.idea/libraries/Dart_SDK.xml (created)
  example001_hellworld/.idea/libraries/KotlinJavaRuntime.xml (created)
  example001_hellworld/.idea/modules.xml (created)
  example001_hellworld/.idea/workspace.xml (created)
Running "flutter pub get" in example001_hellworld...             1,608ms
Wrote 78 files.

All done!
In order to run your application, type:

  $ cd example001_hellworld
  $ flutter run

To enable null safety, type:

  $ cd example001_hellworld
  $ dart migrate --apply-changes

Your application code is in example001_hellworld/lib/main.dart.

qiang@qiangdeMBP flutter % 

2. AS打开项目

在这里插入图片描述

3. 修改lib/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: ‘Hello world!’,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home:Center(child: Text(“Hello world!”),)
);
}
}

# 4. 调试运行
AS中先打开Android或者iOS模拟器,点运行按钮。
或在命令行中运行:

flutter run

显示
>qiang@qiangdeMBP example001_hellworld % flutter run           
Multiple devices found:
Android SDK built for x86 (mobile) • emulator-5554                        • android-x86    • Android 8.0.0 (API 26) (emulator)
iPhone 12 Pro Max (mobile)         • B69DF485-9910-4808-82C2-A45A01A5E38B • ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-4 (simulator)
Chrome (web)                       • chrome                               • web-javascript • Google Chrome 89.0.4389.90
[1]: Android SDK built for x86 (emulator-5554)
[2]: iPhone 12 Pro Max (B69DF485-9910-4808-82C2-A45A01A5E38B)
[3]: Chrome (chrome)
Please choose one (To quit, press "q/Q"): 

然后输入数字选择平台测试

# 打包web

flutter build web


# 演示:
[演示](http://203.176.95.161/example001/#/)


# 问题
1. 卡在"Installing build/app/outputs/flutter-apk/app.apk..."
android模拟器调试时出现,网上有些解决方法,我试了没啥用。
之前测试前一个demo没问题,当前卡在这。关了重开as和模拟器都不行。
当前我是在iOS模拟器里测试的。

猜你喜欢

转载自blog.csdn.net/qiang2080/article/details/115083844
今日推荐