Flutter / Dart - Problem with SetState called from a Floating Action Button - flutter

I am having trouble with calling SetState when pressing a FAB. Nothing changes on the screen...
Here's the code :
bool _editMode = false;
return DefaultTabController(
length: 3,
child: Scaffold(
backgroundColor: Colors.orange[100],
appBar: AppBar(
backgroundColor: Colors.white,
automaticallyImplyLeading: false,
title: Center(
child: Text(
'Liste de vocabulaire n°${userData.selectedCarnetList + 1}'
.toUpperCase(),
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.blue[800],
),
maxLines: 2,
textAlign: TextAlign.center,
),
),
actions: [
GestureDetector(
child: Container(
padding: EdgeInsets.all(16.0),
child: listsProvider.dicoLanguage == Language.french
? Image.asset(
'icons/french_flag.png',
height: 45.0,
width: 45.0,
)
: Image.asset(
'icons/english_flag.png',
height: 45.0,
width: 45.0,
),
),
onTap: () => listsProvider.dicoLanguage == Language.french
? listsProvider.setDicoLanguage(Language.english)
: listsProvider.setDicoLanguage(Language.french),
),
],
bottom: TabBar(
indicatorWeight: 10,
indicatorColor: Colors.green[800],
tabs: [
Tab(
child: Text(
'Ordre alphabétique',
textAlign: TextAlign.center,
style: TextStyle(color: Colors.red[800]),
),
),
Tab(
child: Text(
'Catégorie grammaticale',
textAlign: TextAlign.center,
style: TextStyle(color: Colors.red[800]),
),
),
Tab(
child: Text(
'Niveau',
textAlign: TextAlign.center,
style: TextStyle(color: Colors.red[800]),
),
),
]),
),
body: TabBarView(
children: [
ListView(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: CarnetListCard(
index: index,
taille:
userData.userInfo.carnetVoc[index].wordId.length,
titre: userData.userInfo
.carnetVoc[userData.selectedCarnetList].titre
.toUpperCase(),
dateCreation:
userData.userInfo.carnetVoc[index].creation,
dateModification:
userData.userInfo.carnetVoc[index].modification,
mots: ListView.builder(
itemCount: userData
.userInfo.carnetVoc[index].wordId.length,
itemBuilder: (context, index2) {
return ListTile(
contentPadding: EdgeInsets.all(0),
title: Container(
decoration: BoxDecoration(
color: Colors.red[800],
borderRadius: BorderRadius.circular(10.0),
),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceAround,
children: [
Expanded(
child: Text(
listsProvider.dicoLanguage ==
Language.english
? wordBank[userData
.userInfo
.carnetVoc[index]
.wordId[index2]]
.main
: wordBank[userData
.userInfo
.carnetVoc[index]
.wordId[index2]]
.mainFr,
style: TextStyle(
color: Colors.white,
fontSize: 13.0,
),
),
),
Expanded(
child: Text(
listsProvider.dicoLanguage ==
Language.english
? wordBank[userData
.userInfo
.carnetVoc[index]
.wordId[index2]]
.mainFr
: wordBank[userData
.userInfo
.carnetVoc[index]
.wordId[index2]]
.main,
style: TextStyle(
color: Colors.orange[100],
fontSize: 13.0),
),
),
],
),
),
),
onTap: () => Navigator.push(context,
MaterialPageRoute(builder: (context) {
return DisplayThematicList(
subTheme: listsProvider
.themeBank[index].subTheme[index2],
langue: listsProvider.dicoLanguage,
image: listsProvider.themeBank[index].thema,
);
})),
);
},
),
),
),
],
),
ListView(),
ListView(),
],
),
floatingActionButton: _editMode == false
? Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 25.0),
child: FloatingActionButton(
heroTag: 'Back',
backgroundColor: Colors.red[800],
child: Icon(Icons.arrow_back),
onPressed: () => Navigator.pushReplacementNamed(
context, CarnetScreen.id),
),
),
FloatingActionButton.extended(
heroTag: 'Edit',
backgroundColor: Colors.blue[800],
icon: Icon(Icons.edit),
label: Text('Modifier'),
onPressed: () {
setState(() {
_editMode = true;
print(_editMode);
});
})
],
)
: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 25.0),
child: FloatingActionButton(
heroTag: 'Close',
backgroundColor: Colors.red[800],
child: Icon(Icons.close),
onPressed: () => Navigator.pushReplacementNamed(
context, CarnetScreen.id),
),
),
FloatingActionButton.extended(
heroTag: 'Valider',
backgroundColor: Colors.green[800],
icon: Icon(Icons.library_add_check_rounded),
label: Text('Valider'),
onPressed: () {
setState(() {
_editMode = false;
print(_editMode);
});
}),
],
),
),
);
}
}
When tapping FAB ('EDIT'), I set (_editMode) to TRUE, and it should rebuild with new buttons showing... but for some reason nothing happens...
Is there anything in a FAB which separates the action from the State of the Screen ? or could it be due to the TAB BAR ?
Any idea why ?

Put your variable bool _editMode = false; above build method
bool _editMode = false;
#override
Widget build(BuildContext context) {

Related

How to remove children background color from ExpansionTile title on animation?

This is my code:
class Temp extends StatefulWidget {
const Temp({Key? key}) : super(key: key);
#override
State<Temp> createState() => _TempState();
}
// stores ExpansionPanel state information
class Item {
Item(bool exp) {
this.isExpanded = exp;
}
late bool isExpanded;
}
List<Item> items = [Item(false), Item(true), Item(true), Item(false)];
class _TempState extends State<Temp> {
#override
Widget build(BuildContext context) {
return DefaultTabController(
length: 4,
child: Scaffold(
body: SingleChildScrollView(
child: Container(
child: ExpansionPanelList(
expandedHeaderPadding: EdgeInsets.zero,
expansionCallback: (int index, bool isExpanded) {
setState(() {
items[index].isExpanded = !isExpanded;
});
},
children: [
ExpansionPanel(
headerBuilder: (BuildContext context, bool isExpanded) {
return ListTile(
title: Text("Test", style: TextStyle(fontSize: 16, fontWeight: FontWeight.w700)),
leading: Icon(Icons.info),
minLeadingWidth : 4,
contentPadding: EdgeInsets.symmetric(vertical: 0.0, horizontal: 16.0),
dense:true,
);
},
body: Column(
children: [
ListTile(
title: Text("Test 1", style: TextStyle(fontSize: 16)),
leading: Icon(Icons.handshake_outlined),
minLeadingWidth : 4,
contentPadding: EdgeInsets.symmetric(vertical: 0.0, horizontal: 16.0),
dense:true,
),
ExpansionTile(
title: const Text('Test 2', style: TextStyle(color: Colors.black87),),
leading: Icon(Icons.handshake_outlined, color: Colors.black54,),
trailing: Column(),
children: <Widget>[
ListTile(
dense: true,
tileColor: Color(0xffffeed4),
title: Text('Foo', style: TextStyle (fontSize: 16),),
trailing: SizedBox(
child: Text("foo", style: TextStyle (fontSize: 16),)
),
),
ListTile(
tileColor: Color(0xffffeed4),
title: Text('Bar', style: TextStyle (fontSize: 16),),
dense: true,
trailing: SizedBox(
child: Text("bar", style: TextStyle (fontSize: 16),)
),
),
Container(
height: 10,
color: Color(0xffffeed4),
),
Container(
color: Color(0xffffeed4),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.indigo,
shape: CircleBorder(),
),
child: Icon(
Icons.copy,
color: Colors.white,
),
onPressed: () {},
),
TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.indigo,
shape: CircleBorder(),
),
child: Icon(
Icons.delete_rounded,
color: Colors.white,
),
onPressed: () {},
),
TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.indigo,
shape: CircleBorder(),
),
child: Icon(
Icons.info_outline,
color: Colors.white,
),
onPressed: () {},
),
],
),
),
Container(
height: 10,
color: Color(0xffffeed4),
)
],
onExpansionChanged: (bool expanded) {
//setState(() => _customTileExpanded = expanded);
},
),
],
),
isExpanded: items[1].isExpanded,
canTapOnHeader: true
),
],
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: null,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
)
);
}
}
And this is the result:
As you see when I click on ExpansionTile title/header then children background is visible not only on this ExpansionTile title/header (Test 2) but also on the previous one (Test 1). As a result it is rather ugly. I don't want children background color be visible on ExpansionTile title/header. Could anyone say how to do it?
It is a bug in flutter. Issue is here

how to see the element in emulator ui in flutter

Now I am adding a scrollbar to my app, this is my code:
final ScrollController _scrollController = ScrollController();
return GestureDetector(
onHorizontalDragStart: _onHorizontalDragStart,
onHorizontalDragUpdate: _onHorizontalDragUpdate,
onHorizontalDragEnd: _onHorizontalDragEnd,
child: Container(
constraints: BoxConstraints(
minHeight: MediaQuery.of(context).size.height * 0.9,
),
color: Theme.of(context).scaffoldBackgroundColor,
child: CupertinoScrollbar(
isAlwaysShown: true,
controller: _scrollController,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: buildListView(item, context),
),
)));
but in the UI, I did not find the ScrollBar. How to make the scrollbar show on the UI? or like inspect element like html in Chrome. this is the UI:
I have wake up the Flutter Inspector, but when I click the element, nothing happen in the emulator. Now I am using SingleChildScrollView:
SingleChildScrollView buildListView(Item item, BuildContext context) {
return SingleChildScrollView(
controller: _scrollController,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
InkWell(
onTap: () => CommonUtils.launchUrl(item.link),
child: Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: Container(
child: Text(
item.title == "" ? "Comment" : item.title,
style: Theme.of(context).textTheme.headline5!.copyWith(
fontWeight: FontWeight.w600,
),
),
),
),
),
if (item.domain != "")
Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: InkWell(
onTap: () async {
navToChannelDetail();
},
child: Text(
item.domain,
style: Theme.of(context).textTheme.caption!.copyWith(color: Theme.of(context).primaryColor),
)),
),
InkWell(
onTap: () {},
child: RichText(
text: TextSpan(
children: <TextSpan>[
TextSpan(
text: item.author,
style: Theme.of(context).textTheme.caption,
),
TextSpan(
text: " ${String.fromCharCode(8226)} ",
style: Theme.of(context).textTheme.caption,
),
TextSpan(
text: item.ago,
style: Theme.of(context).textTheme.caption,
),
],
),
),
),
if (item.content != "")
Html(
data: item.content,
style: {
"body": Style(
fontSize: FontSize(19.0),
),
},
//sonLinkTap: (url) => CommonUtils.launchUrl(url),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Padding(
padding: const EdgeInsets.only(right: 16.0),
child: Row(
children: [
if (item.isFav == 1)
IconButton(
icon: Icon(Icons.bookmark, color: Theme.of(context).primaryColor),
onPressed: () => touchFav("unfav", FavStatus.UNFAV),
),
if (item.isFav != 1)
IconButton(
icon: Icon(Icons.bookmark),
onPressed: () => touchFav("fav", FavStatus.FAV),
),
Padding(
padding: const EdgeInsets.only(left: 0.0),
child: Text(
"${item.favCount}",
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.caption!.copyWith(
color: Theme.of(context).primaryColor,
),
),
),
],
),
),
Padding(
padding: const EdgeInsets.only(bottom: 0.0),
child: Row(
children: [
if (item.isUpvote == 1)
IconButton(
icon: Icon(Icons.thumb_up, color: Theme.of(context).primaryColor),
onPressed: () => touchUpvote("unupvote", UpvoteStatus.UNUPVOTE),
),
if (item.isUpvote != 1)
IconButton(
icon: Icon(Icons.thumb_up),
onPressed: () => touchUpvote("upvote", UpvoteStatus.UPVOTE),
),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Text(
"${item.upvoteCount}",
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.caption!.copyWith(
color: Theme.of(context).primaryColor,
),
),
),
],
),
),
],
),
IconButton(
icon: Icon(
Feather.share_2,
),
onPressed: () => handleShare(id: item.id, title: item.title, postUrl: item.link),
),
],
),
],
));
}
You must add the _scrollController to ListView
You can try this , I hope to help you :
return Container(
constraints: BoxConstraints(
minHeight: MediaQuery.of(context).size.height * 0.9,
),
color: Theme.of(context).scaffoldBackgroundColor,
child: CupertinoScrollbar(
isAlwaysShown: true,
controller: _scrollController,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: ListView.builder(
controller: _scrollController,
itemCount: 500,
shrinkWrap: true,
itemBuilder:(_, index){
return Text('Index Number : '+index.toString());
}),
),
));

Trigger slidable from button flutter

I'm using the flutter_slidable package to delete items from a list I have in my app. But I would like to create a button outside of the listview that can trigger these items to display their slidables, but I am unsure how to do this from the documentation provided
https://pub.dev/packages/flutter_slidable
bool isClicked = false;
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
brightness: Brightness.light,
leading: new IconButton(
icon: new Icon(Icons.arrow_back, color: Colors.black),
onPressed: () {
Navigator.of(context).pop();
},
),
backgroundColor: Colors.white,
title: const Text(
'User Cards',
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.black, fontSize: 20.0),
),
actions: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 20.0),
child: Row(
children: <Widget>[
GestureDetector(
onTap: () {
Provider.of<CardBrandProvider>(context, listen: false).clearCardBrand();
Provider.of<Data>(context, listen: false).selectedBrand = null;
Navigator.push(context, MaterialPageRoute(builder: (context) => AddCard()));
},
child: Row(
children: <Widget>[
Icon(
Icons.card_giftcard,
color: Colors.grey[600],
size: 28.0,
),
Icon(
Icons.add,
size: 20.0,
color: Colors.black45,
),
],
)),
],
),
)
],
elevation: 1.0,
centerTitle: true,
),
body: CustomScrollView(
slivers: [
Provider.of<CardProvider>(context, listen: false).cards.isNotEmpty ?
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.only(top: 20),
child: Padding(
padding: const EdgeInsets.only(left: 30.0, right: 26.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'Cards',
style: TextStyle(
fontSize: 17.0,
fontWeight: FontWeight.w500,
fontFamily: 'Lato'),
),
GestureDetector(
onTap: (){
isClicked = true;
},
child: Text(
'Edit',
style: TextStyle(
fontSize: 17.0,
fontWeight: FontWeight.w500,
color: Color.fromRGBO(129, 2, 2, 1),
fontFamily: 'Lato'),
),
),
],
),
),
),
)
:
SliverToBoxAdapter(child: Container(),),
SliverToBoxAdapter(
child: SizedBox(
height: 25,
),
),
Container(
child: SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
var card = getCards(context)[index];
var id = card.Id;
return InkWell(
child: Padding(
padding: const EdgeInsets.only(top: 15, bottom: 15),
child: Column(
children: [
Container(
child: Slidable(
enabled: isClicked,
actionPane: SlidableDrawerActionPane(),
secondaryActions: <Widget>[
IconSlideAction(
caption: 'Delete',
color: Colors.red,
icon: Icons.delete,
onTap: () async {
setState(() {
showSpinner = true;
});
try{
print('$id');
setState(() {
Provider.of<Cards>(context, listen: false).removeIndividualCard(index);
});
} catch(e){
print(e);
setState(() {
showSpinner = true;
});
}
}),
],
child: ListTile(
title: Text('Username$index'),
trailing: Icon(Icons.person),
),
),
),
],
),
),
);
},
childCount: 5,
),
],
),
);
}
}
make a button and handle: Slidable(enabled: false,)

How to display TabBar in bottom of a widget

Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Column(
children: [
Container(
color:Colors.blueGrey.shade900,
width: double.infinity,
height: MediaQuery.of(context).size.height * 0.15,
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text("Available Balance ₹ 10050", style: TextStyle(
color: Colors.white,
fontSize: 18,
),),
],),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
RaisedButton(onPressed: () {}, color: Colors.teal, child: Text("Recharge", style: TextStyle(
color: Colors.white
),),),
RaisedButton(onPressed: () {}, color: Colors.teal, child: Text("Read Rule", style: TextStyle(
color: Colors.white
),),),
Icon(Icons.refresh_rounded, color: Colors.white,)
],),
),
SizedBox(
height: 5,
),
// I need to insert the tabBarHere
],
),
),
],
),
),
);
I have created the widget from flutter but i am not able to display the TabBar after this Widget. I have seen the basic method to create the tabs using DefaultTabController() but it is working when we are using in the bottom of the appbar
You can use a NestedScrollView:
Scaffold(
body: SafeArea(
child: DefaultTabController(
length: 2,
child: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxScrolled) {
return <Widget>[
SliverToBoxAdapter(
child: Container(
color: Colors.blueGrey.shade900,
width: double.infinity,
height: MediaQuery.of(context).size.height * 0.15,
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text(
"Available Balance ₹ 10050",
style: TextStyle(
color: Colors.white,
fontSize: 18,
),
),
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
RaisedButton(
onPressed: () {},
color: Colors.teal,
child: Text(
"Recharge",
style: TextStyle(color: Colors.white),
),
),
RaisedButton(
onPressed: () {},
color: Colors.teal,
child: Text(
"Read Rule",
style: TextStyle(color: Colors.white),
),
),
Icon(
Icons.refresh,
color: Colors.white,
)
],
),
),
SizedBox(
height: 5,
),
],
),
),
),
SliverToBoxAdapter(
child: Container(
color: Colors.blueGrey.shade900,
child: TabBar(
tabs: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: Icon(Icons.card_giftcard),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: Icon(Icons.store),
),
],
),
),
),
];
},
body: Column(
children: <Widget>[
Flexible(
child: TabBarView(
children: [
Center(child: Text('tab 1')),
Center(child: Text('tab 2')),
],
),
),
],
),
),
),
)
)
Result:
you can use bottomNavigationBar
class _MyHomePageState extends State<MyHomePage> {
var selectedIndex = 0;
void onItemTapped(int index) {
setState(() {
selectedIndex = index;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("data"),
backgroundColor: Colors.blueGrey.shade900,
actions: <Widget>[Icon(Icons.notifications)],
),
drawer: Drawer(),
bottomNavigationBar: BottomNavigationBar(
backgroundColor: Colors.amber,
elevation: 12.0,
type: BottomNavigationBarType.shifting,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(icon: Icon(Icons.store), title: Text('Home')),
BottomNavigationBarItem(
icon: Icon(Icons.warning), title: Text('Warning')),
],
showUnselectedLabels: true,
currentIndex: selectedIndex,
unselectedItemColor: Colors.white,
fixedColor: Colors.teal,
onTap: onItemTapped,
),
body: SingleChildScrollView(
child: Column(
children: [
Container(
color: Colors.blueGrey.shade900,
width: double.infinity,
height: MediaQuery.of(context).size.height * 0.15,
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text(
"Available Balance ₹ 10050",
style: TextStyle(
color: Colors.white,
fontSize: 18,
),
),
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
RaisedButton(
onPressed: () {},
color: Colors.teal,
child: Text(
"Recharge",
style: TextStyle(color: Colors.white),
),
),
RaisedButton(
onPressed: () {},
color: Colors.teal,
child: Text(
"Read Rule",
style: TextStyle(color: Colors.white),
),
),
Icon(
Icons.refresh,
color: Colors.white,
)
],
),
),
SizedBox(
height: 5,
),
// I need to insert the tabBarHere
],
),
),
],
),
),
);
}

Flutter Dart Bottomsheet error context = context

I hope somebody can help me solve this error;
I used this showModalBottomSheet Widget already, and just tried to implement the structure onto a new site. The error I get and just don't understand in the BottomSheet has something to do with " context = context, " . Do I have to iplement the void funktion somwhere else or should I create a new class that is extending the Header class? Can somebody please help me?
class Home extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomPadding: false,
body: ListView(
children: <Widget>[
Header(),
//SelectOption(),
//Chats(),
//MoodsDetector(),
//NextUp(),
//PostFeed(),
],
),
);
}
}
class Header extends StatelessWidget {
const Header({
Key key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.fromLTRB(25, 50, 50, 25),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Welcome back,',
style: TextStyle(color: secondColor, fontSize: 20),
),
Text(
'Henri',
style: TextStyle(color: mainColor, fontSize: 30),
),
],
),
Container(
width: 50,
height: 50,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
boxShadow: [
BoxShadow(color: secondColor.withOpacity(0.5), blurRadius: 20),
],
),
child: new IconButton(
icon: new Icon(Icons.search),
highlightColor: Colors.pink,
onPressed: _showSearch,
),
),
],
),
);
}
void _showSearch(){
showModalBottomSheet(
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(topRight: Radius.circular(30.0),topLeft: Radius.circular(30.0))
),
isScrollControlled: true,
isDismissible: true,
context: context,
builder: (builder) {
return SingleChildScrollView(
child: Column(
children: <Widget>[
Stack(
children: <Widget>[
SingleChildScrollView(
padding: const EdgeInsets.all(15.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Card(
elevation: 8.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
color: Colors.green,
child: ListTile(
onTap: () {
//open edit profile
},
title: Text(
"Rate your Friendship",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
leading: CircleAvatar(
backgroundImage: AssetImage("assets/images/HenriKlein.jpeg"),
),
trailing: Icon(
Icons.star,
color: Colors.white,
),
),
),
const SizedBox(height:10.0),
Card(
elevation: 4.0,
margin: const EdgeInsets.fromLTRB(32.0, 8.0, 32.0, 16.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
child: Column(
children: <Widget>[
ListTile(
leading: Icon(
Icons.people_outline,
color: Colors.lightGreen,
),
title: Text("Invite to event"),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: () {
},
),
sizedBox,
ListTile(
leading: Icon(
Icons.directions_run,
color: Colors.lightGreen,
),
title: Text("Challange Henri"),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: () {},
),
sizedBox,
ListTile(
leading: Icon(
Icons.phone_iphone,
color: Colors.lightGreen,
),
title: Text("Text/Call Henri"),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: () { },
),
sizedBox,
ListTile(
leading: Icon(
Icons.lock_outline,
color: Colors.lightGreen,
),
title: Text("Delete Friend"),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: () {},
),
],
),
),
const SizedBox(height: 5.0),
Center(
child: Text(
"Friens since 09/20/2019",
style: TextStyle(
fontSize: 15.0,
),
textAlign: TextAlign.center,
),
),
SizedBox(height: 20.0),
Container(
height: 40.0,
child: GestureDetector(
onTap: () {
},
child: Material(
borderRadius: BorderRadius.circular(50.0),
shadowColor: Colors.black,
color: Colors.green,
elevation: 7.0,
child: Center(
child: Text(
'27 mutural friends', //Login Button
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat'),
),
),
),
),
),
],
),
),
],
),
],
),
);
});
}
}
You are getting the error because context is not defined in _showSearch.
You should modify the function definition and add context as a parameter as follows:
void _showSearch(BuildContext context) {
...
And when you are calling, you must pass context of the widget from where you are calling it, as follows:
child: new IconButton(
icon: new Icon(Icons.search),
highlightColor: Colors.pink,
onPressed: () {
_showSearch(context); //here
},
),