@override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: Container(
height: 60,
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.white,
CupertinoColors.extraLightBackgroundGray
], // Adjust the grey color if needed
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
child: CupertinoNavigationBar(
backgroundColor: Colors.transparent,
automaticallyImplyLeading: false,
middle: Container(
height: 42,
width: 95,
decoration: BoxDecoration(
color: navbg,
borderRadius: BorderRadius.circular(25),
),
child: IconButton(
onPressed: () {
showModalBottomSheet(
backgroundColor: Colors.transparent,
useSafeArea: true,
context: context,
isScrollControlled: true,
builder: (BuildContext context) {
return SearchSheet();
},
);
},
icon: const Icon(
CupertinoIcons.plus,
),
padding: EdgeInsets.zero,
color: Colors.black,
hoverColor: Colors.transparent,
highlightColor: Colors.transparent,
)),
trailing: Container(
height: 35,
width: 35,
decoration: BoxDecoration(
color: navbg,
borderRadius: BorderRadius.circular(20),
),
child: IconButton(
onPressed: () {
showModalBottomSheet(
context: context,
isScrollControlled: true,
useSafeArea: true,
builder: (BuildContext context) {
return SettingsBottomSheet(
webViewController: _webViewController,
currentUrl: _currentUrl,
currentTitle: _currentTitle,
);
});
},
icon: const SizedBox(
child: Icon(
size: 20,
CupertinoIcons.chevron_up,
),
),
padding: EdgeInsets.zero,
color: Colors.black,
hoverColor: Colors.transparent,
highlightColor: Colors.transparent,
)),
),
),
body: SafeArea(
child: WillPopScope(
onWillPop: () async {
return _handleBackPress(); // Handle back press with animation
},
child: Stack(
children: [
Column(
children: [
Expanded(
child: InAppWebView(
initialUrlRequest: URLRequest(
url: WebUri(_buildInitialUrl(widget.query)),
),
initialOptions: _options,
onWebViewCreated: (controller) {
_webViewController = controller;
},
onLoadStart: (controller, url) {
setState(() {
_currentUrl = url.toString();
isLoading = true; // Page is loading
});
},
onLoadStop: (controller, url) async {
setState(() {
_currentUrl = url.toString();
isLoading = false;
});
// If the current URL is a Google search result, hide the search bar
if (_currentUrl.contains('google.com/search')) {
// Injecting JavaScript to hide Google search elements
await _webViewController
.evaluateJavascript(source: '''
(function() {
var googleBar = document.getElementById('searchform');
if (googleBar) googleBar.style.display = 'none';
var googleLogo = document.querySelector('img[alt="Google"]');
if (googleLogo) googleLogo.style.display = 'none';
var topNav = document.querySelector('div#top_nav');
if (topNav) topNav.style.display = 'none';
var footer = document.querySelector('footer');
if (footer) footer.style.display = 'none';
var sidePanel = document.querySelector('div#rhs');
if (sidePanel) sidePanel.style.display = 'none';
})();
''');
}
},
onTitleChanged: (controller, title) {
setState(() {
_currentTitle = title ?? '';
});
},
shouldOverrideUrlLoading:
(controller, navigationAction) async {
var uri = navigationAction.request.url!;
if (uri.scheme == "http" || uri.scheme == "https") {
return NavigationActionPolicy.ALLOW;
}
return NavigationActionPolicy.CANCEL;
},
),
),
isLoading // Use the state variable for the loading state
? Positioned(
bottom: 0,
left: 0,
right: 0,
child: WaterWave(),
)
: const SizedBox.shrink(),
],
),
],
),
),
),
);
}
}
在调试中一切正常,但在发布时出现灰屏并且不显示网络视图。 我已提供所有发布权限。
解决ReleaseMode下的灰屏问题。您应该始终关心如何使用 Stack 和 Column/Row 、Flex 和 Expanded Widget。请在代码中遵循此结构来解决问题。不要在 Stack Widget
中使用 Column/Row widget Stack(
children: [
Container(
child: ElevatedButton(onPressed: (){}, child: Text('sdfsdf')),
),
true // Use the state variable for the loading state
? Positioned(
bottom: 0,
left: 0,
right: 0,
child: SizedBox(),
)
: const SizedBox.shrink(),
],
),