我有100辆卡车的多维阵列。每辆卡车都装有几个箱子。 我将每个卡车的第一个盒子从盒阵列拼接到卡车阵列上:
removed = allBoxes.splice(x, 1)[0];
trucks[i] = {0: removed};
因为我知道这是第一个方框,所以我可以放{0:
。但是要添加下一个框,我希望它是动态的。
我可以在正确的位置插入它,但是下一个框的键是undefined
而不是1
。
removed = allBoxes.splice(x, 1)[0];
trucks[i][trucks[i].length] = removed;
您可以在这里看到结果:它可以说undefined:
而不是1
吗?每当我尝试在数组中添加变量时,它只会写出变量字符串,而不是值。
答案 0 :(得分:0)
正如@JordanBurnett所提到的,它不是一个数组。我必须计算数组中有多少个对象。使用下面的代码(来自this question)给出了预期的结果:
import 'package:flutter/material.dart';
class SignupPage extends StatefulWidget {
@override
_SignupPageState createState() => _SignupPageState();
}
class _SignupPageState extends State<SignupPage> {
@override
Widget build(BuildContext context) {
return new Scaffold(
resizeToAvoidBottomPadding: false,
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
child: Stack(
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(16.0, 100.0, 0.0, 0.0),
child: Text(
'Signup',
style: TextStyle(
fontSize: 80.0, fontWeight: FontWeight.bold),
),
),
Container(
padding: EdgeInsets.fromLTRB(260.0, 105.0, 0.0, 0.0),
child: Text(
'.',
style: TextStyle(
fontSize: 80.0,
fontWeight: FontWeight.bold,
color: Colors.green),
),
)
],
),
),
Container(
padding: EdgeInsets.only(top: 35.0, left: 20.0, right: 20.0),
child: Column(
children: <Widget>[
TextField(
decoration: InputDecoration(
labelText: 'Full Name',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey),
// hintText: 'EMAIL',
// hintStyle: ,
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green))),
),
SizedBox(height: 10.0),
TextField(
decoration: InputDecoration(
labelText: 'Email Address ',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green))),
obscureText: true,
),
SizedBox(height: 10.0),
TextField(
decoration: InputDecoration(
labelText: 'Confirm Email Address ',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green))),
),
SizedBox(height: 10.0),
TextField(
decoration: InputDecoration(
labelText: 'Password',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green))),
obscureText: true,
),
SizedBox(height: 10.0),
TextField(
decoration: InputDecoration(
labelText: 'Phone Number ',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green))),
obscureText: true,
),
SizedBox(height: 50.0),
Container(
height: 40.0,
child: Material(
borderRadius: BorderRadius.circular(20.0),
shadowColor: Colors.greenAccent,
color: Colors.green,
elevation: 7.0,
child: GestureDetector(
onTap: () {},
child: Center(
child: Text(
'SIGNUP',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat'),
),
),
),
)),
SizedBox(height: 20.0),
Container(
height: 40.0,
color: Colors.transparent,
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
style: BorderStyle.solid,
width: 1.0),
color: Colors.transparent,
borderRadius: BorderRadius.circular(20.0)),
child: InkWell(
onTap: () {
Navigator.of(context).pop();
},
child: Center(
child: Text('Go Back',
style: TextStyle(
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat')),
),
),
),
),
],
)),
)
]));
}
}