import 'dart:async';import 'package:Flutter/material.dart';voID main() {runApp(new MaterialApp(deBUGShowCheckedModeBanner: false,home: new MyApp(),));}class MyApp extends StatefulWidget {@overrIDeMyAppState createState() => new MyAppState();}class MyAppState extends State<MyApp> {@overrIDeWidget 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;@overrIDevoID 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,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: nullI/Flutter ( 3819): TrIEd calling: valueI/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,));}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,); }}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,) ); }}总结
以上是内存溢出为你收集整理的android – LinearProgressIndicator Flutter用法全部内容,希望文章能够帮你解决android – LinearProgressIndicator Flutter用法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)