这是我的代码
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
final GlobalKey<ScaffoldState> _myKey = GlobalKey();
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
drawerEnableOpenDragGesture: true,
appBar: AppBar(
title: const Text('Demo Drawer'),
automaticallyImplyLeading: false,
actions: [],
),
key: _myKey,
drawer: Drawer(
child: Text('start'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () => _myKey.currentState!.openDrawer(),
child: const Text('開啟右邊的 Drawer >'),
),
],
),
),
),
);
}
}
在模拟器中一切正常,当我在右边缘滑动时抽屉将打开。
但是当我在网络中构建时,手势不起作用。
我设置了
drawerEnableOpenDragGesture: true
但是没用
如何解决它。谢谢
请注意,
drawerEnableOpenDragGesture
不是 Flutter web 中 Scaffold 的有效属性。相反,您可以使用 :
endDrawerEnableOpenDragGesture: true,