#android #flutter
#Android #флаттер
Вопрос:
Я пытаюсь удалить отладочный баннер из своего приложения, и я добавил debugShowCheckedModeBanner: false
в свой main.dart и каждое действие, но все еще показываю отладочный баннер.
Main.dart
void main() async {
runApp(MaterialApp(home:SplashScreen(), debugShowCheckedModeBanner: false,));
}
class SplashScreen extends StatefulWidget {
@override
_SplashScreenState createState() => new _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
startTime() async {
var _duration = new Duration(seconds: 1);
return new Timer(_duration, navigationPage);
}
void navigationPage() {
Navigator.pushReplacement(
context,
new CupertinoPageRoute(
builder: (BuildContext context) => MyHomesApp()));
}
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new Stack(
children: <Widget>[
Container(
decoration: new BoxDecoration(color: colorGreen),
),
Container(
padding: EdgeInsets.all(30.0),
child: Center(
child: new Image.asset('assets/green_h_logo.png',color: Colors.white,height: 150,width: 150,)
),
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
height: 50,
child:new Image.asset('assets/h.gif')),
),
],
),
);
}
}
Приведенный выше код — мой main.dart, он загружает заставку и через секунду переходит к myhomesapp, который имеет нижнюю панель навигации, как показано ниже:
home.dart
class MyHomesApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'App Name',
theme: ThemeData(
primarySwatch: Colors.green,
fontFamily: "Montserrat", //my custom font
),
builder: (context, child) {
return ScrollConfiguration(
behavior: MyBehavior(),
child: child,
);
},
home: Homes(),
);
}
}
class Homes extends StatefulWidget {
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Homes> {
int _currentIndex;
List<Widget> _children;
@override
void initState() {
_currentIndex = 0;
_children = [
MyDealApp(),
MyRedemptionApp(),
MyProfileApp()
];
_loadCounter();
super.initState();
}
_loadCounter() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
setState(() {
myInt = prefs.getInt('id') ?? 0;
_email = (prefs.getString('email') ?? '');
_fullname = (prefs.getString('fullname') ?? '');
currentTabs = prefs.getInt('currentTab') ?? 0;
debugPrint("currentTabMain:$currentTabMain");
debugPrint("emailr:$_email");
});
}
@override
Widget build(BuildContext context) {
const assetHome = 'assets/home_off.svg';
const assetRedemptions = 'assets/redeemed_off.svg';
const assetCommunity = 'assets/community_off.svg';
const assetProfile = 'assets/profile_off.svg';
const assetHome1 = 'assets/home_on.svg';
const assetRedemptions1 = 'assets/redeemed_on.svg';
const assetCommunity1 = 'assets/community_on.svg';
const assetProfile1 = 'assets/profile_on.svg';
return Container(
height: 30,
child:CupertinoTabScaffold(
tabBar: CupertinoTabBar(
backgroundColor: colorGreen,
currentIndex: _currentIndex,
onTap: onTabTapped,
items: [
BottomNavigationBarItem(
icon: _currentIndex == 0 ?SvgPicture.asset(assetHome1,
color: Colors.white,
width: 20,
height: 20,
semanticsLabel: 'Home'):SvgPicture.asset(assetHome,
color: Colors.white,
width: 20,
height: 20,
semanticsLabel: 'Home'),
),
BottomNavigationBarItem(
icon: _currentIndex == 1 ?SvgPicture.asset(assetRedemptions1,
color: Colors.white,
width: 20,
height: 20,
semanticsLabel: 'Redemptions'):SvgPicture.asset(assetRedemptions,
color: Colors.white,
width: 20,
height: 20,
semanticsLabel: 'Redemptions'),
),
BottomNavigationBarItem( icon: _currentIndex == 2 ? SvgPicture.asset(assetProfile1,
color: Colors.white,
width: 20,
height: 20,
semanticsLabel: 'Profile'):SvgPicture.asset(assetProfile,
color: Colors.white,
width: 20,
height: 20,
semanticsLabel: 'Profile'),
),
],
),
tabBuilder: (BuildContext context, int index) {
return CupertinoTabView(
builder: (BuildContext context) {
return SafeArea(
top: false,
bottom: false,
child: CupertinoApp(
home: CupertinoPageScaffold(
resizeToAvoidBottomInset: false,
child: _children[_currentIndex],
),
),
);
},
);
}
));
}
void onTabTapped(int index) {
setState(() {
_currentIndex = index;
debugPrint("tabbottom:$_currentIndex");
});
}
}
Я использовал то же самое для MyRedemptionApp()
и MyProfileApp()
соответственно. Основная проблема debugShowCheckedModeBanner: false
заключается в том, что отладочный баннер не удаляется, потому что отладочный баннер отображается на каждой странице. Как удалить отладочный баннер?
Комментарии:
1. Я думаю, у вас есть два
MaterialApp
виджета. Пожалуйста, используйте одинMaterialApp
. для одного приложения2. Я использую materialapp, чтобы остановить ошибку материализации, для которой требуется materialapp в корне приложения
Ответ №1:
Обычно это происходит, когда используется несколько виджетов MaterialApp. Если вы не думаете, что можете свести к единице, просто используйте debugShowCheckedModeBanner:false всякий раз, когда вы используете виджеты MaterialApp в своем приложении.