我使用debugShowCheckedModeBanner: false,代碼洗掉了除錯橫幅,它在我以前的所有應用程式中都運行良好。但是現在當我使用這段代碼時,只有除錯橫幅下的陰影會被洗掉。這是我的代碼
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,
home: HomeScreen(),
);
}
}
我附上了以下的圖片debugShowCheckedModeBanner: false,鏈接debugShowCheckedModeBanner: true,。
我怎樣才能完全洗掉這個除錯橫幅,請幫忙!
uj5u.com熱心網友回復:
試試下面的代碼希望它對你有幫助。
MaterialApp從HomeScreen類中洗掉小部件
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: HomeScreen(),
),
),
);
}
}
class HomeScreen extends StatelessWidget {
const HomeScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('E Com App'),
),
body: Container(
color: Colors.red,
height: 200,
width: double.infinity,
child: Text(
'Red Container',
style: TextStyle(
fontSize: 30,
color: Colors.white,
),
),
),
);
}
}
您的結果螢屏->
如果您想在課堂上使用MaterialAppWidget,請在.HomeScreenMaterialAppHomeScreen Class
debugShowCheckedModeBanner: false,
完整的小部件:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: HomeScreen(),
),
),
);
}
}
class HomeScreen extends StatelessWidget {
const HomeScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: Text('E Com App'),
),
body: Container(
color: Colors.red,
height: 200,
width: double.infinity,
child: Text(
'Red Container',
style: TextStyle(fontSize: 30, color: Colors.white),
),
),
),
);
}
}
uj5u.com熱心網友回復:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
//this code add it
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: HomeScreen(),
),
),
);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/433646.html
