flutter-02day-1 项目结构基本介绍

154 阅读1分钟

项目目录结构

.
├── first_shop
│   ├── analysis_options.yaml
│   ├── android
│   ├── build
│   ├── first_shop.iml
│   ├── ios
│   ├── lib
│   │   ├── main.dart # 入口文件
│   ├── pubspec.lock
│   ├── pubspec.yaml # 包管理
│   ├── README.md
│   ├── test
│   ├── web
│   └── windows

入口文件 main.dart

import 'package:flutter/material.dart';

void main(List<String> args) {
  runApp(const App());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'first app',
      theme: ThemeData(primaryColor: Colors.blue),
      home: const Home(),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.blue[50],
      child: const Text(
        'first',
        style: TextStyle(color: Colors.black),
      ),
    );
  }
}

依赖管理pubspec.yaml

  • flutter pub get 拉取依赖
  • flutter pub upgrade 升级
  • flutter pub add xxx 添加包
  • flutter pub remove xxx 移除包
name: first_shop
description: A new Flutter project.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
  sdk: ">=2.16.0 <3.0.0"  # dart sdk
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.2
  fluro: ^2.0.3
dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^1.0.0
flutter:
  uses-material-design: true
  assets:
    - images/a_dot_burr.jpeg
    - images/a_dot_ham.jpeg
  fonts:
    - family: Schyler
      fonts:
        - asset: fonts/Schyler-Regular.ttf
        - asset: fonts/Schyler-Italic.ttf
          style: italic
    - family: Trajan Pro
      fonts:
        - asset: fonts/TrajanPro.ttf
        - asset: fonts/TrajanPro_Bold.ttf
          weight: 700