Anroid-layout How can make custom button like this? - android-layout

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,
),
),
),
],
),
),
);
}
}

Related

How to get indent between image and appbar in Flutter app?

Here is the code without body of the widget:
Column(
children: [
Material(
elevation: 0,
child: Image.asset(
i.first,
fit: BoxFit.fitWidth,
),
),
SizedBox(
width: 130,
child: FittedBox(
fit: BoxFit.fitWidth,
child: Padding(
padding: const EdgeInsets.all(30.0),
child: Text(
i.last
),
),
),
),
],
Need to add space between appbar and image.
How can i achieve additional space between image and appbar widgets?
You can use Padding Widget:
body: Padding(
padding: const EdgeInsets.all(8.0),
child: GridView.count(
crossAxisCount: 2,
children: [
...myImageAndCaption.map(
(i) => Column(
mainAxisSize: MainAxisSize.min,
children: [
Material(
elevation: 0,
child: Image.asset(
i.first,
fit: BoxFit.fitWidth,
height: 150,
width: 150,
),
),
SizedBox(
width: 130,
child: FittedBox(
fit: BoxFit.fitWidth,
child: Padding(
padding: const EdgeInsets.all(30.0),
child: Text(
i.last,
style: const TextStyle(
fontSize: 22,
letterSpacing: 1.0,
fontWeight: FontWeight.w600,
color: Colors.black,
),
),
),
),
),
],
),
),
],
),
),

How to solve RangeError (index): Invalid value: Valid value range is empty: 1 in Flutter/Dart

My code is giving me the output what i required but there is one error which i need support to resolve.
RangeError (index): Invalid value: Valid value range is empty: 1
Below is the csv which i am using:
german word,german sentence,english word,english sentence
die Ansage,Hören Sie auf die Ansagen.,announcement,Listen to the announcements.
Here is the code:
I am getting error on line wher i am calling csvTable[index1+1][0],
class _CsvState extends State<Csv> {
#override
Widget build(BuildContext context, ) {
return FutureBuilder<String>(
future: rootBundle.loadString('assets/questions.csv'),
builder: (BuildContext context, AsyncSnapshot<String> snapshot,) {
List<List<dynamic>> csvTable =
CsvToListConverter().convert(snapshot.data);
return Scaffold(
appBar: AppBar(
title: Text("A1 German Vocabulary"),
),
body: new TransformerPageView (
itemCount: csvTable.length-1,
loop: true,
viewportFraction: 0.8,
itemBuilder: (BuildContext context, int index1) {
return new Padding(
padding: new EdgeInsets.all(10.0),
child: new Material(
elevation: 8.0,
textStyle: new TextStyle(color: Colors.white),
borderRadius: new BorderRadius.circular(10.0),
child: new Stack(
fit: StackFit.expand,
children: <Widget>[
new Positioned(
child: new Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Container(
child: new Text(
csvTable[index1+1][0],
style: new TextStyle(
fontSize: 24.0,
color: Colors.black,
),
),
alignment: Alignment.center,
),
SizedBox(height: 20,),
new Container(
child: new Text(
csvTable[index1+1][1],
textAlign:TextAlign.center,
style: new TextStyle(
fontSize: 24.0,
color: Colors.black,
),
),
alignment: Alignment.center,
),
SizedBox(height: 20,),
new Container(
margin: const EdgeInsets.only(left: 10.0, right: 20.0),
child: Divider(
color: Colors.black,
height: 36,
)),
new Container(
child: new Text(
csvTable[index1+1][2],
style: new TextStyle(
fontSize: 24.0,
color: Colors.black,
height: 2
),
),
alignment: Alignment.center,
),
SizedBox(height: 20,),
new Container(
child: new Text(
csvTable[index1+1][3],
textAlign:TextAlign.center,
style: new TextStyle(
fontSize: 24.0,
color: Colors.black,
),
),
alignment: Alignment.center,
),
],
),
left: 10.0,
right: 10.0,
top: 100.0,
)
],
),
),
);
},
// itemCount:811
),
);
});
}
}

"RenderBox was not laid out" text field error in flutter

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'),
),
],
)
],
)
],
),

Flutter text display issue

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.

Flutter How to using text field inside ListTile?

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(),
),
),

Resources