我尝试运行以下代码(基本上,我有一个倒数计时器和一个按钮。按下按钮后,它应该:
但是,它最终得到以下错误消息:“getter 'value' 被调用为 null。 接收器:空 尝试调用:value"
我在这里附上我的代码,希望它足够简化以理解
问候
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:percent_indicator/circular_percent_indicator.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:ex11/screens/Gate_Page.dart';
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart';
class Test2 extends StatefulWidget {
@override
_Test2State createState() => _Test2State();
}
class _Test2State extends State<Test2> {
@override
Widget build(BuildContext context) {
return Scaffold(body: getbody());
}
bool anim=true;
Timer timer;
bool showSpinner=false;
Widget Stop() {
return MaterialButton(
color: Colors.red,
child: Text("stop timer"),
onPressed: () {
setState(() {
showSpinner=true;
anim=false;
timer = Timer(Duration(seconds: 3), () {
Navigator.push(context,MaterialPageRoute(builder:(context)=>Gate_Page()));
});
});
});
}
Widget animation(){
return Container(
margin: EdgeInsets.all(30),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.blue,
),
child: CircularPercentIndicator(
radius: 80.0,
animation: anim,
animationDuration: 5000,
lineWidth: 10.0,
percent: 1,
center: Text("5"),
circularStrokeCap: CircularStrokeCap.butt,
backgroundColor: Colors.yellow,
)
);
}
Widget getbody(){
return ModalProgressHUD(
inAsyncCall: showSpinner,
child: Center(
child: Container(
child: Column(children: [
animation(),
Stop()
],),
),
),
);}
}