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

 

相关文章

这篇文章主要讲解了“FlutterComponent动画的显和隐怎么实现...
这篇文章主要讲解了“flutter微信聊天输入框功能如何实现”,...
本篇内容介绍了“Flutter之Navigator的高级用法有哪些”的有...
这篇文章主要介绍“Flutter怎么使用Android原生播放器”,在...
Flutter开发的android端如何修改APP名称,logo,版本号,具体...
Flutter路由管理初识路由概念一.路由管理1.1.Route1.2.Mater...