I have a row with a text saying terms of use and a button. I want to show some data but perhaps I'm not using the correct keywords. All I'm getting is how to change a text on button click.
Anyway, what should I do to let the user see the terms of use on button click?
Container(
padding: EdgeInsets.only(top: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
"Terms of Use",
style: TextStyle(
color: Color(0xff18172b),
fontSize: 18,
fontFamily: "Poppins",
fontWeight: FontWeight.w400,
),
),
IconButton(
iconSize: 18,
onPressed: () {},
icon: Icon(Icons.arrow_forward_ios))
],
),
),
you can navigate to another page that hold the Terms or show modal like this :
IconButton(
iconSize: 18,
onPressed: () async {
await showDialog(
barrierColor: Colors.black12.withOpacity(.6),
context: context,
builder: (_) {
return Dialog(
elevation: 0,
backgroundColor: Colors.transparent,
child: Container(
child: Text("TERMS"),
),
);
});
},
icon: Icon(Icons.arrow_forward_ios))
Related
How can I place some buttons to separate between tabs in a sliding up panel? Currently what I am trying to do is place them only when the slider is opened up, ohterwise the button tabs should dissapear. I am trying to controll this behavior with ternary operator and the variable:
PanelState == PanelState.OPEN ?
but it does not work for me. The row dissapear when I close the panel.
SlidingUpPanel(
body: Body()
backdropEnabled: true,
panelSnapping: true,
collapsed: ListTile(
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
InkWell(
onTap: () {
_pcBreedsGrouping.open();
},
child: const Text(
'Breeds',
style: TextStyle(
color: Colors.black,
fontSize: 20,
fontWeight: FontWeight.bold),
),
),
InkWell(
onTap: () {
_pcBreedsGrouping.open();
},
child: const Icon(
Icons.arrow_drop_down,
color: Colors.black,
size: 30,
),
),
],
),
),
minHeight: MediaQuery.of(context).size.height * 0.08,
controller: _pcBreedsGrouping,
defaultPanelState: PanelState.CLOSED,
panel: Positioned(
child: Stack(
children: [
PanelState == PanelState.OPEN
? Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Breeds',
style: TextStyle(
color: Colors.black,
fontSize: 20,
fontWeight: FontWeight.bold),
),
InkWell(
onTap: () => _pcBreedsGrouping.close(),
child: const Icon(
Icons.arrow_drop_up,
color: Colors.black,
size: 30,
),
),
],
)
: Container(),
Visually, the panel is like this right now and I drawed what I am trying in red:
When I close the panel I would like it to be how it is right now, without the buttons, but I do not know how to make them dissapear when is closed:
What I am trying to accomplish:
I'm utilize o Slidable on app Flutter and put as ListTile child.
So far ok.
I'm problem is i would like when I slide it to the left the text keeps appearing on the screen, as shown in the image below.(Red == Title)
At the moment the text is hidden when I swipe, as per the image.(Red == Title)
I saw that when I swipe this attribute changes state Slidable.of(context)?.animation.isCompleted
And I also verified that in my Row title of ListTile, if I line up the title as End, the title will appear msm by swiping.
So I thought, as this Slidable.of(context)?.animation.isCompleted attribute changes state I align my Row to Start or End.
But I couldn't find a way to monitor this attribute, so that when it changes I can rebuild my Row. I tried to put it as Stream but I wasn't successful. Because it looks like it doesn't generate an event, it just changes the value.
I don't know how I could do it, if anyone has any tips...
Code:
#override
Widget build(BuildContext) {
return Slidable(
key: const ValueKey(1),
endActionPane: ActionPane(
motion: const DrawerMotion(),
children: [
SlidableAction(
onPressed: (ctx) => {
Get.to(() => const CredentialOperationScreen(),
arguments:
RouteDetailCredential(itemCredential: itemCredential))
},
backgroundColor: ConstsColors.orangeAccent,
foregroundColor: Colors.white,
icon: Icons.info_outline,
),
SlidableAction(
onPressed: (ctx) => {
Get.to(() => const CredentialOperationScreen(),
arguments:
RouteDeleteCredential(itemCredential: itemCredential))
},
backgroundColor: const Color.fromRGBO(219, 32, 32, 1),
foregroundColor: Colors.white,
icon: Icons.delete_outline,
),
],
),
child: Builder(
builder: (ctx) {
return Container(
child: _listTile(ctx),
decoration: const BoxDecoration(
border: Border(
bottom:
BorderSide(color: ConstsColors.greyColorOpacity))));
},
));
}
Widget _listTile(context) {
return ListTile(
title: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Icon(
itemCredential.icon,
color: Colors.black,
),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Text(
itemCredential.name,
style: const TextStyle(
fontFamily: 'Roboto',
fontSize: 16,
),
),
),
],
),
onTap: () => {
Slidable.of(context)?.animation.isCompleted == true
? Slidable.of(context)?.close()
: Slidable.of(context)?.openEndActionPane()
},
trailing: const Icon(Icons.check_circle_outline, color: Colors.green),
);
}
I use bottomNavigationBar in main page and I have 3 different page.
My screens
final List<Widget> screens = [
findLocation(),
otherPage(),
profilePage(),
];
and my wigdet build like this
return Scaffold(
body: PageStorage(
child: currentScreen,
bucket: bucket,
),
floatingActionButton: showFab?GestureDetector(
onTap: () {
setState(() {
currentScreen =
findLocation(); // if user taps on this location tab will be active
currentTab = 0;
});
},
Find location page like this
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Color(0xFF0B75E0), // background
onPrimary: Colors.white,
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.only(
right: 25.0, left: 15, top: 12, bottom: 10),
child: Text(
'Konum Bul',
textAlign: TextAlign.center,
style: TextStyle(
color: Color.fromRGBO(255, 255, 255, 1),
fontSize: 23,
letterSpacing: 1.5,
fontWeight: FontWeight.w500,
height: 1),
),
),
Icon(
Icons.arrow_forward,
color: Colors.white,
)
],
),
onPressed: () {
Navigator.push(context,
new MaterialPageRoute(builder: (context) => new loginPage()));
},
),
When I click a button on that page while my Find Location page is open, I want a different page to open than the 3 pages in main (I have a 4th login page) but my new loginpage open different place (without bottomnavigatorbar).
I want to open this page in main like the others. I want it to be tapbar underneath. How can I do that.
If you ask about why bottomnavigatorbar not showing up in login page, the answer will be :
Because you do this code in onPressed:
Navigator.push(context,new MaterialPageRoute(builder: (context) => new loginPage()));
And this code will open a new rout.
Try to write this code in onPressed :
setState((){
currentScreen = loginPage();
});
I am using a drawer to create a menu that houses ListTiles for the options. I want to create a popup when the tiles are tapped by the user. Currently, the code displays nothing when the tiles are tapped even though after the showDialog there is a Navigator.pop().
// Drawer that includes the ListTiles in question
Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Text('Smash Tracker'),
),
),
ListTile(
title: Text(
'About',
style: TextStyle(
fontFamily: 'Smash',
fontSize: 15.0,
color: Color.fromRGBO(77, 114, 152, 1.0),
),
),
onTap: () {
// Show PopUp
showDialog(context: context, child:
new AlertDialog(
title: new Text(
'About',
style: TextStyle(fontFamily: "Smash"),
),
content: new Text(
'This is a placeholder. This is a placeholder. This is a placeholder. This is a placeholder.',
style: TextStyle(fontFamily: "Smash"),
),
)
);
// Doesn't run
Navigator.pop(context);
},
),
Here is a demo:
via GIPHY
The other ListTiles have the only have Navigator.pop() inside of their onTap() method.
The dialog isn't showing because you are popping it immediately with the Navigator.pop(context). You can await the Dialog since it returns a Future<T> before popping.
I added a demo using your widget tree as an example:
Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Text('Smash Tracker'),
),
ListTile(
title: Text(
'About',
style: TextStyle(
fontFamily: 'Smash',
fontSize: 15.0,
color: Color.fromRGBO(77, 114, 152, 1.0),
),
),
onTap: () async { // mark the function as async
print('tap');
// Show PopUp
// await the dialog
await showDialog(
context: context,
child: new AlertDialog(
title: new Text(
'About',
style: TextStyle(fontFamily: "Smash"),
),
content: new Text(
'This is a placeholder. This is a placeholder. This is a placeholder. This is a placeholder.',
style: TextStyle(fontFamily: "Smash"),
),
));
// Doesn't run
Navigator.pop(context);
},
),
],
),
),
OUTPUT:
This is my dialog Code
Here is am getting an error of setstate() or MarkerneedsBuild called during the build. this overlay widget cannot be marked as needing to process of building widgets.
When I am trying to call _onAlertOtp widget it will show me this error.in the build method, i've bloc and state when my signup is successful then i have to call alert dialog. but when I am trying to do that it will show me the error. Hope you understand the question please help me.
_onAlertotp(BuildContext context) {
return showDialog<void>(
context: context,
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return AlertDialog(
title: Text('Enter OTP'),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height / 2.7,
width: MediaQuery.of(context).size.width,
alignment: Alignment.center,
child: ListView(
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Text(
'We have Texted and/or Emailed OTP (One Time Pin) to your registered cell phone and/ or email account. Please check and enter OTP below to activate your TUDO account.',
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 15),
textAlign: TextAlign.center,
),
),
SizedBox(
height: 5,
),
Padding(
padding: const EdgeInsets.symmetric(
vertical: 8.0, horizontal: 30),
child: PinCodeTextField(
length: 6, // must be greater than 0
obsecureText: false, //optional, default is false
shape: PinCodeFieldShape
.underline, //optional, default is underline
onDone: (String value) {
setState(() {
passcode = value;
print(value);
});
},
textStyle: TextStyle(
fontWeight: FontWeight
.bold), //optinal, default is TextStyle(fontSize: 18, color: Colors.black, fontWeight: FontWeight.bold)
onErrorCheck: (bool value) {
setState(() {
hasError = value;
});
},
shouldTriggerFucntions:
changeNotifier.stream.asBroadcastStream(),
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 30.0),
child: Text(
hasError
? "*Please fill up all the cells and press VERIFY again"
: "",
style: TextStyle(
color: Colors.red.shade300, fontSize: 12),
),
),
SizedBox(
height: 20,
),
RichText(
textAlign: TextAlign.center,
text: TextSpan(
text: "Didn't receive the code? ",
style:
TextStyle(color: Colors.black54, fontSize: 15),
children: [
TextSpan(
text: " RESEND",
// recognizer: onTapRecognizer,
style: TextStyle(
color: colorStyles["primary"],
fontWeight: FontWeight.bold,
fontSize: 16))
]),
),
SizedBox(
height: 7,
),
Container(
margin: const EdgeInsets.symmetric(
vertical: 16.0, horizontal: 30),
child: ButtonTheme(
height: 50,
child: FlatButton(
onPressed: () async {
/// check the [_onData] fucntion to understand better
changeNotifier.add(Functions.submit);
// at first we will check error on the press of the button.
if (!hasError) {
_onAlertrunnigbusiness(context);
}
},
child: Center(
child: Text(
"VERIFY".toUpperCase(),
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold),
)),
),
),
decoration: BoxDecoration(
color: colorStyles["primary"],
borderRadius: BorderRadius.circular(5),
),
),
],
),
),
],
),
),
actions: <Widget>[
FlatButton(
child: Text('Regret'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
Here Is Another DIalog. which open on first dialog verify button click
_onAlertrunnigbusiness(context) {
return showDialog<void>(
context: context,
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return AlertDialog(
title: Text('Are you running Business?'),
content: Container(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SizedBox(
height: 10,
),
Text(
"TUDO.App aims at Businesses bridging gaps between Business Service Providers and Consumers collaborate on unique technology platform. If you own a business, we strongly recommend, provide your business information to grow your customer base and expand your business services. Any questions? Call us #1-800-888-TUDO"),
SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
FlatButton.icon(
icon: Icon(FontAwesomeIcons.arrowCircleRight),
label: Text('No'),
color: colorStyles["primary"],
textColor: Colors.white,
padding:
EdgeInsets.symmetric(vertical: 10, horizontal: 15),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(7),
),
onPressed: () {
NavigationHelper.navigatetoMainscreen(context);
},
),
SizedBox(height: 10),
FlatButton.icon(
icon: Icon(FontAwesomeIcons.arrowCircleRight),
label: Text('Yes'),
color: colorStyles["primary"],
textColor: Colors.white,
padding:
EdgeInsets.symmetric(vertical: 10, horizontal: 15),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(7),
),
onPressed: () {
NavigationHelper.navigatetoBspsignupcreen(context);
},
),
],
)
],
),
),
actions: <Widget>[
FlatButton(
child: Text('Close'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
And Here i am calling my dialog
#override
Widget build(BuildContext context) {
return BlocListener<SignupBloc, SignupState>(
bloc: widget._signupBloc,
listener: (
BuildContext context,
SignupState currentState,
) {
if (currentState is InSignupState) {
_countries = currentState.countries.countries;
return Container(child: content(_signupBloc, context, _countries));
}
if (currentState is SignupButtonClickedEvent) {
print('SignupButtonClickedEvent clicked');
return Container();
}
if (currentState is SignupSuccessState) {
print(
' You are awesome. you have successfully registered without confirmation');
print(currentState.signupUser.toJson());
print("Hey Otp Is opned");
if (!_isError) {
return _onAlertotp(context);
}
// NavigationHelper.navigatetoMainscreen(context);
_isLoading = false;
showAlertBox = true;
return Container(
child: content(_signupBloc, context, _countries),
);
}
if (currentState is SignupVerficationOtp) {
print('signup verficitaion otp button clicked');
return Container();
}
return Container(child: content(_signupBloc, context, _countries));
},
);
}
}
try using below code to display an alert dialog
in place of return _onAlertotp(context);
WidgetsBinding.instance.addPostFrameCallback((_) {
// show alert dialog here
_onAlertotp(context);
});
You should use a BlocListener at the root of your build method to handle events that do not return a widget (in your case the showDialog method)
Your if (currentState is SignupSuccessState) { part would be in the BlocListener and not in the BlocBuilder