flutter hero widget not working when going to new page - flutter

i am currently using the hero widget for flutter. my issue is that the hero is only working when i go from profile screen to chat screen and not from chat screen to profile screen. the tags are the same but i just cannot wrap my head around why is it not working. tia for all inputs
chat screen
class _AppBarTitle extends StatelessWidget {
const _AppBarTitle({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
final channel = StreamChannel.of(context).channel;
return Row(
children: [
Hero(
tag: 'community-profile-picture',
child: Padding(
padding: const EdgeInsets.only(bottom: 4),
child: Avatar.medium(
url: Helpers.randomPictureUrl(), // can be a random image url
onTap: () {
Navigator.of(context).push(
PersonalDevelopmentProfileScreen.routeWithChannel(
channel));
}),
),
),
const SizedBox(
width: 16,
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
Helpers.getChannelName(channel, context.currentUser!),
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 16,
),
),
const SizedBox(height: 2),
],
)),
Padding(
padding: const EdgeInsets.all(8),
child: IconBackground(
icon: CupertinoIcons.info_circle,
onTap: () => showDialog<String>(
context: context,
builder: (BuildContext context) => AlertDialog(
title: Center(
child: Text(
'About ${Helpers.getChannelName(channel, context.currentUser!)}'),
),
content: Text(
'${Helpers.getChannelName(channel, context.currentUser!)} Description'),
actions: <Widget>[
TextButton(
style: TextButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0)),
primary: AppColors.accent),
onPressed: () => Navigator.pop(context, 'OK'),
child: const Text('OK',
style: TextStyle(color: AppColors.secondary)),
),
],
),
),
))
],
);
}
}
scaffold for chat screen
return Scaffold(
appBar: AppBar(
leadingWidth: 54,
leading: Align(
alignment: Alignment.centerRight,
child: IconBackground(
icon: CupertinoIcons.chevron_back,
onTap: () => Navigator.of(context).push(CustomPageRoute(
child: const HomeScreen(), direction: AxisDirection.right)),
),
),
title: const _AppBarTitle(),
),
profile screen
class _AppBarTitle extends StatelessWidget {
const _AppBarTitle({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Members Of Community',
style: GoogleFonts.lato(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.black)),
const SizedBox(height: 2),
],
)),
const SizedBox(
width: 16,
),
Hero(
tag: 'community-profile-picture',
child: Padding(
padding: const EdgeInsets.only(bottom: 4),
child: Avatar.medium(
url: Helpers.randomPictureUrl(), // can be a random image url
onTap: () => Navigator.of(context).pop()),
),
),
],
);
}
}
scaffold for profile screen
return Scaffold(
appBar: AppBar(
leadingWidth: 54,
leading: Align(
alignment: Alignment.centerRight,
child: IconBackground(
icon: CupertinoIcons.chevron_back,
onTap: () => Navigator.of(context).pop()),
),
title: const _AppBarTitle(),
),
avatar
class Avatar extends StatelessWidget {
const Avatar({
Key? key,
this.url,
required this.radius,
this.onTap,
}) : super(key: key);
const Avatar.small({
Key? key,
this.url,
this.onTap,
}) : radius = 18,
super(key: key);
const Avatar.medium({
Key? key,
this.url,
this.onTap,
}) : radius = 26,
super(key: key);
const Avatar.large({
Key? key,
this.url,
this.onTap,
}) : radius = 34,
super(key: key);
final double radius;
final String? url;
final VoidCallback? onTap;
#override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
child: _avatar(context),
);
}
Widget _avatar(BuildContext context) {
if (url != null) {
return CircleAvatar(
radius: radius,
backgroundImage: CachedNetworkImageProvider(url!),
backgroundColor: Theme.of(context).cardColor,
);
} else {
return CircleAvatar(
radius: radius,
backgroundColor: Theme.of(context).cardColor,
child: Center(
child: Text(
'?',
style: TextStyle(fontSize: radius),
),
),
);
}
}
}

Provide hero top level on second widget and follow this pattern,
chat screen
class _AppBarTitle extends StatelessWidget {
const _AppBarTitle({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: row(context),
),
);
}
Row row(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Hero(
tag: 'community-profile-picture',
child: Padding(
padding: const EdgeInsets.only(bottom: 4),
child: GestureDetector(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => _2AppBarTitle(),
),
);
},
child: Material(
child: Container(
height: 100,
width: 100,
color: Colors.green,
child: Text("tap")),
),
),
),
),
],
);
}
}
profile screen
class _2AppBarTitle extends StatelessWidget {
const _2AppBarTitle({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Hero(
tag: 'community-profile-picture',
child: Scaffold(
body: Padding(
padding: const EdgeInsets.only(bottom: 4),
child: GestureDetector(
onTap: () => Navigator.of(context).pop(),
child: Text("pop"),
),
),
),
);
}
}

Related

Why do not work the onTap in gesturedetector?

`
class SearchOffScreen extends StatelessWidget {
const SearchOffScreen({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return DefaultLayout(
child: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Column(
children: [
const SizedBox(height: 200.0,),
InkWell(
child: IgnorePointer(
child: MainSearchTextFormField(),
),
onTap: () {
print("call");
},
),
]
)
),
),
);
}
}
`
I don't know why the MainSearchTextFormField is not working when I click the MainSearchTextFormField. I hope the SearchOffScreen switches the SearchOnScreen when I click the MainSearchTextFormField.
Please help me.
I hope the SearchOffScreen will be switched the SearchOnScreen when I clicked the MainSearchTextFormField. Bit it didn't.
// this is search_on_screen
class SearchOnScreen extends StatelessWidget {
const SearchOnScreen ({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return DefaultLayout(
child: SafeArea(
top: true,
bottom: false,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 0.0),
child: Column(
children: [
CupertinoSearchTextField(
suffixInsets: EdgeInsets.only(right: 16),ts.only(left: 16),
padding: EdgeInsets.only(left: 15,top: 15, bottom: 15),
decoration: BoxDecoration(
border: Border(bottom: BorderSide(width: 0.5, color: Color(0xff868686)))
),
),
],
),
),
),
);
}
}
// This is search_off_screen
class SearchOffScreen extends StatelessWidget {
const SearchOffScreen({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return DefaultLayout(
child: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: GestureDetector(
onTap: (){
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context){
return SearchOnScreen();
}
),
);
},
child: Container(// <-- add this
child: Column(
children: [
const SizedBox(height: 200.0,),
IgnorePointer( // <-- add this
child: MainSearchTextFormField(),
)
], //children
),
),
)
),
),
);
}
}
// This is dart.main
void main() {
runApp(
_App(),
);
}
class _App extends StatelessWidget {
const _App({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
fontFamily: 'NotoSans',
),
debugShowCheckedModeBanner: false,
home: SearchOffScreen(),
);
}
}
Because the textfield has pointer to its self you need to disable that in order GestureDetector tap work, so wrap your MainSearchTextFormField with IgnorePointer and then replace GestureDetector with InkWell:
child: Column(
children: [
const SizedBox(height: 200.0,),
InkWell(
child: IgnorePointer(
child: MainSearchTextFormField(),
),
onTap: (){
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context){
return SearchOnScreen();
}
),
);
},
),
]
)

Flutter Elevated Button Hover Color

When I use the elevated button class inside the home page, its background color changes when hovering over it (because I am using 'MaterialStateProperty'):
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.blue[50],
body: Center(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
ElevatedButton( // <----
style: ButtonStyle(
foregroundColor: MaterialStateProperty.all(Colors.black),
backgroundColor: MaterialStateProperty.all(Colors.blue[200]),
),
onPressed: myFunction,
child: Text("Click Me", style: TextStyle(fontSize: 20)),
),
],
),
),
),
);
}
But when I use my own class that return an elevated button, its background Color doesn't change when hovering over it:
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.blue[50],
body: Center(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.center
children: [
ButtonWidget("Click Me", myFunction, fontSize: 20) // <---- My own Class
),
],
),
),
),
);
}
My ButtonWidget Class:
class ButtonWidget extends StatefulWidget {
const ButtonWidget(
this.text,
this.command, {
this.padding = const EdgeInsets.all(10.0),
this.fontSize = 14.0,
Key? key,
}) : super(key: key);
final String text;
final Function command;
final EdgeInsets padding;
final double fontSize;
#override
State<ButtonWidget> createState() => _ButtonWidgetState();
}
class _ButtonWidgetState extends State<Button> {
#override
Widget build(BuildContext context) {
return Padding(
padding: widget.padding,
child: ElevatedButton(
style: ButtonStyle(
foregroundColor: MaterialStateProperty.all(Colors.black),
backgroundColor: MaterialStateProperty.all(Colors.blue[200]),
),
onPressed: widget.command(),
child: Text(widget.text, style: TextStyle(fontSize: widget.fontSize)),
),
);
}
}
Why is this hapenning?
For using onHover you need to call it, but in your custom ButtonWidget you use wrong action, change :
onPressed: widget.command(),
to:
onHover: (value) { },
onPressed: widget.command(),
Note: for making onHover work, you should call empty onPressed too.

How do I pass a variable to a child widget?

I am passing a string value `final String userLogin; from another file via Route.
class AutfPasswordWidget extends StatefulWidget {
final String userLogin;
AutfPasswordWidget({Key? key, required this.userLogin}) : super(key: key);
#override
State<AutfPasswordWidget> createState() => _AutfPasswordWidgetState();
}
final iconColor = const Color(0xFF2787F5);
class _AutfPasswordWidgetState extends State<AutfPasswordWidget> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
leading: BackButton(
color: Colors.grey
),
elevation: 0,
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min, // Иконка по центру несмотря на кнопку назад
children: [
Icon(Icons.telegram_sharp, color: iconColor),
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 2, vertical: 2)),
Text('ID', style: TextStyle(color: Colors.black, fontSize: 18)),
],
)),
body: Padding(
padding: const EdgeInsets.all(20),
child: ListView(
children: [
_MainInfoWidget(),
],
),
),
);
}
}
But I need to use the resulting value in another widget 'Use password for $userLogin' , located under it.
class _MainInfoWidget extends StatelessWidget {
const _MainInfoWidget({Key? key,}) : super(key: key);
#override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(
Icons.telegram_sharp,
color: iconColor,
size: 64,
),
SizedBox(height: 20),
Text('Password',
style: AppAuthTitleStyle.LinkButton),
SizedBox(height: 20),
Text(
'Use password for $userLogin' ,
style: AppDescribeTittleStyle.LinkButton,
textAlign: TextAlign.center,
),
],
),
);
}
}
How do I pass the value to the desired widget ?
You can pass userLogin to _mainInfoWidget() by accesing the parent variable using widget.userLogin:
_MainInfoWidget(userLogin: widget.userLogin),
Complete example:
class AutfPasswordWidget extends StatefulWidget {
final String userLogin;
AutfPasswordWidget({Key? key, required this.userLogin}) : super(key: key);
#override
State<AutfPasswordWidget> createState() => _AutfPasswordWidgetState();
}
final iconColor = const Color(0xFF2787F5);
class _AutfPasswordWidgetState extends State<AutfPasswordWidget> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
leading: BackButton(color: Colors.grey),
elevation: 0,
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize:
MainAxisSize.min, // Иконка по центру несмотря на кнопку назад
children: [
Icon(Icons.telegram_sharp, color: iconColor),
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 2, vertical: 2)),
Text('ID', style: TextStyle(color: Colors.black, fontSize: 18)),
],
)),
body: Padding(
padding: const EdgeInsets.all(20),
child: ListView(
children: [
_MainInfoWidget(userLogin: widget.userLogin),
],
),
),
);
}
}
class _MainInfoWidget extends StatelessWidget {
final String? userLogin;
const _MainInfoWidget({
this.userLogin,
Key? key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(
Icons.telegram_sharp,
color: iconColor,
size: 64,
),
SizedBox(height: 20),
Text(
'Password',
),
SizedBox(height: 20),
Text(
'Use password for $userLogin',
// style: AppDescribeTittleStyle.LinkButton,
textAlign: TextAlign.center,
),
],
),
);
}
}

How can I create a ListView correctly?

I'm not able to create a Listview in Flutter because of when I create a Listview of widgets the screen stays empty, it's something like that 1
This is the Code that I wrote and returns a list view:
import 'package:dietapp/pages/homepage.dart';
import 'package:dietapp/pages/list.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:dietapp/pages/profile.dart';
import 'package:dietapp/pages/createReg.dart';
import 'package:percent_indicator/percent_indicator.dart';
void main() {}
class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
const SafeArea(child: TopBar()),
const Align(
alignment: Alignment.topLeft,
child: Padding(
padding: EdgeInsets.only(left: 25, bottom: 20),
child: Text('Seguiment Diari', style: TextStyle(fontSize: 20)),
)),
Align(alignment: Alignment.center, child: TypesListView()),
],
),
floatingActionButton: FloatingActionButton.extended(
onPressed: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => const CreateReg()));
},
label: const Text('Crear'),
icon: const Icon(Icons.add),
),
);
}
}
class TopBar extends StatelessWidget {
const TopBar({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(25.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Dietapp",
style: TextStyle(
color: Colors.black, fontSize: 30, fontWeight: FontWeight.bold),
),
],
),
);
}
}
class TotalLabel extends StatefulWidget {
final String typeOf;
final String subtitle;
final Function() onPressed;
final double fillBar;
const TotalLabel(
{required this.typeOf,
required this.subtitle,
required this.onPressed,
required this.fillBar,
Key? key})
: super(key: key);
#override
State<TotalLabel> createState() => _TotalLabelState();
}
class _TotalLabelState extends State<TotalLabel> {
Color getColor(double fillBar) {
if (fillBar < 0.5) {
return Colors.orange;
} else {
return Colors.green;
}
}
#override
Widget build(BuildContext context) {
return GestureDetector(
onTap: widget.onPressed,
child: Container(
width: 350,
height: 125,
padding: const EdgeInsets.all(15.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12.5),
boxShadow: [
BoxShadow(
offset: const Offset(10, 20),
blurRadius: 10,
spreadRadius: 0,
color: Colors.grey.withOpacity(.05)),
],
),
child: Column(
children: [
Text(widget.typeOf,
textAlign: TextAlign.center,
style: const TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 20,
)),
const SizedBox(
height: 5,
),
Text(
widget.subtitle,
textAlign: TextAlign.center,
style: const TextStyle(
color: Colors.grey,
fontWeight: FontWeight.normal,
fontSize: 12),
),
const SizedBox(
height: 10,
),
const Spacer(),
LinearPercentIndicator(
width: 300,
lineHeight: 10,
barRadius: const Radius.circular(50),
backgroundColor: Colors.black12,
progressColor: getColor(widget.fillBar),
percent: widget.fillBar,
),
const Spacer()
],
),
),
);
}
}
class TypesListView extends StatelessWidget {
const TypesListView({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return ListView(
padding: const EdgeInsets.all(8),
children: <Widget>[
TotalLabel(
typeOf: 'Proteines',
subtitle: 'Range',
onPressed: () {},
fillBar: 0.2),
],
);
}
}
When I run the code, the error view is the following:
I have also tried to use a Stateless widget returning a list view but didn't worked.
Thanks you so much :)
The following is an example of how to use a ListView. Note that I created a MaterialApp since ListView is a Material Widget. You can replace ListViewExample with your own Widget containing a ListView.
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'ListView Example',
home: ListViewExample(),
);
}
}
class ListViewExample extends StatelessWidget {
#override
Widget build(BuildContext context) {
return ListView(
padding: const EdgeInsets.all(8),
children: <Widget>[
Text('Text Widget 1'),
Text('Text Widget 2'),
Text('Text Widget 3'),
],
);
}
}
ListView.builder(
itemCount: 5
itemBuilder: (context, index) {
return Card(
child: Padding(
padding: const EdgeInsets.all(10),
child: Text("Some text $index")
),
);
}),
More about listview

Showing widgets by taping on different options in flutter?

I am using flutter. I want to show different widgets when I tap on different options. On selecting option A, the option A widget is shown. On selecting option B, the option B widget is shown below the options bar and vice versa (like a tab bar). The code is attached below. I am glad if someone helps. ..
import 'package:flutter/material.dart';
class Cards extends StatefulWidget {
const Cards({Key? key}) : super(key: key);
#override
State<Cards> createState() => _CardsState();
}
class _CardsState extends State<Cards> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Cards"),
),
body: Padding(
padding: const EdgeInsets.only(top: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
optionCards("A", "assets/icons/recycle.png", context, "1"),
optionCards("B", "assets/icons/tools.png", context, "2"),
optionCards("C", "assets/icons/file.png", context, "3"),
],
),
),
);
}
Widget optionCards(
String text, String assetImage, BuildContext context, String cardId) {
return Container(
width: 100,
height: 100,
decoration: ShapeDecoration(
color: Colors.grey,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(5),
),
),
),
child: SingleChildScrollView(
child: Column(
children: [
const Padding(
padding: EdgeInsets.only(top: 13),
child: IconButton(
onPressed: null,
icon: Icon(Icons.file_copy),
),
),
Text(
text,
style: const TextStyle(
fontSize: 14,
fontFamily: 'CeraPro',
color: Color.fromRGBO(0, 0, 0, 1),
),
),
],
),
),
);
}
Widget optiona() {
return Container();
}
Widget optionb() {
return Container();
}
Widget optionc() {
return Container();
}
}
class Cards extends StatefulWidget {
const Cards({Key? key}) : super(key: key);
#override
State<Cards> createState() => _CardsState();
}
class _CardsState extends State<Cards> {
Widget? selectedOption;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Cards"),
),
body: Padding(
padding: const EdgeInsets.only(top: 20),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
InkWell(
onTap: (){
setState(() {
selectedOption = optiona();
});
},
child: optionCards("A", "assets/icons/recycle.png", context, "1")
),
InkWell(
onTap: (){
setState(() {
selectedOption = optionb();
});
},
child: optionCards("B", "assets/icons/tools.png", context, "2")
),
InkWell(
onTap: (){
setState(() {
selectedOption = optionc();
});
},
child: optionCards("C", "assets/icons/file.png", context, "3")
),
],
),
// options
if(selectedOption != null) selectedOption!
],
),
),
);
}
Widget optionCards(
String text, String assetImage, BuildContext context, String cardId) {
return Container(
width: 100,
height: 100,
decoration: const ShapeDecoration(
color: Colors.grey,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(5),
),
),
),
child: SingleChildScrollView(
child: Column(
children: [
const Padding(
padding: EdgeInsets.only(top: 13),
child: IconButton(
onPressed: null,
icon: Icon(Icons.file_copy),
),
),
Text(
text,
style: const TextStyle(
fontSize: 14,
fontFamily: 'CeraPro',
color: Color.fromRGBO(0, 0, 0, 1),
),
),
],
),
),
);
}
Widget optiona() {
return Container();
}
Widget optionb() {
return Container();
}
Widget optionc() {
return Container();
}
}
You can use the Visibility widget to wrap the widgets which you want to hide or show and keep track of which one to show through a variable. Then you can set the visible property accordingly.
import 'package:flutter/material.dart';
class Cards extends StatefulWidget {
const Cards({Key? key}) : super(key: key);
#override
State<Cards> createState() => _CardsState();
}
class _CardsState extends State<Cards> {
var showOption = "";
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Cards"),
),
body: Padding(
padding: const EdgeInsets.only(top: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
optionCards("A", "assets/icons/recycle.png", context, "1"),
optionCards("B", "assets/icons/tools.png", context, "2"),
optionCards("C", "assets/icons/file.png", context, "3"),
],
),
),
);
}
Widget optionCards(
String text, String assetImage, BuildContext context, String cardId) {
return Container(
width: 100,
height: 100,
decoration: ShapeDecoration(
color: Colors.grey,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(5),
),
),
),
child: SingleChildScrollView(
child: Column(
children: [
const Padding(
padding: EdgeInsets.only(top: 13),
child: IconButton(
onPressed: null,
icon: Icon(Icons.file_copy),
),
),
Text(
text,
style: const TextStyle(
fontSize: 14,
fontFamily: 'CeraPro',
color: Color.fromRGBO(0, 0, 0, 1),
),
),
],
),
),
);
}
Widget optiona() {
return Visibility(visible: showOption == "A", child: Container());
}
Widget optionb() {
return Visibility(visible: showOption == "B", child: Container());
}
Widget optionc() {
return Visibility(visible: showOption == "C", child: Container());
}
Now you can change the showOption variable whenever you want to show another option.