[英]in flutter, Need to use 'Login()' in my main.dart file. Check my dart code below:
Here's the snippet of little bit of the code这是一小段代码
class Login extends StatefulWidget {
final double screenHeight, screenWidth;
const Login({Key key, this.screenHeight, this.screenWidth}) : super(key: key);
@override
_LoginState createState() => _LoginState();
}
class _LoginState extends State<Login> {
var _formkey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: PopBlue,
body: Stack(
children: <Widget>[
CustomPaint(
painter: MyCustomPainter(),
child: Container(
height: widget.screenHeight * 0.65,
),
),
...
Login class is in 1st line.登录class 在第一行。
i have to use this Login class as home: Login()
in my main.dart
file.我必须在我的main.dart
文件中使用这个登录class 作为home: Login()
。
i am not able to use this login class in my main code which is at main.dart file help me finding a way to use this class in my main.dart
file. i am not able to use this login class in my main code which is at main.dart file help me finding a way to use this class in my main.dart
file.
OK, I've played around a bit and come up with this which should help get you started, (tested and working on Chrome)好的,我玩了一会儿,想出了这个应该可以帮助你入门的方法,(测试并在 Chrome 上工作)
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) => MaterialApp(home: Login());
}
class Login extends StatefulWidget {
@override
_LoginState createState() => _LoginState();
}
class _LoginState extends State<Login> {
var _formkey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.blue, //PopBlue,
body: Stack(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height * 0.65, //widget.screenHeight * 0.65,
width: MediaQuery.of(context).size.width * 0.65,
color: Colors.red,
),
CustomPaint(
size: Size(300, 300),
painter: MyCustomPainter(),
// child: Container(
// height: MediaQuery.of(context).size.height * 0.65, //widget.screenHeight * 0.65,
// width: MediaQuery.of(context).size.width * 0.65,
// color: Colors.red, // ), ),
],
),
);
}
}
class MyCustomPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final left = 50.0;
final top = 100.0;
final right = 250.0;
final bottom = 200.0;
final rect = Rect.fromLTRB(left, top, right, bottom);
final paint = Paint()
..color = Colors.black
..style = PaintingStyle.stroke
..strokeWidth = 4;
canvas.drawRect(rect, paint);
}
@override
bool shouldRepaint(CustomPainter old) => false;
}
Your main.dart will be something like below您的 main.dart 将如下所示
import 'package:flutter/material.dart';
import 'path-of-your-login-page';//import './login.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Login();
);
}
}
What do you mean by "i am not able to use this login class in my main code"? “我无法在我的主代码中使用此登录 class”是什么意思?
Is the IDE reporting a problem? IDE 是否报告了问题? If so, what does it say?如果是这样,它说明了什么?
Or is it failing at run time?还是在运行时失败? If so, what is the error message?如果是这样,错误信息是什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.