Skip to content

Instantly share code, notes, and snippets.

@drewpayment
Created July 26, 2019 03:20
Show Gist options
  • Save drewpayment/08e963f8cf0fa715711408a2bf33d899 to your computer and use it in GitHub Desktop.
Save drewpayment/08e963f8cf0fa715711408a2bf33d899 to your computer and use it in GitHub Desktop.
Hack to fix Flutter not scrolling TextField and TextFormField into view to take viewInset of keyboard into account.
import 'package:flutter/material.dart';
class CustomBottomSheet {
static Future<T> showScrollingModalBottomSheet<T>({
@required BuildContext context,
bool isScrollControlled = true,
ShapeBorder shape,
double heightPercView = 0.95,
double topMargin = 65.0,
@required Widget appBar,
@required Widget child,
}) {
final br = BorderRadius.circular(50);
shape = shape != null ? shape
: RoundedRectangleBorder(borderRadius: br);
return showModalBottomSheet(
isScrollControlled: isScrollControlled,
context: context,
shape: shape,
builder: (ctx) {
return Container(
height: MediaQuery.of(ctx).size.height * heightPercView,
decoration: BoxDecoration(borderRadius: br),
child: Scaffold(
backgroundColor: Colors.transparent,
resizeToAvoidBottomInset: true,
appBar: PreferredSize(
preferredSize: Size.fromHeight(topMargin),
child: appBar,
),
body: child,
),
);
}
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment