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