gpt4 book ai didi

flutter - 为什么此初始屏幕代码无法正常运行?

转载 作者:行者123 更新时间:2023-12-03 03:25:12 24 4
gpt4 key购买 nike

main.dart ----

import 'package:flutter/material.dart';
import 'package:flutter_app/splashscreen.dart';
import 'package:flutter_app/homepage.dart';
import 'package:flutter_app/constants.dart';

void main() => runApp(MaterialApp(
title: 'GridView Demo',
home: SplashScreen(),
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.red,
accentColor: Color(0xFF761322),
),
routes: <String, WidgetBuilder>{
SPLASH_SCREEN: (BuildContext context) => SplashScreen(),
HOME_SCREEN: (BuildContext context) => HomeScreen(),
//GRID_ITEM_DETAILS_SCREEN: (BuildContext context) => GridItemDetails(),
},
));



slashscreen.dart ------

import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app/constants.dart';



class SplashScreen extends StatefulWidget {
@override
SplashScreenState createState() => new SplashScreenState();
}

class SplashScreenState extends State<SplashScreen>
with SingleTickerProviderStateMixin {
var _visible = true;

AnimationController animationController;
Animation<double> animation;

startTime() async {
var _duration = new Duration(seconds: 3);
return new Timer(_duration, navigationPage);
}

void navigationPage() {
Navigator.of(context).pushReplacementNamed(HOME_SCREEN);
}

@override
void initState() {
super.initState();
animationController = new AnimationController(
vsync: this,
duration: new Duration(seconds: 2),
);
animation =
new CurvedAnimation(parent: animationController, curve: Curves.easeOut);

animation.addListener(() => this.setState(() {}));
animationController.forward();

setState(() {
_visible = !_visible;
});
startTime();
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
fit: StackFit.expand,
children: <Widget>[
new Column(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: EdgeInsets.only(bottom: 30.0),
child: new Image.asset(
'assets/r1.png',
height: 25.0,
fit: BoxFit.scaleDown,
),
)
],
),
new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Image.asset(
'assets/r2.png',
width: animation.value * 250,
height: animation.value * 250,
),
],
),
],
),
);
}
}




homepage.dart --------
import 'package:flutter/material.dart';


class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Table Widget")),
body: Center(child:Text('jai sri ram ')
)
);
}
}


constants.dart -----
String SPLASH_SCREEN='SPLASH_SCREEN';
String HOME_SCREEN='HOME_SCREEN';



1.错误的未定义名称'SPLASH_SCREEN'

2.错误的未定义名称'HOME_SCREEN'

3.如何解决此错误?

我不知道为什么这些未定义的名称错误会出现在屏幕上,也不知道如何解决这些错误。

如何解决未定义名称SPLASH_SCREEN和HOME_SCREEN错误?

请帮助我..谢谢

最佳答案

我尝试了您的代码,它工作正常。

您可以尝试以下操作:

  • 在项目目录
  • 中运行 flutter clean
  • 重新启动/重新安装应用程序,而不是使用热重加载
  • 关于flutter - 为什么此初始屏幕代码无法正常运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58576901/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com