Flutter网页设置了一个高度小于500像素的白色屏幕



当有人将选项卡的高度调整为小尺寸时,我想设置一个白色屏幕它适用于最初的路线,然而,我想为我所有的屏幕做这件事

这是我的代码

class _ExcelitState extends State<Excelit> {
@override
Widget build(BuildContext context) {
return MaterialApp(
initialRoute: '/',
key: navigatorKey,
debugShowCheckedModeBanner: false,
onUnknownRoute: (RouteSettings settings) {
return MaterialPageRoute<void>(
settings: settings,
builder: (BuildContext context) =>
const Scaffold(body: Center(child: Text('Page Not Found!!!'))),
);
},
// navigatorObservers: [observer],
routes: {
'/': (context) => (kIsWeb && setHeight(context, 0.01) <= 5)
? const EmptyScreen()
: const LoginScreen(),
},
);
}
}
class EmptyScreen extends StatelessWidget {
const EmptyScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(backgroundColor: kBackgroundColor,);
}
}

我做了以下操作:IndexedStack会保存状态,一旦网络上的屏幕高度低于~500px,我就会切换到空屏幕但我不得不把我所有的脚手架都改成CustomScaffold

import 'package:excelit/constants/constants.dart';
import 'package:excelit/main.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
class CustomScaffold extends StatelessWidget {
const CustomScaffold({Key? key, required this.widget}) : super(key: key);
final Widget widget;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: kBackgroundColor,
resizeToAvoidBottomInset: true,
body: IndexedStack(
index: (kIsWeb && setHeight(context, 0.01) <= 5) ? 1 : 0,
children: [
widget,
const EmptyScreen(), //if height is reduced below ~500px show white screen
],
),
);
}
}
class EmptyScreen extends StatelessWidget {
const EmptyScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(backgroundColor: kBackgroundColor,);
}
}

最新更新