bottom_sheet_plus 0.0.1
bottom_sheet_plus: ^0.0.1 copied to clipboard
Demonstrating the three segment BottomSheet with drag and drop support and damping effects.
example/lib/main.dart
import 'package:bottom_sheet_plus/bottom_sheet_plus.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
///
/// 演示BottomSheet三段式
/// 启用三段式,需提供 constraints,minHeight为折叠后的最小高度,maxHeight为展开后的高度
/// 同时,设置以下属性:
/// isDragMode: true,
/// enableHalf: true,
///
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> with TickerProviderStateMixin {
late AnimationController controller;
@override
void initState() {
super.initState();
controller = AnimationController(
vsync: this,
value: 1.0,
duration: const Duration(milliseconds: 500),
reverseDuration: const Duration(milliseconds: 500),
);
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
themeMode: ThemeMode.light,
home: Scaffold(
appBar: AppBar(
elevation: 0.5,
backgroundColor: Colors.white,
title: const Text(
'BottomSheetBehavior',
style: TextStyle(fontSize: 17, color: Colors.black),
),
),
// body: Align(
// alignment: Alignment.bottomCenter,
// child: BottomSheetViewPlus(
// animationController: controller,
// elevation: 1.0,
// backgroundColor: Colors.deepOrange[200],
// isDragMode: true,
// enableHalf: true,
// isPersistent: true,
// constraints: BoxConstraints(
// maxHeight: MediaQuery.of(context).size.height * 0.75,
// minHeight: 150,
// ),
// onBehaviorChanged: _onBehaviorChanged,
// shape: const RoundedRectangleBorder(
// borderRadius: BorderRadius.only(
// topLeft: Radius.circular(16),
// topRight: Radius.circular(16),
// ),
// ),
// builder: (context) => Container(),
// ),
// ),
bottomSheet: BottomSheetViewPlus(
animationController: controller,
elevation: 1.0,
backgroundColor: Colors.deepOrange[200],
isDragMode: true,
enableHalf: true,
isPersistent: true,
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height * 0.75,
minHeight: 150,
),
onBehaviorChanged: _onBehaviorChanged,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(16),
topRight: Radius.circular(16),
),
),
builder: (context) => Container(),
),
),
);
}
BottomSheetBehavior? behavior = BottomSheetBehavior.EXPANDED;
/// 状态回调
void _onBehaviorChanged(BottomSheetBehavior behavior) {
if (this.behavior == behavior) {
return;
}
setState(() {
this.behavior = behavior;
});
}
}