简体   繁体   English

如何从除 main.dart 以外的 flutter 中的其他文件中获取参考

[英]How to take reference from other files in flutter other than main.dart

I have main.dart, search.dart, explore.dart as files in the flutter program.我有 main.dart, search.dart, explore.dart 作为 flutter 程序中的文件。 My search.dart and explore.dart are coded completely, but my main.dart is empty.我的 search.dart 和 explore.dart 是完全编码的,但是我的 main.dart 是空的。 What should be my main.dart 's code so than I have to import search and explore and have the app working ????我的 main.dart 代码应该是什么,以便我必须导入搜索和探索并使应用程序正常运行????

THIS IS MY main.dart CODE这是我的 main.dart 代码

import 'package:flutter/cupertino.dart';导入'包:颤振/cupertino.dart'; import 'search.dart';导入“search.dart”;

void main(){
  //a class from myLib in the LibraryFile.dart file
  var some = new MyApp();
}

I imported search.dart file but when I run the app I only get a white screen我导入了 search.dart 文件,但是当我运行该应用程序时,我只看到一个白屏

You have to import the file you want to show first to your main.dart file and you can navigate to that page using the code below:您必须首先将要显示的文件导入 main.dart 文件,然后您可以使用以下代码导航到该页面:

import 'package:flutter/material.dart';
import './search.dart';
import './explore.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Search(); 
      //home can be any screen you want. Search() or Explore(). 
      //With this part of code, your app will show the file you want.
    );
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter:如何打开main.dart - Flutter: How to open main.dart 如何在 flutter 中的 main.dart 中实现多个包? - How to implement multiple packages in main.dart in flutter? 在Android Studio上安装Flutter。 没有main.dart或任何文件出现 - flutter installation on android studio. No main.dart or any files showing up Flutter 返回 Main.dart 屏幕而不是关闭应用程序 - Flutter returns Main.dart screen instead of closing the Application main.dart中的脚手架未编译 - Scaffold in main.dart not compiling 我如何引用当前文件以外的其他布局文件? - How can I reference layout files other than the current one? 如何从主要父活动以外的活动中启动片段? - how to launch a fragment from an activity other than the main parent activity? 如何从main / UI以外的线程访问soundPool? - How to access soundPool from a thread other than main/UI? Flutter 的 main.dart 文件在 Android Studio 中执行时卡在“Syncing files to device Android SDK built for x86 64...” - Flutter's main.dart file gets stuck at "Syncing files to device Android SDK built for x86 64..." at execution in Android Studio 无法在 ARM Mac 上的 IntelliJ 中的 Android 模拟器上运行 Flutter 项目,说该模拟器不适用于“main.dart”配置 - Cannot run Flutter project on Android emulator in IntelliJ on ARM Mac, says that the emulator is not applicable for the "main.dart" configuration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM