我正在尝试包含,但在通过调用 SharedPreferences 和is填充 'time' 的值后,FutureBuilder
它会进入CircularProgressIndicator()
并且不会加载实际的屏幕代码 。它只是卡在 CircularProgressIndicator() 中。ConnectionState
done
我在这里想念什么?
Future<int> getTime() async {
await MySharedPreferences.instance.getIntValue("time_key").then((value) =>
setState(() {
time= value;
}));
return time;
@override
void initState() {
super.initState();
MySharedPreferences.instance
.getStringValue("title_key")
.then((value) => setState(() {
title = value;
}));
controller =
AnimationController(vsync: this,
duration: Duration(
seconds: time));
controller2 =
AnimationController(vsync: this,
duration: Duration(
seconds: time));
controller3 =
AnimationController(vsync: this,
duration: Duration(
seconds: 1));
....}
@override
Widget build(BuildContext context){
return WillPopScope(
onWillPop: () async => false,
child: Scaffold(
backgroundColor: Colors.black,
body: FutureBuilder<int>
(
future: getTime(),
builder: ( BuildContext context, AsyncSnapshot<int> snapshot) {
print(snapshot);
print(time);
if (snapshot.connectionState == ConnectionState.done) {
print(time);
return SafeArea(
minimum: const EdgeInsets.all(20.0),
child: Stack(
children: <Widget>[
Container(
child:
Align(
alignment: FractionalOffset.topCenter,
child: AspectRatio(
aspectRatio: 1.0,
child: Container(
height: MediaQuery
.of(context)
.size
.height / 2,
width: MediaQuery
.of(context)
.size
.height / 2,
decoration: BoxDecoration(
//shape: BoxShape.rectangle,
color: Colors.black,
image: DecorationImage(
image: AssetImage(
"assets/images/moon.png"),
fit: BoxFit.fill,
)
),
),
),
),
),
build_animation(),
],
),
);
}
else {
return CircularProgressIndicator();
}
}
),
),
);
}
build_animation() {
return AnimatedBuilder(
animation: controller,
builder: (context, child) {
return Stack(
children: <Widget>[
Padding(
padding: EdgeInsets.all(0.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
child: Align(
alignment: FractionalOffset.bottomCenter,
child: AspectRatio(
aspectRatio: 1.0,
child: Stack(
children: <Widget>[
Padding(
padding: EdgeInsets.only(top:MediaQuery.of(context).size.height / 6),
child: Column(
children: <Widget>[
Text(
title.toString(),
style: TextStyle(
fontSize: 20.0,
color: Colors.black,fontWeight: FontWeight.bold,),
),
new Container(
child: new Center(
child: new Countdown(
animation: new StepTween(
begin: time,
end: 0,
).animate(controller),
.....