Related
What am I doing wrong? I can't get the border radius of my card to change. The elevation isn't working either. I'm new at this. What do I need to change? Is it because it's in ListView? I'm confused. If you need for information, just ask. Sorry it wants me to write more... too much code?
class Home extends StatelessWidget {
#override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
child: Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(85),
child: AppBar(
backgroundColor: Color(),
bottom: TabBar(
tabs: <Widget>[
Tab(icon: Icon(Icons.people), text: (''),),
Tab(icon: Icon(Icons.person), text: (''),),
Tab(icon: Icon(Icons.circle), text: (''),),
],
),
),
),
body: ListView(
children: <Widget>[
Card(
margin: EdgeInsets.all(10),
elevation: 8.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24),
),
child: Container(
color: Colors.white,
height: 120,
child: Column(
children: <Widget>[
ListTile(
leading: CircleAvatar(backgroundImage:
NetworkImage(''),backgroundColor: Color(),),
title: Text('', style: TextStyle(color: Color ()),
subtitle: Text(
'', style: TextStyle(color: Color()),),),
Divider(
height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Row(
children: <Widget>[
Icon(Icons.add, color: Color()),
SizedBox(width: 8.0),
Text('', style: TextStyle(color: Color()),
),
],
),
Row(
children: <Widget>[
Icon(Icons.comment, color: Color()),
SizedBox(width: 8.0),
Text('', style: TextStyle(color: Color())),
],
),
Row(
children: <Widget>[
Icon(Icons.bookmark, color: Color()),
SizedBox(width: 8.0),
Text('', style: TextStyle(color: Color()),),
],
),
],
),
SizedBox(height: 12.0,),
I believe the problem is caused by the child container in the card widget. The container is overlapping over the cards borders so it covers the border radius and the elevation. Try putting the container as the parent of the card and see it that helps. Additionally,you could set the containers decorations property to have the same border radius as the card so it does not overlap.
I am trying to display list of titles and subtitles in scrollview but the scrollview is not working. I am getting this error:
RenderBox was not laid out: RenderRepaintBoundary#d93c1 relayoutBoundary=up4 NEEDS-PAINT
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1940 pos 12: 'hasSize'
Full code of my dart file:
//import 'package:flappy_search_bar/flappy_search_bar.dart';
import 'package:flappy_search_bar/flappy_search_bar.dart';
import 'package:flappy_search_bar/search_bar_style.dart';
import 'package:flutter/material.dart';
import 'body.dart';
class DefinationBody extends StatelessWidget {
const DefinationBody({
Key key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
centerTitle: true,
leading: Padding(
padding: EdgeInsets.only(left: 12),
child: IconButton(
icon: Icon(Icons.arrow_back, color: Colors.black),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (context) => BusinessBody()),
),
),
),
title: Text(
"Definations",
style: TextStyle(
color: Colors.orange[900],
),
),
),
//backgroundColor: Colors.yellow,
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/main_bottom.png"),
alignment: Alignment.bottomCenter,
fit: BoxFit.cover,
),
),
child: MyCardWidget(),
),
),
);
}
}
/// This is the stateless widget that the main application instantiates.
class MyCardWidget extends StatelessWidget {
MyCardWidget({Key key}) : super(key: key);
//final ScrollController _scrollController = ScrollController();
#override
Widget build(BuildContext context) {
return Center(
child: Column(
children: [
Container(
alignment: Alignment.topCenter,
child: Padding(
padding: const EdgeInsets.only(top: 10, left: 50.0),
child: Column(
children: [
SizedBox(
child: Row(
children: [
Text(
'Definations',
style: TextStyle(
fontFamily: 'Arial',
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.black,
height: 2,
),
textAlign: TextAlign.center,
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 10.0),
child: Container(
margin: EdgeInsets.only(top: 10),
height: 3.0,
width: 200.0,
color: Colors.orange[900],
),
),
],
),
),
],
),
),
),
Padding(
padding: const EdgeInsets.only(top: 20.0, left: 20, right: 20),
child: Container(
height: 82,
width: double.infinity,
decoration: BoxDecoration(
border: Border.all(color: Colors.orange[900]),
borderRadius: BorderRadius.all(Radius.circular(40))),
// ignore: missing_required_param
child: SearchBar(
searchBarStyle: SearchBarStyle(
backgroundColor: Colors.transparent,
padding: EdgeInsets.all(20),
borderRadius: BorderRadius.circular(40),
),
hintText: "Search",
hintStyle: TextStyle(
color: Colors.grey[100],
),
textStyle: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
),
mainAxisSpacing: 10,
crossAxisSpacing: 10,
)),
),
Container(
child: new Expanded(
flex: 1,
child: Scrollbar(
isAlwaysShown: true,
child: SingleChildScrollView(
child: ListView(
children: [
ListTile(
title: Text('this is title'),
subtitle: Text('this is sub title'),
),
ListTile(
title: Text('this is title'),
subtitle: Text('this is sub title'),
),
ListTile(
title: Text('this is title'),
subtitle: Text('this is sub title'),
),
]
)
)
)
),
),
],
),
);
}
}
Make your listview shrinkwrap: true and ensure scroll physics
shrinkWrap: true,
physics: ScrollPhysics()
I think your ListView and SingleChildScrollView are conflict.
SingleChildScrollView(
child: Column(
children: [
ListTile(
title: Text('this is title'),
subtitle: Text('this is sub title'),
),
ListTile(
title: Text('this is title'),
subtitle: Text('this is sub title'),
),
ListTile(
title: Text('this is title'),
subtitle: Text('this is sub title'),
),
],
),
),
or you can setting your height
SingleChildScrollView(
child: SizedBox(
height: 200,
child: ListView(
children: [
ListTile(
title: Text('this is title'),
subtitle: Text('this is sub title'),
),
ListTile(
title: Text('this is title'),
subtitle: Text('this is sub title'),
),
ListTile(
title: Text('this is title'),
subtitle: Text('this is sub title'),
),
],
),
),
),
you cant do Expanded+SingleChildScroll view, SingleChildScrollView has infinite height, so it wont work, you need constrained/fixed height for SingleChildScrollView,
#EDIT
Scrollbar(
isAlwaysShown: true,
child: ListView(
children: List.generate(100, (index) => ListTile(
title: Text('this is title'),
subtitle: Text('this is sub title'),
))
)
)
Facing some difficulties in flutter as I am new to it, how to centerInParent for imageView for flutter? The image is not center, I had use Align but still not working. And how to construct the image and text like this photo ?
appBar: PreferredSize(
preferredSize: Size.fromHeight(45.0),
child: AppBar(
leading: Row(
children: [
Container(
child: GestureDetector(
onTap: () {/* open left menu */},
child: Image.asset("assets/images/ic_title_menu.png", width: 18.0, height: 18.0,)),
padding: EdgeInsets.fromLTRB(14.0, 14.0, 14.0, 14.0),
),
],
),
title: Container(
child: GestureDetector(
onTap: () {/* open search */},
child: Image.asset("assets/images/ic_title_search.png", width: 18.0, height: 18.0,)),
),
actions: <Widget>[
Center(
child: Container(
child: Stack(children: <Widget>[
Align(
alignment: Alignment.center,
child: Image.network(""),)
],),
),
)
],
titleSpacing: 0.0,
automaticallyImplyLeading: false,
),
),
I hope this is something you wanted!
import 'package:flutter/material.dart';
const Color kRed = Colors.red;
class Test extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
Icon(
Icons.menu,
color: kRed,
size: 30,
),
SizedBox(width: 10),
Icon(
Icons.search,
color: kRed,
size: 30,
)
],
),
Text(
'Test Text',
style: TextStyle(color: kRed, fontSize: 30),
),
Row(
children: <Widget>[
Column(
children: <Widget>[
Text(
'Test Text',
style: TextStyle(color: kRed, fontSize: 15),
),
Text(
'Test Text',
style: TextStyle(color: kRed, fontSize: 15),
),
],
),
SizedBox(width: 10),
Icon(
Icons.person,
color: kRed,
size: 30,
)
],
)
],
),
),
);
}
}
Just replace the Text Widget in the middle with Image Widget. And tweak with your colors.
App Bar has a property called centerTitle, it will add title on the Appbar center.
centerTitle: true,
Try This
flexibleSpace: Container(
margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
child: Center(
child: Image(
image: AssetImage('assets/img/icon_1.png'),
))),
I have implemented tab layout which consists of two tabs, each tab view has a listview, container with tabview & listview should occupy space upto bottom as of now i place static value of 400, so only up to 400 the listview appears, i need the list view to be appeared up to bottom. can you please me to fix this
Widget build(BuildContext context) {
return Container(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left:20.0,right:20.0),
child: Container(
color: Colors.white,
child: new TabBar(
controller: _controller,
labelColor: Colors.deepOrange,
tabs: [
new Tab(
icon: const Icon(Icons.description),
text: 'ABC',
),
new Tab(
icon: const Icon(Icons.assignment),
text: 'XYZ',
),
],
),
),
),
Padding(
padding: const EdgeInsets.only(left:20.0,right:20.0),
child: Container(
color: Colors.white,
height: 400.0,
child: new TabBarView(
controller: _controller,
children: <Widget>[
ListView(
children: <Widget>[
ListTile(
title: Text('Sun'),
),
ListTile(
title: Text('Moon'),
),
ListTile(
title: Text('Star'),
),
],
),
ListView(
children: <Widget>[
ListTile(
title: Text('Sun'),
),
ListTile(
title: Text('Moon'),
),
ListTile(
title: Text('Star'),
),
],
),
],
),
),
),
],
),
);
}
I have Used Expanded & Flex Widgets which solved the problem
#override
Widget build(BuildContext context) {
return Container(
child: Column(
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.only(left:20.0,right:20.0),
child: Container(
color: Colors.white,
child: new TabBar(
controller: _controller,
labelColor: Colors.deepOrange,
tabs: [
new Tab(
icon: const Icon(Icons.description),
text: 'Current Openings',
),
new Tab(
icon: const Icon(Icons.assignment),
text: 'Applied Jobs',
),
],
),
),
),
flex: 1,
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(left:20.0,right:20.0,bottom: 10.0),
child: Container(
color: Colors.white,
child: new TabBarView(
controller: _controller,
children: <Widget>[
ListView(
children: <Widget>[
ListTile(
title: Text('Sun'),
),
],
),
ListView(
children: <Widget>[
ListTile(
title: Text('Sun'),
),
],
),
],
),
),
),
flex: 9,
),
],
),
);
}
I feel like I'm not completely getting persistentFooterButtons. I thought that they'd be part of the safe area, so I can see them when the keyboard is visible. Is there a way to achieve this?
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Persisting test'),
),
body: Center(child: TextFormField()),
persistentFooterButtons: <Widget>[
IconButton(icon: Icon(Icons.map), onPressed: () {}),
IconButton(icon: Icon(Icons.view_week), onPressed: () {}),
],
);
}
You could try using a Stack and an Align widget
return Scaffold(
appBar: AppBar(
title: Text('Persisting test'),
),
body: Center(
child: Stack(
children: <Widget>[
TextFormField(),
Align(
alignment: Alignment.bottomRight,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
IconButton(icon: Icon(Icons.map), onPressed: () {}),
IconButton(icon: Icon(Icons.view_week), onPressed: () {}),
],
),
)
],
)),
);
i hope this may help
Widget bodySection = new Expanded(
child: new Container (
padding: new EdgeInsets.all(8.0),
color: Colors.white70,
child: new TextFormField(
style: const TextStyle(
color: Colors.black,
),
decoration: new InputDecoration(
icon: new Icon(
Icons.lock,
color: Colors.black,
),
border: InputBorder.none,
hintText: "Enter some text here ..",
hintStyle: const TextStyle(color: Colors.black, fontSize: 12.0),
contentPadding: const EdgeInsets.only(
top: 20.0, right: 5.0, bottom: 20.0, left:30.0),
),
),
),
);
Widget fixedBottomSection = new Container (
padding: new EdgeInsets.all(8.0),
color: Colors.purpleAccent[200],
height: 48.0,
child:
new InkWell(
onTap: _continue,
child: new Center(
child: new Text('Next ' , style: TextStyle(color: Colors.white , fontWeight: FontWeight.bold),),
),
)
);
Widget content = new Column(
// This makes each child fill the full width of the screen
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
bodySection,
fixedBottomSection,
],
);
return new Scaffold(
appBar: new AppBar(
// backgroundColor: Colors.purpleAccent[200],
title: new Text("Fixed bottom action bar above keyboard"),
),
body: new Padding(
padding: new EdgeInsets.symmetric(vertical: 0.0, horizontal: 0.0),
child: content,
),
);
here is a prove that it works: