第006例-toast弹出消息-(学习Flutter第2天)

测试地址:(网页比较慢)
网页演示

参考原文:https://blog.csdn.net/w329300817/article/details/114573716

1. 创建项目

flutter create example006_toast

2. AS打开

3. 修改mart.dart

添加依赖


dependencies:
  flutter:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  fluttertoast: ^4.0.1
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

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

class MyApp extends StatelessWidget {
    
    
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    
    
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(title: Text("Test Toast"),),
        body:
            Center(
              child:
                Column(
                  children: [
                    new FadeInImage.assetNetwork(
                      placeholder: 'images/logo.png',
                      image: 'https://img-home.csdnimg.cn/images/20200629060519.png',
                      fit: BoxFit.fill,
                    ),
                    RaisedButton(
                      child: Text("弹出"),
                      onPressed:(){
    
    
                        Fluttertoast.showToast(
                            msg: "点击了按钮",
                            gravity: ToastGravity.BOTTOM,
                            timeInSecForIosWeb: 1,
                            backgroundColor: Colors.black45,
                            textColor: Colors.white,
                            fontSize: 16.0);
                      },
                    ),
                  ],
                )
            ),

        ),
    );
  }
}

5. 调试运行

AS中先打开Android或者iOS模拟器,点运行按钮。
或在命令行中运行:

flutter run

6. 打包web

flutter build web

猜你喜欢

转载自blog.csdn.net/qiang2080/article/details/115112015
今日推荐