Flutter CupertinoPicker UI breaks and children are not displayed properly - flutter

I am quite new to Flutter and was trying to implement the CupertinoPicker Widget.
When I press a button I want to be able to replace the current CupertinoPicker with another one.
Unfortunately when I try this the text from the second UI is quite distorted.
Here are some images to help you understand my issue.
What exactly am I missing here?
Here is my code
Code on Github

Just wrap the Center widget with a Container widget. Here's a screenshot of the app and the code.
Widget _second() {
return Container(
child: Center(
child: CupertinoPicker(
selectionOverlay: null,
onSelectedItemChanged: (value) {},
itemExtent: 30,
children: [
Text("City 1"),
Text("City 2"),
Text("City 3"),
Text("City 4"),
Text("City 5"),
Text("City 6"),
Text("City 7"),
],
),
),
);
}

Related

Google Map is clickable under the SpeedDial overlay in flutter web

I developed a flutter web application that has google map widget as a part of Scaffold body. I use flutter_speed_dial as a floating action button. When I click on SpeedDial, it shows an overlay on whole screen, but the map is still clickable.
I know it is happened because google map use HtmlElementView in web and we have a pointer_interceptor package to prevent triggering map when click on above buttons. But how about the overlays? there is no place to wrap SpeedDial overlay with pointer_interceptor.
Here is my sample code:
Scaffold(
...
body: Column(
children: [
...
SizedBox(
height: 230,
child: GoogleMap(...)),
...
]
),
floatingActionButton: PointerInterceptor(
child: SpeedDial(
...
childPadding: const EdgeInsets.all(5),
spaceBetweenChildren: 1,
isOpenOnStart: false,
children: [
SpeedDialChild(
onTap: () {
...
},
labelWidget: PointerInterceptor(
child: Card(
...
),
),
),
],
),
),
)
I believe you can Solve your problem by using IgnorePointer.
Wrap a widget with IgnorePointer and set it to true.
IgnorePointer(
ignoring: true,
child: Widget _test(),
),
you can take a look at docs here:
https://api.flutter.dev/flutter/widgets/IgnorePointer-class.html

Button within Table within Gridview within Sizedbox or Flex is not clickable dependent on other table rows - Flutter

I am rendering a standard Table inside a GridView, inside a Flex inside a Row. The 2nd row of the table includes a Button.
When the contents of the first row of the table are above a certain size the clickable region of the button begins to cut off, missing entirely over a certain size.
Note: this is using Flutter Web, I have not tested on Mobile/Desktop.
I have created a minimal reproducible example in an attempt to isolate all logic.
Widget _render() {
return Row(mainAxisSize: MainAxisSize.max, children: [
SizedBox(
width: 900,
height: 900,
child: GridView.count(
crossAxisCount: 2,
children: <Widget>[
Table(border: TableBorder.all(), children: <TableRow>[
TableRow(
children: <Widget>[
TableCell(
child: Text(''),
),
TableCell(
child: SizedBox(
height:
440, //The clickable region of the button begins to be cut off around 430, and stops altogether by 450
))
],
),
TableRow(children: <Widget>[
TableCell(
child: Text(""),
),
TableCell(
child: TextButton(
onPressed: () => {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Hi Button"))),
},
child: Text("Hi"))),
])
]),
],
),
),
]);
}
What is causing this effect? I am assuming it is some interaction between the visible container and the Table.
Edit: as suggested by #pskink rendered with debugPaintSizEnabled flag which highlights the problem perfectly. However; how would you fix?

Handle tap in Flutter TableRow

I need to make the TableRow clickable and navigate to other screen but I cannot wrap TableRow with GestureDetector or Inkwell. How can I make the TableRow clickable. I have implemented as follows:
for (int i = 0; i < menuList.length; i++)
TableRow(children: [
SizedBox(
width: 5,
),
Text((i + 1).toString()),
Text(menuList[i].name),
Text(menuList[i].price.toString()),
Text(menuList[i].maxQty.toString()),
menuList[i].status == 0
? Text(
menuList[i].foodStatus,
style: TextStyle(color: Colors.red),
)
: YourListViewItem(
id: menuList[i].id,
index: menuList[i].status,
),
]),
I don't think you can do this,
You can use DataTable instead of Table widget, it will definitely meet your need.
In DataRow there is a property named onSelectChanged, This is
exactly what you want.
Not for the whole row, but for the individual cells in a row you can use TableRowInkWell. TableRowInkWell goes inside a TableRow itself, wrapping a child. Here is the answer, with credit to SoloWofl93: How to use TableRowInkWell inside Table in flutter?
Table(
border: TableBorder.all(),
children: [
TableRow(children: [
// HERE IT IS...
TableRowInkWell(
onTap: (){},
child: Column(children: [
Icon(
Icons.account_box,
size: iconSize,
),
Text('My Account'),
]),
),
Column(children: [
Icon(
Icons.settings,
size: iconSize,
),
Text('Settings')
]),
]),
],
)
It seems impossible to do this.
One thing you can try is adding inkwell to a table row of exactly the same size on top of the original table using a stack widget.

How to have multiple child with their onTaps within GestureDetector?

I have a sign-up page which contains Text like privacy policy, terms and etc and I want that on clicking those text webpage should get open.
I used the GestureDetector for that but the issue is that it contains one child only
But I want all the three texts to be there and should perform Onclick or here onTap.
Any idea?
GestureDetector(
onTap: () => launch(
'https://docs.flutter.io/flutter/services/UrlLauncher- class.html'),
child: Text('Terms of use,',
style: TextStyle(
color: Colors.blueAccent,
fontSize: 18.0,
fontWeight: FontWeight.bold)),
)
expected: all three text with onTap inside GestureDetector.
actual: only one child is there.
You can try creating a Row widget which contains the text you need, that is, privacy policy, terms and etc, as its children. And then wrap the Text widgets with GestureDetector widgets. A code snippet is given below:
Container(
alignment: Alignment.center,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
GestureDetector(
onTap: (){
print("Privacy policy");
},
child: Text("Privacy policy, "),
),
GestureDetector(
onTap: (){
print('Terms');
},
child: Text("Terms, "),
),
GestureDetector(
onTap: (){
print('Contact Us');
},
child: Text("Contact Us"),
),
],
),
),
Outputs:
Hope this helps!!
That's currently not directly supported by Flutter. But you can use RichText for implementing the requirement.
It is similar to Spannable string in Android.

Flutter Stack size to sibling

Is there a way to size a stack child automatically to its largest sibling?
I.e. if I have a Stack with a ListTile and a Container on top, how do I make sure the Container covers the entire ListTile?
Example:
new Stack(children: <Widget>[
new ListTile(
leading: new AssetImage('foo.jpg'),
title: new Text('Bar'),
subtitle: new Text('yipeee'),
isThreeLine: true,
),
new Container(color: Colors.grey, child: new Text('foo'))
],
)
I tried to make it work with Row, Column and Expanded but am running into problems with unbounded constraints.
Is there a way to size the Container (or any other widget such as a GestureDetector) to its largest sibling in the stack?
I had the same issue and finally managed to solve it using this answer:
Inside your Stack, you should wrap your background widget in a Positioned.fill.
return new Stack(
children: <Widget>[
new Positioned.fill(
child: background,
),
foreground,
],
);
-- Mary, https://stackoverflow.com/a/45745479
Applying that to your question results in the following:
Stack(
children: <Widget>[
ListTile(
leading: AssetImage('foo.jpg'),
title: Text('Bar'),
subtitle: Text('yipeee'),
isThreeLine: true,
),
Positioned.fill(
child: Container(color: Colors.grey, child: Text('foo')),
),
],
),