我正在学习Flutter的所有想法,我不知道它是否正确。我想以任何方式使用Material
Librery的LinearProgressIndicator组件,但是我没有得到使用方法,我尝试了以下代码:
import 'dart:async';
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
debugShowCheckedModeBanner: false,
home: new MyApp(),
));
}
class MyApp extends StatefulWidget {
@override
MyAppState createState() => new MyAppState();
}
class MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Slider Demo'),
),
body: new Container(
color: Colors.blueAccent,
padding: new EdgeInsets.all(32.0),
child: new ProgressIndicatorDemo(),
),
);
}
}
class ProgressIndicatorDemo extends StatefulWidget {
@override
_ProgressIndicatorDemoState createState() =>
new _ProgressIndicatorDemoState();
}
class _ProgressIndicatorDemoState extends State<ProgressIndicatorDemo>
with SingleTickerProviderStateMixin {
AnimationController _controller;
@override
void initState() {
super.initState();
_controller = new AnimationController(
duration: const Duration(milliseconds: 1500),
vsync: this,
);
_playAnimation();
}
Future<Null> _playAnimation() async {
try {
await _controller.repeat().orCancel;
} on TickerCanceled {
// the animation got canceled, probably because we were disposed
}
}
@override
void dispose() {
_controller.stop();
super.dispose();
}
@override
Widget build(BuildContext context) {
return _buildAnimation(context, null);
}
Widget _buildAnimation(BuildContext context, Widget child) {
return new Center(
child: new Container(
color: Colors.redAccent.withOpacity(.1),
child: new LinearProgressIndicator(
value: _controller.value,
backgroundColor: Colors.redAccent,
),
));
}
}
但我总是得到这个错误
I/flutter ( 3819): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY
╞═══════════════════════════════════════════════════════════
I/flutter ( 3819): The following NoSuchMethodError was thrown building
ProgressIndicatorDemo(dirty, state:
I/flutter ( 3819): _ProgressIndicatorDemoState#80400(ticker active)):
I/flutter ( 3819): The getter 'value' was called on null.
I/flutter ( 3819): Receiver: null
I/flutter ( 3819): Tried calling: value
I/flutter ( 3819):
I/flutter ( 3819): When the exception was thrown, this was the stack:
I/flutter ( 3819): #0 Object.noSuchMethod
(dart:core/runtime/libobject_patch.dart:46:5)
I/flutter ( 3819): #1 _ProgressIndicatorDemoState.build
(file:///E:/Flutter_work/animation_test/lib/main.dart:67:26)
I/flutter ( 3819): #2 StatefulElement.build
(package:flutter/src/widgets/framework.dart:3730:27)
I/flutter ( 3819): #3 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3642:15)
I/flutter ( 3819): #4 Element.rebuild
(package:flutter/src/widgets/framework.dart:3495:5)
I/flutter ( 3819): #5 StatefulElement.update
(package:flutter/src/widgets/framework.dart:3799:5)
I/flutter ( 3819): #6 Element.updateChild
(package:flutter/src/widgets/framework.dart:2699:15)
I/flutter ( 3819): #7 SingleChildRenderObjectElement.update
(package:flutter/src/widgets/framework.dart:4661:14)
I/flutter ( 3819): #8 Element.updateChild
(package:flutter/src/widgets/framework.dart:2699:15)
I/flutter ( 3819): #9 SingleChildRenderObjectElement.update
(package:flutter/src/widgets/framework.dart:4661:14)
I/flutter ( 3819): #10 Element.updateChild
(package:flutter/src/widgets/framework.dart:2699:15)
I/flutter ( 3819): #11 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3653:16)
I/flutter ( 3819): #12 Element.rebuild
(package:flutter/src/widgets/framework.dart:3495:5)
I/flutter ( 3819): #13 StatelessElement.update
(package:flutter/src/widgets/framework.dart:3702:5)
I/flutter ( 3819): #14 Element.updateChild
(package:flutter/src/widgets/framework.dart:2699:15)
I/flutter ( 3819): #15 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3653:16)
I/flutter ( 3819): #16 Element.rebuild
(package:flutter/src/widgets/framework.dart:3495:5)
I/flutter ( 3819): #17 ProxyElement.update
(package:flutter/src/widgets/framework.dart:3909:5)
I/flutter ( 3819): #18 Element.updateChild
(package:flutter/src/widgets/framework.dart:2699:15)
I/flutter ( 3819): #19 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3653:16)
I/flutter ( 3819): #20 Element.rebuild
(package:flutter/src/widgets/framework.dart:3495:5)
I/flutter ( 3819): #21 ProxyElement.update
(package:flutter/src/widgets/framework.dart:3909:5)
I/flutter ( 3819): #22 Element.updateChild
(package:flutter/src/widgets/framework.dart:2699:15)
I/flutter ( 3819): #23 RenderObjectElement.updateChildren
(package:flutter/src/widgets/framework.dart:4379:32)
I/flutter ( 3819): #24 MultiChildRenderObjectElement.update
(package:flutter/src/widgets/framework.dart:4769:17)
I/flutter ( 3819): #25 Element.updateChild
(package:flutter/src/widgets/framework.dart:2699:15)
I/flutter ( 3819): #26 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3653:16)
I/flutter ( 3819): #27 Element.rebuild
(package:flutter/src/widgets/framework.dart:3495:5)
I/flutter ( 3819): #28 StatefulElement.update
(package:flutter/src/widgets/framework.dart:3799:5)
I/flutter ( 3819): #29 Element.updateChild
(package:flutter/src/widgets/framework.dart:2699:15)
I/flutter ( 3819): #30 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3653:16)
I/flutter ( 3819): #31 Element.rebuild
(package:flutter/src/widgets/framework.dart:3495:5)
I/flutter ( 3819): #32 ProxyElement.update
(package:flutter/src/widgets/framework.dart:3909:5)
I/flutter ( 3819): #33 Element.updateChild
(package:flutter/src/widgets/framework.dart:2699:15)
I/flutter ( 3819): #34 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3653:16)
I/flutter ( 3819): #35 Element.rebuild
(package:flutter/src/widgets/framework.dart:3495:5)
I/flutter ( 3819): #36 StatefulElement.update
(package:flutter/src/widgets/framework.dart:3799:5)
I/flutter ( 3819): #37 Element.updateChild
(package:flutter/src/widgets/framework.dart:2699:15)
I/flutter ( 3819): #38 SingleChildRenderObjectElement.update
(package:flutter/src/widgets/framework.dart:4661:14)
I/flutter ( 3819): #39 Element.updateChild
(package:flutter/src/widgets/framework.dart:2699:15)
I/flutter ( 3819): #40 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3653:16)
I/flutter ( 3819): #41 Element.rebuild
(package:flutter/src/widgets/framework.dart:3495:5)
I/flutter ( 3819): #42 StatelessElement.update
(package:flutter/src/widgets/framework.dart:3702:5)
I/flutter ( 3819): #43 Element.updateChild
(package:flutter/src/widgets/framework.dart:2699:15)
I/flutter ( 3819): #44 SingleChildRenderObjectElement.update
(package:flutter/src/widgets/framework.dart:4661:14)
I/flutter ( 3819): #45 Element.updateChild
(package:flutter/src/widgets/framework.dart:2699:15)
I/flutter ( 3819): #46 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3653:16)
I/flutter ( 3819): #47 Element.rebuild
(package:flutter/src/widgets/framework.dart:3495:5)
I/flutter ( 3819): #48 StatefulElement.update
(package:flutter/src/widgets/framework.dart:3799:5)
I/flutter ( 3819): #49 Element.updateChild
(package:flutter/src/widgets/framework.dart:2699:15)
I/flutter ( 3819): #50 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3653:16)
I/flutter ( 3819): #51 Element.rebuild
(package:flutter/src/widgets/framework.dart:3495:5)
I/flutter ( 3819): #52 StatefulElement.update
(package:flutter/src/widgets/framework.dart:3799:5)
I/flutter ( 3819): #53 Element.updateChild
(package:flutter/src/widgets/framework.dart:2699:15)
I/flutter ( 3819): #54 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3653:16)
I/flutter ( 3819): #55 Element.rebuild
(package:flutter/src/widgets/framework.dart:3495:5)
I/flutter ( 3819): #56 ProxyElement.update
(package:flutter/src/widgets/framework.dart:3909:5)
I/flutter ( 3819): #57 Element.updateChild
(package:flutter/src/widgets/framework.dart:2699:15)
I/flutter ( 3819): #58 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3653:16)
I/flutter ( 3819): #59 Element.rebuild
(package:flutter/src/widgets/framework.dart:3495:5)
I/flutter ( 3819): #60 ProxyElement.update
(package:flutter/src/widgets/framework.dart:3909:5)
I/flutter ( 3819): #61 Element.updateChild
(package:flutter/src/widgets/framework.dart:2699:15)
I/flutter ( 3819): #62 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3653:16)
I/flutter ( 3819): #63 Element.rebuild
(package:flutter/src/widgets/framework.dart:3495:5)
I/flutter ( 3819): #64 StatefulElement.update
(package:flutter/src/widgets/framework.dart:3799:5)
I/flutter ( 3819): #65 Element.updateChild
(package:flutter/src/widgets/framework.dart:2699:15)
I/flutter ( 3819): #66 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3653:16)
I/flutter ( 3819): #67 Element.rebuild
(package:flutter/src/widgets/framework.dart:3495:5)
I/flutter ( 3819): #68 BuildOwner.buildScope
(package:flutter/src/widgets/framework.dart:2242:33)
Reloaded 0 of 391 libraries in 829ms.
Lost connection to device.
如何解决这个问题,我愿意做这个演示Flutter Progress Indicator
Demo,
但结果也一样。任何人都可以帮助我解决这个问题,或者告诉我代码中有什么问题吗?问候
您没有使用动画对象。
import 'dart:async';
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
debugShowCheckedModeBanner: false,
home: new MyApp(),
));
}
class MyApp extends StatefulWidget {
@override
MyAppState createState() => new MyAppState();
}
class MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Slider Demo'),
),
body: new Container(
color: Colors.blueAccent,
padding: new EdgeInsets.all(32.0),
child: new ProgressIndicatorDemo(),
),
);
}
}
class ProgressIndicatorDemo extends StatefulWidget {
@override
_ProgressIndicatorDemoState createState() =>
new _ProgressIndicatorDemoState();
}
class _ProgressIndicatorDemoState extends State<ProgressIndicatorDemo>
with SingleTickerProviderStateMixin {
AnimationController controller;
Animation<double> animation;
@override
void initState() {
super.initState();
controller = AnimationController(
duration: const Duration(milliseconds: 2000), vsync: this);
animation = Tween(begin: 0.0, end: 1.0).animate(controller)
..addListener(() {
setState(() {
// the state that has changed here is the animation object’s value
});
});
controller.repeat();
}
@override
void dispose() {
controller.stop();
super.dispose();
}
@override
Widget build(BuildContext context) {
return new Center(
child: new Container(
child: LinearProgressIndicator( value: animation.value,),
)
);
}
}
我为multi_image_picker编写了示例代码 在真实设备上启动应用程序后,我有这个日志输出 如果我触摸中心按钮,我就会有这个输出。 我该怎么修? 颤动医生 [√] Flutter(Channel beta,v1.17.0,在Microsoft Windows[版本10.0.18363.752]上,语言环境ru ru) •Flutter版本1.17.0位于C:\src\Flutter ;框
我最近安装了android studio 4.1.2和flutter 1.22.6,尽管我在android studio中安装了flutter和dart插件。 现在为了明确错误,请执行以下操作(步骤对我有效):
我已经按照这里的所有步骤进行了操作,我还在Firebase控制台中添加了SHA1键。 这是我的代码 我按照以下步骤创建了一个debug. keystore 异常:平台异常(sign_in_failed,com.google.android.gms.common.api.ApiException:10:,null)E/flutter(30467):#0 StandardMethodCodec。dec
将颤振集成到主机应用程序(docs)时,有几种方法可以实现,其中一种(最简单的)方法是通过颤振活动类在新活动中打开颤振。这样地: 传统上,对于Flutter侧的Android风格窗口,我们创建带有后退按钮的AppBar。 此AppBar后退按钮和Android系统后退按钮的行为必须相同:按下后退按钮时,前台活动必须关闭(完成)。 目前系统后退按钮确实关闭了,但如何从flutters AppBar后
我正在使用firebase云功能向特定用户发送通知。这是我从函数发送的有效负载。 我正在使用firebase_messaging(flutter package:https://pub.dartlang.org/packages/firebase_messaging)接收通知,并且我已经编写了onMessage、onLaunch和onResume方法的代码。 因此,当我使用Admin SDK发送消
我已经在我的Ubuntu机器上正确安装了颤振。我还安装了Android Studio及其插件飘飘和飞镖。无论如何,当我运行时: 我得到这个输出: 我的Android Studio位于/快照/Android Studio/当前/Android Studio我也尝试过运行: 和: 但运行后的结果始终相同,无法识别。 谢谢
/D:/flutter/. pub-ache/pub.dartlang.org/path_provider_windows-0.0.43/lib/src/path_provider_windows_real.dart:126: 25:错误:getter'addressOf'没有为类'GUID'定义。 “GUID”来自“包:win32/src/结构”(“/D:/颤动/缓存/托管/发布/达特朗.org
我注意到Flatter firebase\u消息包自动处理设备的推送通知。但是,有没有办法通过编程启用或禁用通知声音和振动?我想在我的应用程序设置中提供一个开关盒,用户可以选择在收到通知时是否希望设备发出声音和/或振动。