其他分享
首页 > 其他分享> > flutter组件常用总结

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 //字体颜色
            ),
      ),
    );
  }
}

 

标签:总结,Widget,context,BuildContext,StatelessWidget,build,MyApp,组件,flutter
来源: https://www.cnblogs.com/angelyan/p/14147119.html