gpt4 book ai didi

flutter - CircularProgressIndicator 不会停止

转载 作者:行者123 更新时间:2023-12-04 13:15:27 31 4
gpt4 key购买 nike

这可能是一个基本问题,但我没有找到答案。
我执行 CircularProgressIndicator() 并且屏幕显示圆圈但圆圈停止了?
在我的情况下,它继续......无休止......
为什么?我需要打电话才能停止吗?

在示例代码下方:

import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:web_scraper/web_scraper.dart';
import 'dart:io';

void main() => runApp(MyApp());

/// This Widget is the main application widget.
class MyApp extends StatelessWidget {
static const String _title = 'Flutter Code Sample';

@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: MyStatefulWidget(),
);
}
}

class MyStatefulWidget extends StatefulWidget {
MyStatefulWidget({Key key}) : super(key: key);

@override
_MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}

class _MyStatefulWidgetState extends State<MyStatefulWidget> {
int _count = 0;
bool ShowCircle = true;


Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Sample Code'),
),
body: Center(
child : Column(
children: <Widget>[
//sleep(const Duration(seconds:2)),
Text("Sample",style:TextStyle(fontSize: 21)),
]



)),
backgroundColor: Colors.blueGrey.shade200,
floatingActionButton: FloatingActionButton(
onPressed: () {
ShowCircle = !ShowCircle;
if (ShowCircle)
CircularProgressIndicator(value:0.0);
else
CircularProgressIndicator(value:1.0);
},
tooltip: 'Increment Counter',
child: const Icon(Icons.add),
),
);
}
}

BR
阿西

最佳答案

正如官方文档所说,CircularProgressIndicator 有两种行为:

  • 确定。确定进度指标在每个时间点都有一个特定的值,该值应从 0.0 单调增加到 1.0,此时指标完成。 要创建确定的进度指示器,请使用介于 0.0 和 1.0 之间的非空值 .
  • 不定。不确定的进度指标在每个时间点都没有特定的值,而是表明正在取得进展,但不表明还有多少进展。要创建不确定的进度指示器,请使用空值。

  • https://api.flutter.dev/flutter/material/CircularProgressIndicator-class.html
    class _MyStatefulWidgetState extends State<MyStatefulWidget> {
    bool _showCircle = true;

    Widget build(BuildContext context) {
    return Scaffold(
    appBar: AppBar(
    title: const Text('Sample Code'),
    ),
    body: Center(
    child: Column(
    children: <Widget>[
    Text("Indeterminate", style: TextStyle(fontSize: 21)),
    _showCircle ? CircularProgressIndicator() : CircularProgressIndicator(value: 0.0),
    Text("Determinate", style: TextStyle(fontSize: 21)),
    _showCircle ? CircularProgressIndicator(value: 0.7) : CircularProgressIndicator(value: 0.0),
    ],
    ),
    ),
    backgroundColor: Colors.blueGrey.shade200,
    floatingActionButton: FloatingActionButton(
    onPressed: () {
    setState(() {
    _showCircle = !_showCircle;
    });
    },
    tooltip: 'Increment Counter',
    child: const Icon(Icons.add),
    ),
    );
    }
    }

    关于flutter - CircularProgressIndicator 不会停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61001370/

    31 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com