Skip to content

Instantly share code, notes, and snippets.

@1206yaya
Created October 20, 2022 23:41
Show Gist options
  • Save 1206yaya/c797790ce4759b93b642cef605b56f02 to your computer and use it in GitHub Desktop.
Save 1206yaya/c797790ce4759b93b642cef605b56f02 to your computer and use it in GitHub Desktop.
keyboard modal
// https://stackoverflow.com/questions/71554829/textfield-in-modal
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: ""),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: _buildBody(),
floatingActionButton: FloatingActionButton(
onPressed: () {
showModalBottomSheet(
isScrollControlled: true,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
top: Radius.circular(25.0),
),
),
backgroundColor: Colors.white,
context: context,
builder: (context) => SingleChildScrollView(
child: Container(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom),
child: Wrap(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
// ... another widget
// ...
// ...
// Write review text area
Container(
margin: EdgeInsets.fromLTRB(24, 8, 24, 0),
padding: EdgeInsets.fromLTRB(16, 4, 16, 4),
width: double.infinity,
height: 100,
decoration: BoxDecoration(
color: Color(0xffF7F7F7),
borderRadius: BorderRadius.circular(20),
),
child: TextField(
expands: true,
maxLines: null,
decoration: InputDecoration(
hintText:
'Bagaimana pengalaman Anda secara keseluruhan?',
hintStyle: TextStyle(
color: Color(0xffB2B2B2),
),
border: InputBorder.none,
),
),
),
],
),
],
),
),
),
);
},
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
Widget _buildBody() {
return Container();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment