简体   繁体   English

在 flutter 中,需要在我的 main.dart 文件中使用“Login()”。 检查我的 dart 代码如下:

[英]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.

相关问题 Android Studio 替换了我 main.dart 文件中的代码 - Android Studio replaced code in my main.dart file 如何在我的 main.dart 文件中使用 showChoiceDialog() - how can I use showChoiceDialog() in my main.dart file 调用登录function in main.dart flutter - Calling login function in main.dart flutter 如何在我的 JS 文件中使用 main.dart 变量? - How can I use main.dart variable in my JS file? 我正在尝试通过 VS 代码在模拟器上运行我的 flutter 应用程序,但收到错误消息,说它找不到我的 main.dart 文件的路径 - I'm trying to run my flutter app on an emulator from VS code and I get an error saying it cannot find the path to my main.dart file 使用Main.Dart与.java的Flutter示例入门代码 - Flutter Example Starter code with Main.Dart vs. .java 未找到目标文件“lib\main.dart”。 flutter - Target file "lib\main.dart" not found. flutter 我在我的 main.dart 文件中使用 ChangeNotifierProvider 作为暗模式出现此错误断言失败:boolean 表达式不得为 null - i use ChangeNotifierProvider for darkmode in my main.dart file got this error Failed assertion: boolean expression must not be null Flutter 在 main.dart 文件中添加提供程序的更好方法 - Flutter Better way to add Providers in main.dart file flutter 项目中的根文件(main.dart)在哪里? - Where is the root file(main.dart) in a flutter project located?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM