我能够使用两个插件的组合找到一个变通解决方案:
这样,我只在移动浏览器中访问网络应用程序时激活缩放功能。
注意:以下代码质量和结构仅用于演示目的,不应在实际应用中使用。发展
import 'package:flutter/material.dart';
import 'package:pinch_to_zoom_scrollable/pinch_to_zoom_scrollable.dart';
import 'package:platform_detector/platform_detector.dart';
class _MyHomePageState extends State<MyHomePage> {
int myFlag = 0;
@override
void initState() {
if (isAndroidOs() || isIOS()) {
myFlag = 1;
} else {
if (isAndroidApp()) {
myFlag = 2;
} else {
if (isWindowsWeb() || isLinuxWeb() || isMacOsWeb()) {
myFlag = 4;
}
}
}
super.initState();
}
@override
Widget build(BuildContext context) {
return myFlag == 0
? PinchToZoomScrollableWidget(
child: content(),
resetDuration: Duration(minutes: 5),
)
: content();
}
Widget content() {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: SingleChildScrollView(
child: Column(
children: [
Container(color: Colors.green,width: 100,height: 100,),
Container(color: Colors.green,width: 100,height: 100,),
Container(color: Colors.green,width: 100,height: 100,),
Container(color: Colors.green,width: 100,height: 100,),
Container(color: Colors.green,width: 100,height: 100,),
Container(color: Colors.green,width: 100,height: 100,),
Container(color: Colors.green,width: 100,height: 100,),
const SizedBox(
height: 16,
)
],
)),
);
}