gpt4 book ai didi

flutter - 在 flutter 朔迷离中,需要在我的main.dart文件中使用 'Login()'。检查以下我的 Dart 代码:

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

这是一些代码片段

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,
),
),
...

登录类位于 的第一条行中。
我必须在我的 home: Login() 文件中将此 登录类用作 main.dart
我无法在main.dart文件中的主代码中使用此登录类
帮助我找到一种在 main.dart文件中使用此类的方法。

最佳答案

好的,我做了一些尝试,并提出了一些建议,可以帮助您入门(在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;
}

关于flutter - 在 flutter 朔迷离中,需要在我的main.dart文件中使用 'Login()'。检查以下我的 Dart 代码:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61760642/

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