bottom_sheet 1.0.4
bottom_sheet: ^1.0.4 copied to clipboard
Flexible bottom sheet with the ability to scroll content even without a list.
example/lib/main.dart
// Copyright (c) 2019-present, SurfStudio LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import 'package:bottom_sheet/bottom_sheet.dart';
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
final String title;
const MyHomePage({
required this.title,
Key? key,
}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ElevatedButton(
onPressed: _showSheet,
child: const Text('Open BottomSheet'),
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: _showSheetWithoutList,
child: const Text('Open StickyBottomSheet'),
),
],
),
),
);
}
void _showSheet() {
showFlexibleBottomSheet<void>(
minHeight: 0,
initHeight: 0.5,
maxHeight: 1,
context: context,
builder: (context, controller, offset) {
return _BottomSheet(
scrollController: controller,
bottomSheetOffset: offset,
);
},
anchors: [0, 0.5, 1],
);
}
void _showSheetWithoutList() {
showStickyFlexibleBottomSheet<void>(
minHeight: 0,
initHeight: 0.5,
maxHeight: .8,
headerHeight: 200,
context: context,
decoration: const BoxDecoration(
color: Colors.teal,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(40.0),
topRight: Radius.circular(40.0),
),
),
headerBuilder: (context, offset) {
return AnimatedContainer(
duration: const Duration(milliseconds: 300),
width: double.infinity,
height: 200,
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(offset == 0.8 ? 0 : 40),
topRight: Radius.circular(offset == 0.8 ? 0 : 40),
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Center(
child: Text(
'Header',
style: Theme.of(context).textTheme.headline4,
),
),
),
Text(
'position $offset',
style: Theme.of(context).textTheme.headline6,
),
],
),
);
},
bodyBuilder: (context, offset) {
return SliverChildListDelegate(
_children,
);
},
anchors: [.2, 0.5, .8],
);
}
}
class _BottomSheet extends StatelessWidget {
final ScrollController scrollController;
final double bottomSheetOffset;
const _BottomSheet({
required this.scrollController,
required this.bottomSheetOffset,
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return SafeArea(
child: Material(
child: Container(
decoration: const BoxDecoration(
color: Color(0xFFFFFFFF),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(16),
topRight: Radius.circular(16),
),
),
child: ListView(
padding: EdgeInsets.zero,
controller: scrollController,
children: [
Text(
'position $bottomSheetOffset',
style: Theme.of(context).textTheme.headline6,
),
Column(
children: _children,
),
],
),
),
),
);
}
}
List<Widget> _children = [
const _TextField(),
const _TestContainer(color: Color(0xEEFFFF00)),
const _TextField(),
const _TestContainer(color: Color(0xDD99FF00)),
const _TextField(),
const _TestContainer(color: Color(0xCC00FFFF)),
const _TextField(),
const _TestContainer(color: Color(0xBB555555)),
const _TextField(),
const _TestContainer(color: Color(0xAAFF5555)),
const _TextField(),
const _TestContainer(color: Color(0x9900FF00)),
const _TextField(),
const _TestContainer(color: Color(0x8800FF00)),
const _TextField(),
const _TestContainer(color: Color(0x7700FF00)),
const _TextField(),
];
class _TextField extends StatelessWidget {
const _TextField({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Enter a search term',
),
);
}
}
class _TestContainer extends StatelessWidget {
final Color color;
const _TestContainer({
required this.color,
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
height: 100,
color: color,
),
);
}
}