這是我正在嘗試制作的應用程式的代碼,但是每當我在vs代碼終端中使用flutter run命令運行代碼時,錯誤:在主代碼中未找到用于Web和移動設備的方法主要代碼是
import 'package:flutter/material.dart';
import 'utility/colors.dart';
import 'responsive/responsive_layout_screen.dart';
import 'responsive/mobile_screen_layout.dart';
import 'responsive/webscreen_layout.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'E-Shopping',
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: mobileBackgroundColor,
),
home: const Layout(WebLayout: web(), MobileLayout: mobile()),
);
}
}
這是我的布局程式
import 'package:flutter/material.dart';
import '../utility/dimension.dart';
class Layout extends StatelessWidget {
final Widget WebLayout;
final Widget MobileLayout;
const Layout({
Key? key,
required this.WebLayout,
required this.MobileLayout,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (context, constraints) {
if (constraints.maxWidth \> 600) {
return WebLayout;
} else {
return MobileLayout;
}
});
}
}
這是我的網頁螢屏布局代碼
import 'package:flutter/material.dart';
class web extends StatelessWidget {
const web({ Key? key }) : super(key: key);
@override
Widget build(BuildContext context) {
// ignore: prefer_const_constructors
return Scaffold(
body: const Center(child: Text("web")),
);
}
}
這是我的手機螢屏布局代碼
import 'package:flutter/material.dart';
class mobile extends StatelessWidget {
const mobile({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
// ignore: prefer_const_constructors
return Scaffold(
body: const Center(child: Text("mobile")),
);
}
}
每當我運行代碼時,都會出現以下錯誤
lib/main.dart:23:37: Error: Method not found: 'web'.
home: const Layout(WebLayout: web(), MobileLayout: mobile()),
^^^
lib/main.dart:23:58: Error: Method not found: 'mobile'.
home: const Layout(WebLayout: web(), MobileLayout: mobile()),
^^^^^^
FAILURE: Build failed with an exception.
* Where:
Script 'C:\\flutter\\packages\\flutter_tools\\gradle\\flutter.gradle' line: 1102
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\\flutter\\bin\\flutter.bat'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 27s
我已經嘗試重新啟動 vs 代碼和模擬器,但錯誤仍然存??在。
uj5u.com熱心網友回復:
- 讓您的課程以大寫字母開頭
- 將每個類的檔案匯入到你需要使用的檔案中
- 屬性為以小寫開頭的駝峰式
這將有助于提高應用程式的可讀性,并使我們更容易查看您是在嘗試呼叫函式(以小寫字母開頭)還是以大寫字母開頭的 Class 建構式。
一旦您在代碼中更新它并且它仍然不起作用,請發表評論,我會根據您更新的答案來編輯我的答案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/453765.html
上一篇:我是否需要為Firebase深層鏈接提供域名才能將用戶重定向到我在Playstore上的顫振應用程式?
下一篇:如何更改對話框位置以顯示對話框?
