当我运行我的应用程序时,它可能会出现一个红色的屏幕打印无效参数。我认为问题出在我的代码上,请指出是否有问题或者这是其他问题。
I/flutter ( 4556): EXCEPTION CAUGHT BY WIDGETS LIBRARY
I/flutter ( 4556): The following ArgumentError was thrown building MyApp(dirty, state: _MyAppState#34ff8):
I/flutter ( 4556): Invalid argument(s)
I/flutter ( 4556):
I/flutter ( 4556): When the exception was thrown, this was the stack:
I/flutter ( 4556): #0 List.[] (dart:core-patch/growable_array.dart:145:60)
I/flutter ( 4556): #1 _MyAppState.build (package:colors_pick/main.dart:74:31)
I/flutter ( 4556): #2 StatefulElement.build (package:flutter/src/widgets/framework.dart:4039:27)
I/flutter ( 4556): #3 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3933:15)
I/flutter ( 4556): #4 Element.rebuild (package:flutter/src/widgets/framework.dart:3730:5)
I/flutter ( 4556): #5 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2340:33)
I/flutter ( 4556): #6 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:701:20)
I/flutter ( 4556): #7 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:285:5)
I/flutter ( 4556): #8 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1033:15)
I/flutter ( 4556): #9 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:975:9)
I/flutter ( 4556): #10 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:784:7)
I/flutter ( 4556): #12 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:382:19)
I/flutter ( 4556): #13 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:416:5)
I/flutter ( 4556): #14 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
I/flutter ( 4556): (elided one frame from package dart:async-patch)
I/flutter ( 4556):
我试过运行颤振医生,颤振干净。但没有帮助
import 'package:flutter/material.dart';
import 'dart:math';
//import 'package:random_color/random_color.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
State<StatefulWidget> createState(){
return _MyAppState();
}
}
class _MyAppState extends State<MyApp> {
// ignore: non_constant_identifier_names
List _Colors = [Colors.black,Colors.white,Colors.green,Colors.red,Colors.lightBlueAccent,Colors.yellow,
Colors.purple,Colors.orange,Colors.cyan,Colors.grey, Colors.pinkAccent, Colors.brown,
Colors.lightGreen,Colors.indigo,Colors.teal
];
int index,indbtn = 0;
Random random = new Random();
// ignore: non_constant_identifier_names
var Score = 0;
int ind=0;
void changeIndex(int ic) {
setState((){
debugPrint('Index is : $index');
bool ans = index == ic ? true : false ;
if(ans)
Score= Score+10;
else
Score = Score-10 ;
index = random.nextInt(4);
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Colors Pick',
textAlign: TextAlign.center,
),
backgroundColor: Colors.blueGrey,
),
body: Column(children:<Widget> [
Padding(
padding: EdgeInsets.only(top: 20.0),
child:ClipRRect(
borderRadius : BorderRadius.circular(700.0),
child : AnimatedContainer(
width : 150.0,height: 150.0,
color: _Colors[index],
duration : Duration(seconds: 0),
),
),),
Card(
margin: EdgeInsets.all(15.0),
child: Container(
width: 320.0,
height: 100.0,
margin: EdgeInsets.only(top:10.0, bottom:0),
decoration: new BoxDecoration(borderRadius: BorderRadius.circular(12.0),
),
child: new Column(
children: <Widget>[
new Row(children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Text("Score : $Score"),
),
],),
new Row (
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left:8.0, top:0),
child: Text("Level : 1"),
),
],
),
new Row (
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left:8.0, top:8.0),
child: Text("High Score : $Score"),
),
],
),
],
),
),
),
new Container(
margin: EdgeInsets.only(left: 20.0,top: 20.0,right: 20.0),
child:new Row(children: <Widget>[
new Expanded(child: OutlineButton(
child: Padding(
padding: const EdgeInsets.only(left:16.0,top:30.0,right:16.0 ,bottom: 30.0 ),
child: Text('First'),
),
onPressed: () {
ind = 0;
changeIndex(ind);
}, //callback when button is clicked
borderSide: BorderSide(
color: Colors.black87, //Color of the border
style: BorderStyle.solid, //Style of the border
width: 0.1, //width of the border
),), ),
new Expanded(child: OutlineButton(
child: Padding(
padding: const EdgeInsets.only(left:16.0,top:30.0,right:16.0 ,bottom: 30.0 ),
child: Text('SecondButton'),
),
onPressed: () {
ind = 1;
changeIndex(ind);
}, //callback when button is clicked
borderSide: BorderSide(
color: Colors.black87, //Color of the border
style: BorderStyle.solid, //Style of the border
width: 0.1, //width of the border
),), ),
],),
),
new Container(
margin: EdgeInsets.only(left: 20.0,right: 20.0),
child:new Row(children: <Widget>[
new Expanded(child: OutlineButton(
child: Padding(
padding: const EdgeInsets.only(left:16.0,top:30.0,right:16.0 ,bottom: 30.0 ),
child: Text('Vutton'),
),
onPressed: () {
ind = 2;
changeIndex(ind);
}, //callback when button is clicked
borderSide: BorderSide(
color: Colors.black87, //Color of the border
style: BorderStyle.solid, //Style of the border
width: 0.1, //width of the border
),), ),
new Expanded(child: OutlineButton(
child: Padding(
padding: const EdgeInsets.only(left:16.0,top:30.0,right:16.0 ,bottom: 30.0 ),
child: Text('Hell'),
),
onPressed: () {
ind = 3;
changeIndex(ind);
}, //callback when button is clicked
borderSide: BorderSide(
color: Colors.black87, //Color of the border
style: BorderStyle.solid, //Style of the border
width: 0.1, //width of the border
),), ),
],),
),
],),
bottomNavigationBar: new Container(
color: Colors.white,
height: 50.0,
alignment: Alignment.center,
child: new BottomAppBar(
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
new IconButton(
icon: Icon(Icons.home,),
onPressed: (){}),
new IconButton(icon: Icon(Icons.search,),
onPressed: null),
new IconButton(icon: Icon(Icons.school,),
onPressed: null),
new IconButton(icon: Icon(Icons.people_outline,),
onPressed: null),
new IconButton(icon: Icon(Icons.school,),
onPressed: null)
],
),
),
),
),);
}
}