Flutter基本UI组件StatefulWidget与StatelessWidget(下)

Flutter里StatefulWidge组件的含义为 有状态的组件类,StatelessWidget为无状态的组件,这篇只说StatelessWidget

效果图

Flutter基本UI组件StatefulWidget与StatelessWidget(下)_第1张图片

图示中 就是一个简单的弹窗和一个点击后的吐司以及背景的渐变,没有做过多的介绍,因为StatelessWidget比较StatefulWidget 还是相对容易些

贴一下代码

吐司用的是一个依赖库 fluttertoast: ^4.0.1 需要看效果的可以添加一下这个依赖库


import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:fluttertoast/fluttertoast.dart';



class StateLessLearn extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter stateless学习',
      theme: ThemeData(

        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(title: Text('Flutter stateless学习'),),


        body: Container(
          decoration: BoxDecoration(
            color: Colors.blueGrey,
            gradient: LinearGradient(
              colors: [Colors.blueGrey,Colors.black]
            )
          ),
          /**
           * 内容
           */
          child: Column(
          verticalDirection: VerticalDirection.down,
            children: [

              AlertDialog(
                title: Text("弹窗"),
                backgroundColor: Colors.amber,
                content: Text("这是我的第一个弹窗"),
                actions: [
                  FlatButton(
                      onPressed: () {

                      },
                      child: Text('确定')),
                  FlatButton(
                      onPressed: () {
                       Fluttertoast.showToast(
                           msg: "我来了flutter",
                         gravity: ToastGravity.CENTER,
                         toastLength: Toast.LENGTH_LONG,
                       );
                      },
                      child: Text('取消')),

                ],
              )
            ],
          ),
        ),
      ),
    );
  }
}




你可能感兴趣的:(android,android,studio,flutter)