gpt4 book ai didi

ios - Flutter:键盘激活时如何去除键盘后面的白色背景

转载 作者:行者123 更新时间:2023-11-29 05:20:58 24 4
gpt4 key购买 nike

我有一个 flutter 应用程序,当我的 iPhone 中激活键盘时,我确实遇到了奇怪的行为。正如您从下图中看到的,弹出键盘时,键盘下方会出现白色背景......有谁知道如何设置背景颜色???

enter image description here

编辑:感谢您建议使用 resizeToAvoidBottomPadding。该命令已弃用,我已替换为 resizeToAvoidBottomInset: false。这已经解决了问题(是的!)并且键盘下不再有白色背景,但它产生了另一个奇怪的效果。现在键盘上方有一个深蓝色的条。检查下一张图片...我设置了橙色背景颜色,以便您可以更好地看到它。您还可以看到 float 按钮向上移动,这意味着深蓝色条现在位于键盘和支架之间。你知道我怎样才能摆脱那个酒吧吗?这似乎比白色背景更糟糕,因为它占用了宝贵的屏幕空间..

作为引用,脚手架嵌套在 CupertinoTabScaffold 中 enter image description here

这是我的代码中最相关的部分

void main() async {
Crashlytics.instance.enableInDevMode = true;

FlutterError.onError = Crashlytics.instance.recordFlutterError;

runApp(ChangeNotifierProvider<Data>(
builder: (context) => Data(),
child: new CupertinoApp(

theme: CupertinoThemeData(
barBackgroundColor: kColorPrimary,

primaryColor:
kColorText,
textTheme: CupertinoTextThemeData(
primaryColor:
kColorText,
navLargeTitleTextStyle: TextStyle(
fontWeight: FontWeight.bold, fontSize: 70.0, color: kColorText),
),
),

home: new CheckIfFirstTime(),
),
));
}

class CheckIfFirstTime extends StatefulWidget {
@override
_CheckIfFirstTimeState createState() => _CheckIfFirstTimeState();
}

class _CheckIfFirstTimeState extends State<CheckIfFirstTime> {
Future checkFirstSeen() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
bool _seen = (prefs.getBool('seen') ?? false);

if (_seen) {
Navigator.of(context).pushReplacement(
new MaterialPageRoute(builder: (context) => new HomeScreen()));
}
}

@override
void initState() {
super.initState();
checkFirstSeen();
}

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: kColorPrimary,
body: Text(
'loading...',
style: kSendButtonTextStyle,
),
);
}
}



class HomeScreen extends StatefulWidget {
static const String id = 'home';

@override
_HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
int currentIndex = 0;

void confirmPlatform() {
if (Platform.isIOS)
appData.isIOS = true;
else
appData.isIOS = false;
}

@override
void initState() {
// TODO: implement initState
super.initState();
confirmPlatform();

}


@override
Widget build(BuildContext context) {
return CupertinoTabScaffold(
resizeToAvoidBottomInset: false,
tabBar: CupertinoTabBar(
backgroundColor: kColorPrimaryLight,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.search),
title: Text('Discover', style: TextStyle(fontFamily: kFontFamily)),
),

BottomNavigationBarItem(
icon: Badge(
showBadge: Provider.of<Data>(context).filterCounter == 0
? false
: true,
badgeContent: Text(
Provider.of<Data>(context).filterCounter.toString(),
style: TextStyle(color: kColorText),
),
child: Icon(Icons.filter_list)),
title: Text('Filters', style: TextStyle(fontFamily: kFontFamily)),
),

BottomNavigationBarItem(
icon: Icon(Icons.account_circle),
title: Text('Me', style: TextStyle(fontFamily: kFontFamily)),
),
BottomNavigationBarItem(
icon: Icon(Icons.assignment),
title: Text('Stories', style: TextStyle(fontFamily: kFontFamily)),
),
//with badge
BottomNavigationBarItem(
icon: Badge(
showBadge: Provider.of<Data>(context).basketCounter == '0'
? false
: true,
badgeContent: Text(
Provider.of<Data>(context).basketCounter,
style: TextStyle(color: kColorText),
),
child: Icon(Icons.shopping_cart)),
title: Text('Basket', style: TextStyle(fontFamily: kFontFamily)),
),
],
),
tabBuilder: (context, index) {
if (index == 0) {
return CupertinoTabView(
navigatorKey: firstTabNavKey,
builder: (BuildContext context) => DiscoverScreenFinal(),
);

} else if (index == 1) {
return CupertinoTabView(
navigatorKey: secondTabNavKey,
builder: (BuildContext context) => FilterScreen(),
);
} else if (index == 2) {
return CupertinoTabView(
navigatorKey: thirdTabNavKey,
builder: (BuildContext context) => WelcomeScreen(),
);
} else if (index == 3) {
return CupertinoTabView(
navigatorKey: forthTabNavKey,
builder: (BuildContext context) => Stories(),
);
}
{
return CupertinoTabView(
navigatorKey: fifthTabNavKey,
builder: (BuildContext context) => Basket(),
);
}
},
);
}
}


class DiscoverScreenFinal extends StatefulWidget {
@override
_DiscoverScreenFinalState createState() => _DiscoverScreenFinalState();
}

class _DiscoverScreenFinalState extends State<DiscoverScreenFinal> {

@override
Widget build(BuildContext context) {
return TopBarAgnostic(
text: 'Discover',
style: kSendButtonTextStyle,
firstIcon: Icon(Icons.blur_on),
firstIconDestination: CameraApp(),
scannerOn: true,
secondtIcon: Icon(Icons.location_on),
secondIconDestination: MapPage(),
uniqueHeroTag: 'discover001a',
child: Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: kColorPrimary,
floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
floatingActionButton: FloatingActionButton.extended(
backgroundColor: kColorAccent,
onPressed: () {
//…
},
label: Text(
'To Favorites',
style: kDescriptionTextStyle.copyWith(
fontSize: kFontSizeSmall, fontWeight: FontWeight.bold),
),
icon: Icon(Icons.favorite),
),
body: Container()
),
);
}
}

最佳答案

你必须在Scaffold中使用这条线,当键盘出现和消失时它会自动调整你的 View 。

resizeToAvoidBottomPadding: false

关于ios - Flutter:键盘激活时如何去除键盘后面的白色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58685174/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com