相关疑难解决方法(0)

如何在Flutter中正确显示Snackbar?

我试图显示一个Snackbar点击floatingActionbutton。但是,当我单击时,floatingactionbutton它什么也没有显示。这是我的代码。我正在使用StatefulWidget。我调试并检查了onPressed函数是否也正在执行,但是以某种方式Snackbar不可见。造成此问题的根本原因是什么?我觉得我传递的BuildContext有问题。

class MyApp extends StatefulWidget{
  @override
  MyAppState createState() {
    // TODO: implement createState
    return new MyAppState();
  }

}

class MyAppState extends State<MyApp>{
  File _image;
  String _text;

  Future getImage() async {
    var image = await ImagePicker.pickImage(source: ImageSource.camera);
    _image = image;
    final FirebaseVisionImage visionImage = FirebaseVisionImage.fromFile(_image);
    final TextRecognizer textRecognizer = FirebaseVision.instance.textRecognizer();
    final VisionText visionText = await textRecognizer.processImage(visionImage);

    String detectedText = visionText.text;

    setState(() {
      _image = image;
      _text = detectedText;
    });
  }

  @override …
Run Code Online (Sandbox Code Playgroud)

dart snackbar flutter

4
推荐指数
2
解决办法
1531
查看次数

为什么传递 BuildContext 会说该上下文中没有 Scaffold?

import 'package:flutter/material.dart';

main() {
  runApp(MaterialApp(
    home: HomeScreen(),
  ));
}

class HomeScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('Rite.ly'),
      ),
      body: new Container(
          decoration: new BoxDecoration(
              image: new DecorationImage(
            image: new AssetImage('assets/login_background.png'),
            fit: BoxFit.fill,
          )),
          child: new ListView(
            children: [
              new Padding(
                padding:
                    const EdgeInsets.only(top: 16.0, bottom: 8.0, left: 16.0),
                child: new Text('Link : ',
                    style: new TextStyle(color: Colors.white)),
              ),
              _takeUrl(context),
            ],
          )),
    );
  }
}

Widget _takeUrl(BuildContext context) {
  return …
Run Code Online (Sandbox Code Playgroud)

scaffold dart flutter

2
推荐指数
1
解决办法
3152
查看次数

标签 统计

dart ×2

flutter ×2

scaffold ×1

snackbar ×1