flutter组件常用总结

一、 继承StatelessWidget组件

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //TODO:implementbuild
    return Center(
      child: Text(
        "My name is maple",
        textDirection: TextDirection.ltr,
      ),
    );
  }
}

二、Text组件

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //TODO:implementbuild
    return Center(
      child: Text(
        "My name is maple",
        textDirection: TextDirection.ltr,
        style: TextStyle(
            fontSize: 40.0, //字体大小
            fontWeight: FontWeight.bold, //字体粗细
            color: Colors.yellow //字体颜色
        ),
      ),
    );
  }
}

三、MaterialApp顶层组件

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  final routes = {
    '/': (BuildContext context) => new Home(),
  };

  @override
  Widget build(BuildContext context) {
    //TODO:implementbuild
    return MaterialApp(
        title: "标题",
        //主题
        theme:
            ThemeData(primarySwatch: Colors.red, brightness: Brightness.light),
        // 主页
        // home: Home(),
        // 路由
        routes: routes);
  }
}

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Center(
      child: Text(
        "My name is maple",
        textDirection: TextDirection.ltr,
        style: TextStyle(
            fontSize: 30.0, //字体大小
            fontWeight: FontWeight.bold, //字体粗细
            color: Colors.yellow //字体颜色
            ),
      ),
    );
  }
}

 

上一篇:Django创建


下一篇:python使用django创建项目详解