I want to know how to make a list view inside a drawer shows from the other side, and I'm confused why it gave me the default apperance like this:
drawer: Drawer(
child: Container(
alignment: Alignment.centerLeft,
child: ListView(
children: <Widget>[
ListTile(
trailing: FlatButton.icon(
onPressed: _onClicked,
icon: Icon(Icons.home),
label: Text('Home')),
),
ListTile(
trailing: FlatButton.icon(
onPressed: _onClicked,
icon: Icon(Icons.favorite),
label: Text('Favorite')),
),
ListTile(
trailing: FlatButton.icon(
onPressed: _onClicked,
icon: Icon(Icons.share),
label: Text('Share_app')),
),
ListTile(
trailing: FlatButton.icon(
onPressed: _onClicked,
icon: Icon(Icons.info),
label: Text('About Us')),
),
ListTile(
trailing: FlatButton.icon(
onPressed: _onClicked,
icon: Icon(Icons.settings),
label: Text('Settings')),
),
],
),
)));
}
}
thank you for your help
Is there a reason why you want to put your Icon in the trailing position, and also put a label to it? If you want to simply display a ListView of ListTile children, you can simply do this:
ListView(
children: [
ListTile(
leading: Icon(Icons.home),
title: Text('Home'),
onTap: // onTap callback
),
...
],
),
Or am I misunderstanding the question?
Related
I'm trying to put a textfield, the error does not appear, but I think I'm getting a logical error.
I guess sizing is required. But I couldn't understand where to specify.
And the screen is blank.
I don't know if I could explain it properly because my English is not good.
child: Row(
children: <Widget>[
Column(
children: <Widget>[
TextFormField(
decoration: const InputDecoration(
hintText: 'Enter your email',
),
validator: (String? value) {
if (value == null || value.isEmpty) {
return 'Please enter some text';
}
return null;
},
),
const Padding(
padding: EdgeInsets.symmetric(vertical: 16.0),
child: ElevatedButton(
onPressed: null,
child: Text('Submit'),
),
),
],
),
Column(
children: <Widget>[
TextButton(
style: TextButton.styleFrom(
textStyle: const TextStyle(fontSize: 20),
backgroundColor: Colors.blueAccent,
),
onPressed: null,
child: const Text('Button'),
),
Row(
children: <Widget>[
TextButton(
style: TextButton.styleFrom(
textStyle: const TextStyle(fontSize: 20),
backgroundColor: Colors.blueAccent,
),
onPressed: null,
child: const Text('Button2'),
),
],
)
],
)
],
),
),`
Somehow you have to tell Flutter how should it size the two columns in the row. One of the possible solutions is to wrap the first column in an Expanded widget. As a result the second column will be drawn, its size is determined by the text sizes of Button and Button2). And then the first column will occupy all the remaining space, that's what Expanded means. Code:
Row(
children: <Widget>[
Expanded( // <--- this is added, the rest is unchanged
child: Column(
children: <Widget>[
TextFormField(
decoration: const InputDecoration(
hintText: 'Enter your email',
),
validator: (String? value) {
if (value == null || value.isEmpty) {
return 'Please enter some text';
}
return null;
},
),
const Padding(
padding: EdgeInsets.symmetric(vertical: 16.0),
child: ElevatedButton(
onPressed: null,
child: Text('Submit'),
),
),
],
),
),
Column(
children: <Widget>[
TextButton(
style: TextButton.styleFrom(
textStyle: const TextStyle(fontSize: 20),
backgroundColor: Colors.blueAccent,
),
onPressed: null,
child: const Text('Button'),
),
Row(
children: <Widget>[
TextButton(
style: TextButton.styleFrom(
textStyle: const TextStyle(fontSize: 20),
backgroundColor: Colors.blueAccent,
),
onPressed: null,
child: const Text('Button2'),
),
],
)
],
)
],
),
those three things are clickable buttons, I don't know how to make it....
enter image description here
return Scaffold(
backgroundColor: Colors.grey[200],
body: Padding(
padding: const EdgeInsets.all(28.0),
child: Column(
children: [
Card(
child: new InkWell(
onTap: () {},
child: Container(
child: ListTile(
title: Text(
"Bignners Level Lessons",
),
subtitle: Text("write your text"),
),
height: 100.0,
),
),
),
Card(
child: new InkWell(
onTap: () {},
child: Container(
child: ListTile(
title: Text(
"Bignners Level Lessons",
),
subtitle: Text("write your text"),
),
height: 100.0,
),
),
),
Card(
child: new InkWell(
onTap: () {},
child: Container(
child: ListTile(
title: Text(
"Bignners Level Lessons",
),
subtitle: Text("write your text"),
),
height: 100.0,
),
),
),
],
),
),
);
}
}
how to change icon colour on PopupMenuButton, I have used Theme with iconTheme but it doesn't affect the icon on CheckedPopupMenuItem nor PopupMenuItem.
Scaffold(
backgroundColor: Colors.transparent,
appBar: AppBar(
elevation: 0.0,
backgroundColor: Colors.transparent,
actions: <Widget>[
Theme(
data: Theme.of(context).copyWith(
cardColor: Colors.indigo,
iconTheme: IconThemeData(color: Colors.white),
),
child: ListTileTheme(
iconColor: Colors.white,
child: PopupMenuButton<String>(
onSelected: _showCheckedMenuSelections,
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
CheckedPopupMenuItem<String>(
value: _checkedValue1,
checked: _showRoles,
child: Text(_checkedValue1, style: Theme.of(context).textTheme.body1),
),
const PopupMenuDivider(),
PopupMenuItem<String>(
value: 'Get Link',
child: ListTile(
leading: Icon(Icons.phonelink),
title: Text('Get link', style: Theme.of(context).textTheme.body1),
),
),
],
),
),
),
],
),
The result is look like this :
Just do this
appBar: AppBar(
iconTheme: IconThemeData(color: Colors.white, size: 10.0),
elevation: 4.0,
backgroundColor: Colors.black,
)
You can wrap the Icon widget inside IconButton which provides color property to change the icon color. Sample code below:
value: 'Get Link',
child: ListTile(
leading: IconButton(
icon: Icon(Icons.phonelink,
color: Colors.blue,),
onPressed: () {},
),
title: Text('Get link', style: Theme.of(context).textTheme.body1),
),
Am writing a very basic app that just displays numbers on the screen and you can increase and decrease the value of this number with some buttons.
Works fine, except for some reason the text display often goes nuts. I'll show you what I mean:
The above text is trying to display a value of 20, but it is struggling for some reason, as you can see.
This only appears to be happening with double-digit or higher values. My code:
class _SinglePlayerModeParentState extends State<SinglePlayerMode> {
#override
void initState() {
super.initState();
SystemChrome.setEnabledSystemUIOverlays([]);
SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft,]);
}
#override
Widget build(BuildContext context) {
Widget numberDisplay = GestureDetector(
onTap: () {
print("GestureDetector");
_incrementBy1();
},
child: Center(child: Text(_numberValue.toString(),
style: TextStyle(
fontSize: 200.0,
color: Colors.white,
),
),
),
);
This code was already displaying these text issues before I rearranged the code to include the following as well:
Widget buttonRow() {
return Row(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 40.0, right: 20.0),
child: FloatingActionButton(
heroTag: null,
onPressed: _numberValueMinus5,
child: Text('-5'),
),
),
Padding(
padding: EdgeInsets.only(left: 20.0, right: 40.0),
child: FloatingActionButton(
heroTag: null,
onPressed: _numberValueMinus1,
child: Text('-1'),
),
),
],
),
Row(
children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 40.0, right: 20.0),
child: FloatingActionButton(
heroTag: null,
onPressed: _numberValuePlus1,
child: Text('+1'),
),
),
Padding(
padding: EdgeInsets.only(left: 20.0, right: 40.0),
child: FloatingActionButton(
heroTag: null,
onPressed: _numberValuePlus5,
child: Text('+5'),
),
),
],
),
],
);
}
return MaterialApp(
title: 'Bean Counter',
home: Scaffold(
backgroundColor: Colors.blueAccent,
body: Column(
children: [
Padding(
padding: EdgeInsets.only(top: 90.0, bottom: 40.0),
child: numberDisplay,
),
buttonRow(),
],
),
),
);
}
Not sure what I can do differently here, it's just text!
Any thoughts?
Edit: Testing the FittedBox solution.
#override
Widget build(BuildContext context) {
Widget numberDisplay = GestureDetector(
onTap: () {
print("GestureDetector");
_incrementBy1();
},
child: Center(
child: FittedBox(
fit: BoxFit.scaleDown,
child: Text(_numberValue.toString(),
style: TextStyle(
fontSize: 200.0,
color: Colors.white,
),
),
),
),
);
}
Results: this is trying to display the number 30:
As you can see, it still isn't displaying properly. I also tried BoxFit.contain, same issue. Information obtained from this reference: https://docs.flutter.io/flutter/painting/BoxFit-class.html
Any other ideas guys? Or did I implement FittedBox incorrectly?
Edit: Tried with AutoSizeText, as recommended below. Code:
#override
Widget build(BuildContext context) {
Widget scoreText = GestureDetector(
onTap: () {
print("GestureDetector");
_incrementBy1();
},
child: Center(
child: AutoSizeText(_numberValue.toString(),
style: TextStyle(
fontSize: 200.0,
color: Colors.white,
),
),
),
);
Results:
Argh! Displaying text on a clear screen. Level: difficult.
I wanna implement a ListTile which in the tailing is a textfield, this is something like iOS static tableview, so that users can click it and directly edit text.
How to do this in Flutter anyway?
For the future people may also have this trouble, here is the solution:
new ListTile(
title: Text('签名'),
trailing: new Container(
width: 150.0,
child: new Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
new Expanded(
flex: 3,
child: new TextField(
textAlign: TextAlign.end,
decoration:
new InputDecoration.collapsed(hintText: '$userAddr'),
),
),
new Expanded(
child: new IconButton(
icon: new Icon(Icons.chevron_right),
color: Colors.black26,
onPressed: () {},
),
)
],
),
),
),
Always using a Expand for textfiled.
Right now, on V1.12 of flutter, you can put a Row in the title and populate it
ListTile(
title: Row(
children: <Widget>[
Expanded(
child: Text('签名')
),
Expanded(
child: TextField(
// your TextField's Content
),
),
],
),
trailing: IconButton(
icon: new Icon(Icons.chevron_right),
color: Colors.black26,
onPressed: () {},
)
),
Try the following code:
ListTile(
title: Text("Price"),
trailing: SizedBox(
width: MediaQuery.of(context).size.width * 0.2,
child: TextField(),
),
),