Example 006-toast pop-up message-(learning Flutter day 2)

Test address: (Webpage is slower)
Webpage demo

Reference original text: https://blog.csdn.net/w329300817/article/details/114573716

1. Create a project

flutter create example006_toast

2. AS opens

3. Modify mart.dart

Add dependency


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. Debugging and running

Open the Android or iOS simulator in AS first, and click the run button.
Or run in the command line:

flutter run

6. Package the web

flutter build web

Guess you like

Origin blog.csdn.net/qiang2080/article/details/115112015