Este es el ejemplo de tu código completo donde modifico tu código para que el BottomSheet se muestre al dar click en el IconButton.
La función se ejecuta dentro de la clase Main, y no dentro de el HomePage
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
void main() => runApp(Main());
class Main extends StatelessWidget {
@override
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(statusBarColor: Colors.transparent),
);
return MaterialApp(
debugShowCheckedModeBanner: false,
title: "Social",
theme: ThemeData(primaryColor: Colors.white, primarySwatch: Colors.teal),
home: Scaffold(
drawer: Builder(
builder: (context) => Drawer(
child: ListView(
physics: BouncingScrollPhysics(),
padding: EdgeInsets.zero,
children: [
UserAccountsDrawerHeader(
accountName: Text("Nombre"),
accountEmail: Text("Correo Electronico"),
currentAccountPicture: CircleAvatar(
child: Text("N"),
)),
ListTile(
title: Text('Inicio'),
leading: Icon(Icons.home_outlined),
onTap: () {},
)
]),
),
),
appBar: AppBar(title: Text("Social"), actions: <Widget>[
IconButton(
icon: Icon(Icons.search),
onPressed: () {},
splashRadius: 20,
tooltip: "Buscar",
iconSize: 25)
]),
body: SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: Column(
children: [
Container(
margin: EdgeInsets.only(top: 5),
child: ListView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: 1,
itemBuilder: (BuildContext context, int i) => Card(
child: Container(
child: Column(
children: [
Padding(
padding: EdgeInsets.only(
left: 10,
top: 10,
right: 5,
bottom: 10,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
GestureDetector(
onTap: () {
Scaffold.of(context).showSnackBar(
SnackBar(
content: Text("click"),
),
);
},
child: CircleAvatar(
child: Text("N"),
radius: 20,
),
),
Expanded(
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.only(
left: 10,
bottom: 5,
),
child: Text(
"N",
style: TextStyle(
fontWeight: FontWeight.bold),
overflow: TextOverflow.ellipsis,
maxLines: 3,
),
),
Padding(
padding: EdgeInsets.only(left: 10),
child: Row(
children: [
Icon(
Icons.timer_outlined,
size: 12,
),
Padding(
padding: EdgeInsets.only(
left: 5,
),
child: Text(
"Fecha y Hora",
style: TextStyle(
fontSize: 12,
),
),
),
],
),
),
],
),
),
IconButton(
icon: Icon(Icons.more_vert),
iconSize: 25,
splashRadius: 20,
onPressed: () {
_onButtonPressed(context);
},
tooltip: "Opciones",
),
],
),
),
Container(
height: 500,
)
],
),
),
elevation: 0,
color: Colors.white,
margin: EdgeInsets.only(
top: 10,
bottom: 10,
),
),
),
),
],
),
),
floatingActionButton: FloatingActionButton.extended(
onPressed: () {},
label: Text(""),
icon: Icon(Icons.add),
),
backgroundColor: Color(0xFFE0E0E0),
),
);
}
void _onButtonPressed(BuildContext context) {
showModalBottomSheet(
context: context,
builder: (context) {
return MyHomePage();
},
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String _selectedItem = "";
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Home'),
),
body: Center(
child: Column(
children: [Text(_selectedItem, style: TextStyle(fontSize: 30))],
),
),
);
}
}
MyHomePage
que es unStatefulWidget
, mientras que en mi caso, desde el método principal estoy llamando a una clase 'Main' que es unStatelessWidget
y dentro de esa claseMain
recién estoy queriendo llamar aMyHomePage
mediante unIconButton
, será que este es problema por tener unStatelessWidget
en vez de unStatefulWidget
?