当我点击一个TextButton
时,我想打开一个面板(来自sliding_up_panel包)。面板应该是隐藏的,只有在我点击按钮后才能看到。
- 面板. dart *
import 'package:flutter/material.dart';
import 'package:sliding_up_panel/sliding_up_panel.dart';
class Panel extends StatelessWidget {
final ScrollController controller;
final PanelController panelController;
const Panel(
{Key? key, required this.controller, required this.panelController})
: super(key: key);
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
return ListView(
physics: const BouncingScrollPhysics(),
padding: const EdgeInsets.fromLTRB(20, 0, 20, 20),
controller: controller,
children: const <Widget>[
SizedBox(height: 32),
Center(child: Text("PANEL")),
],
);
}
}
- 我的主页.dart*
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final panelController = PanelController();
final controller = ScrollController();
@override
Widget build(BuildContext context) {
final panelHeightOpen = MediaQuery.of(context).size.height * 0.7;
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: SlidingUpPanel(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'Click Here to Build a New Panel',
),
TextButton(
onPressed: () {
//TODO: Build new Panel
},
child: const Text("Click"),
),
],
),
),
controller: panelController,
maxHeight: panelHeightOpen,
defaultPanelState: PanelState.CLOSED,
minHeight: 120,
borderRadius: const BorderRadius.vertical(top: Radius.circular(20)),
backdropTapClosesPanel: true,
//panel: ,
panelBuilder: (controller) {
return Panel(
controller: controller,
panelController: panelController,
);
},
),
);
}
}
2条答案
按热度按时间t3psigkw1#
要初始化
SlidingUpPanel
,您需要提供使用
panelController.open();
打开。mpgws1up2#
我最终复制了SlidingUpPanel代码,并将
_isPanelVisible
字段设置为false
而不是true
作为默认值。也可以调整代码,以便能够使用构造函数设置该字段(但出于我的需要,我总是希望它在开始时不可见)