Skip to content

Instantly share code, notes, and snippets.

@RobertBrunhage
Last active May 9, 2023 05:41
Show Gist options
  • Save RobertBrunhage/08e5658b839b5a45576149ed9abb8239 to your computer and use it in GitHub Desktop.
Save RobertBrunhage/08e5658b839b5a45576149ed9abb8239 to your computer and use it in GitHub Desktop.
A usage of material bottomsheet that should push the bottomsheet up in case of keyboard, but doesn't
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: darkBlue,
),
debugShowCheckedModeBanner: false,
home: Scaffold(
resizeToAvoidBottomInset: false,
body: const Center(
child: MyWidget(),
),
floatingActionButton: Builder(builder: (context) {
return FloatingActionButton(
onPressed: () {
showModalBottomSheet(
backgroundColor: darkBlue,
isScrollControlled: true,
context: context,
builder: (context) {
return Container(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom),
child: DraggableScrollableSheet(
expand: false,
builder: (context, controller) {
return BottomSheetExample(controller: controller);
},
),
);
},
);
},
);
}),
),
);
}
}
class MyWidget extends StatelessWidget {
const MyWidget({super.key});
@override
Widget build(BuildContext context) {
return Text(
'Hello, World!',
style: Theme.of(context).textTheme.headlineMedium,
);
}
}
class BottomSheetExample extends StatefulWidget {
const BottomSheetExample({super.key, required this.controller});
final ScrollController controller;
@override
State<BottomSheetExample> createState() => _BottomSheetExampleState();
}
class _BottomSheetExampleState extends State<BottomSheetExample> {
@override
void didUpdateWidget(covariant BottomSheetExample oldWidget) {
super.didUpdateWidget(oldWidget);
}
@override
Widget build(BuildContext context) {
return ListView(
controller: widget.controller,
children: const [
TextField(),
TextField(),
TextField(),
TextField(),
TextField(),
TextField(),
TextField(),
TextField(),
],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment