Flutter Listview with rounded corners - flutter

I'm trying to create a listview with rounded corners in Flutter. I thought I might have been on the right track by adding a ClipRRect wrapped around the listview. However, when I did so only the top corners were rounded, the bottom ones were not, I assume this is because the listview did not have enough rows to take up the full screen, but the ClipRRect, must be taking up the full scren width.
What's the best way to add rounded corners to the listview widget?

try this for round corners with list.
Container(
decoration: BoxDecoration(
border: Border.all(
color: Color(0xFFF05A22),
style: BorderStyle.solid,
width: 1.0,
),
color: Color(0xFFF05A22),
borderRadius: BorderRadius.circular(30.0),
),
child:ListView(
children: new List.generate(
100,
(index) => Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Text("data $index"),
Divider(),
])),
),
)

Wrap your ListView with SizedBoxand provide size.
body: LayoutBuilder(
builder: (context, constraints) {
return ClipRRect(
borderRadius: BorderRadius.circular(12.0),
child: SizedBox(
height: constraints.maxHeight,//based on your need
width: constraints.maxWidth,
child: ListView.builder(

https://gist.github.com/Nitingadhiya/5f2020d2f3d3258d0ff95280e025062f
//List-view-border-radius-example.dart
// Border-bottom-left
// Border-bottom-right
// Border all
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
#override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: ListBuilder(),
);
}
}
class ListBuilder extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: ListView(
padding: const EdgeInsets.all(8),
children: <Widget>[
Container(
decoration: BoxDecoration(
borderRadius:
const BorderRadius.only(bottomLeft: Radius.circular(85.0)),
color: Colors.amber[600],
),
height: 50,
child: const Center(child: Text('Entry A')),
),
Container(
height: 50,
decoration: BoxDecoration(
borderRadius:
const BorderRadius.only(bottomRight: Radius.circular(85.0)),
color: Colors.amber[500],
),
child: const Center(child: Text('Entry B')),
),
Container(
height: 50,
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(85.0)),
color: Colors.amber[100],
),
child: const Center(child: Text('Entry C')),
),
],
),
);
}
}

I like to create constants in a separate file for the BoxDecoration and other hard-coded values e.g.
const kCards = BorderRadius.only(
bottomLeft: Radius.circular(5),
bottomRight: Radius.circular(5),
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
);
And then call the const kCards in the decoration: kCards,
It makes your code much cleaner and of course follows DRY-Do not Repeat Yourself.
If you want to make any adjustments to specific buttons/tiles etc use
e.g....
gradientButton.copyWith(color: Colors.blue),
borderRadius.copyWith(bottomLeft: Radius.circular(20),),
Another example but with hard-coded values
ListTile(
title: TextField(
controller: _email,
decoration: InputDecoration(
labelText: 'Email',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
),
),
),
),
ListView specific Example with ClipRect
ListView(
shrinkWrap: true,
children: [
ClipRect(
child: TextField(
controller: _email,
decoration: const InputDecoration(
labelText: 'Email',
border: OutlineInputBorder(),
),
),
),
const SizedBox(height: 10),
ClipRect(
child: TextField(
controller: _password,
obscureText: true,
decoration: const InputDecoration(
labelText: 'Password',
border: OutlineInputBorder(),
),
),
),
const SizedBox(height: 10),
],
),

Related

Flutter Bottom Overflow on custom bottom sheet

You can see the problem here (I turned on flutter inspector gridlines so you can see the problem better)
Overflow disappears when I wrap my Container inside Expanded,
but then my search bar height is just stretching and it isn't good. Tried to use SingleChildScrollView but it didn't do the trick.
Container(
margin: const EdgeInsets.symmetric(
horizontal: AppConstants.bottomModalSheetSearchMarin,
vertical: AppConstants.bottomModalSheetSearchMarin),
decoration: BoxDecoration(
color: AppColors.searchBoxBackgroundColor,
borderRadius:
BorderRadius.circular(AppConstants.searchBoxRadius),
),
child: const TextField(
// onChanged: (value)=>controller.filterMountain(value),
decoration: InputDecoration(
hintStyle:
TextStyle(fontSize: AppFontSizes.searchBoxHintText),
hintText: 'Search',
suffixIcon: Icon(
Icons.search,
color: AppColors.searchBoxSearchIconColor,
),
border: InputBorder.none,
contentPadding:
EdgeInsets.all(AppPaddings.searchBoxPadding),
),
),
),
The problem is in the search bar container (we can see that from flutter inspector - show gridlines)
This is how it looks when I wrap Container with Expanded, (don't be bothered with the different look of the cards below)
Edit:
Here is the full bottomSheet code as requested:
bottomNavigationBar: SolidBottomSheet(
draggableBody: false,
headerBar: Container(
child: ClipRRect(
borderRadius: const BorderRadius.only(
topRight: Radius.circular(20),
topLeft: Radius.circular(20)
),
child: OutlinedButton(
child: Column(
children: const [
Icon(Icons.expand_less,),
Text("Search pois")
],
),
onPressed: () {}),
),
),
body: Container(
color:Colors.blue,
child: Column(
children: [
Container(
decoration: BoxDecoration(
color:Colors.red,
borderRadius: BorderRadius.circular(20),
),
child: const TextField(
decoration: InputDecoration(,
hintText: 'Search',
suffixIcon: Icon(Icons.search,),
),
),
),
Obx(
),
],
),
),
),
You can wrap TextFiled's Container with Expanded and enable expanded on TextFiled.
body: Container(
child: Column(
children: [
Expanded(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(22),
),
child: TextField(
expands: true,
maxLines: null,
minLines: null,
)),
),
],
),
),
SingleChildScrollView also work
body: SingleChildScrollView(
child: Column(
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(22),
),
child: TextField(
maxLines: 3,
minLines: 1,
)),
],
),
),
class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
bottomNavigationBar: SolidBottomSheet(
draggableBody: true,
headerBar: Container(
child: ClipRRect(
borderRadius: const BorderRadius.only(
topRight: Radius.circular(22), topLeft: Radius.circular(22)),
child: OutlinedButton(
child: Column(
children: const [
Icon(
Icons.expand_less,
),
Text(
"Search pois",
)
],
),
onPressed: () {}),
),
),
body: SingleChildScrollView(
child: Column(
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(22),
),
child: TextField(
maxLines: 3,
minLines: 1,
)),
],
),
),
),
);
}
}

flutter design list item

I want to design something like the below image:
the main widget is Card and the skill's widget is Chip. skills length can be between 3 words to 12 words, so the number of chips that can show is variable. this is my model:
class NurseListItem {
late String imageUrl;
late String nurseName;
late String userType;
late List<String> skills;
late bool isBusy;
}
how can I create this listItem widget?
Try to below code I have try above image like Widget hope its helpful for you.
Card(
shape: RoundedRectangleBorder(
side: BorderSide(
color: Colors.green.shade300,
),
borderRadius: BorderRadius.circular(15.0),
),
child: Column(
children: [
ListTile(
leading: Icon(Icons.check),
title: Text('User Name'),
subtitle: Text('User Type'),
trailing: FlutterLogo(size: 100),
),
ButtonBar(
alignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
padding: const EdgeInsets.all(5.0),
decoration: BoxDecoration(
border: Border.all(color: Colors.green),
borderRadius: BorderRadius.circular(5),
),
child: Text('Skill 0'),
),
Container(
padding: const EdgeInsets.all(5.0),
decoration: BoxDecoration(
border: Border.all(color: Colors.green),
borderRadius: BorderRadius.circular(5),
),
child: Text('Skill 1'),
),
Container(
padding: const EdgeInsets.all(5.0),
decoration: BoxDecoration(
border: Border.all(color: Colors.green),
borderRadius: BorderRadius.circular(5),
),
child: Text('Skill 2'),
),
Container(
padding: const EdgeInsets.all(5.0),
decoration: BoxDecoration(
border: Border.all(color: Colors.green),
borderRadius: BorderRadius.circular(5),
),
child: Text('Skill 3'),
),
],
)
],
),
)
Your Screen Look like this ->

Image not showing up in ListView

I know the code is a little messy, still learning.
I have placed the Image outside of the BoxDecoration but noting is showing up. Nothing shows up in the RUN as an error. I am guessing that it has something to do with the container inside the ListView but haven't been able to find out why its blank.
import 'package:flutter/material.dart';
class Home extends StatefulWidget {
#override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
elevation: 0.0,
title: Text("App"),
),
body: SafeArea(
child: Container(
height: 80,
decoration: new BoxDecoration(
color: Colors.blue,
borderRadius: new BorderRadius.only(
bottomLeft: const Radius.circular(40.0),
bottomRight: const Radius.circular(40.0))
),
child: ListView(
children: <Widget>[
Container(
margin: EdgeInsets.symmetric(horizontal: 10.0, vertical: 10.0),
width: 120,
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey[300],
offset: Offset(1, 1),
blurRadius: 0
),
], // BoxShadow
borderRadius: BorderRadius.all(Radius.circular(20))
),
child: ListTile(
leading: Icon(Icons.search, color: Colors.red),
title: TextField(
decoration: InputDecoration(
hintText: "What stuff do you want to seach for?",
hintStyle: TextStyle(fontSize: 16, color: Colors.grey),
border: InputBorder.none
),
),
trailing: Icon(Icons.filter_list, color: Colors.red),
),
),
SizedBox(height: 5),
Container(
height: 220,
width: 220,
child: Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.red,
offset: Offset(1, 1),
blurRadius: 4
),
],
),
child: Image.asset("assets/images/1.jpg"),
),
],
),
),
],
),
),
)
);
}
}
This is what I am trying to do.
I updated the structure as a Column with two children:
The blue Container with the TextField
The ListView with the pictures
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
home: Home(),
),
);
}
class Home extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(elevation: 0.0, title: Text("App")),
body: SafeArea(
child: Column(
children: [
Container(
padding: EdgeInsets.all(20.0),
decoration: const BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(40.0),
bottomRight: Radius.circular(40.0),
),
),
child: DecoratedBox(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20.0),
),
child: const ListTile(
leading: Icon(Icons.search),
title: TextField(
decoration: InputDecoration(
hintText: "What stuff do you want to seach for?",
hintStyle: TextStyle(fontSize: 16, color: Colors.grey),
border: InputBorder.none,
),
autofocus: true,
),
trailing: Icon(Icons.filter_list),
),
),
),
SizedBox(
height: 120.0,
child: ListView(
scrollDirection: Axis.horizontal,
shrinkWrap: true,
children: List.generate(
20,
(index) => Padding(
padding: const EdgeInsets.all(16.0),
child: Image.asset("assets/images/cartoon.jpg"),
),
),
),
),
],
),
),
);
}
}

How do i center a text field horizontaly and vertically in flutter

Hi i am new to flutter i need to align the text field horizontally and vertically for more elaboration see this
What i am getting:
Text aligned at the very top it needs to be in the center
What i really want:
the text field is aligned both horizontaly and vertically that is exactly what i am looing for
Here is the code:
import 'package:multi_purpose_scope/Animation/FadeAnimation.dart';
import 'package:flutter/material.dart';
void main() => runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: HomePage(),
)
);
class HomePage extends StatelessWidget {
gotoSecondActivity(BuildContext context){
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondActivity()),
);
}
#override
Widget build(BuildContext context){
return Scaffold(
backgroundColor: Colors.white,
body: SingleChildScrollView(
child: RaisedButton(
onPressed: () {
gotoSecondActivity(context);
},
child: Container(
child: Column(
children: <Widget>[
Container(
height: 400,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/loginHeader.png'),
fit: BoxFit.fill
)
),
child: Stack(
children: <Widget>[
],
),
),
Padding(
padding: EdgeInsets.all(30.0),
child: Column(
children: <Widget>[
FadeAnimation(1.8, Container(
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: Color.fromRGBO(143, 148, 251, .2),
blurRadius: 20.0,
offset: Offset(0, 10)
)
]
),
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.all(8.0),
decoration: BoxDecoration(
border: Border(bottom: BorderSide(
color: Colors.grey[100]))
),
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Email or Phone number",
hintStyle: TextStyle(
color: Colors.grey[400])
),
),
),
Container(
padding: EdgeInsets.all(8.0),
child: TextField(
obscureText: true,
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Password",
hintStyle: TextStyle(
color: Colors.grey[400])
),
),
)
],
),
)),
SizedBox(height: 30,),
FadeAnimation(2, Container(
height: 50,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
gradient: LinearGradient(
colors: [
Color.fromRGBO(214, 0, 27, 1),
Color.fromRGBO(214, 0, 27, 1),
]
)
),
child: Center(
child: Text("Login", style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold),),
),
)),
SizedBox(height: 70,),
FadeAnimation(1.5, Text("Forgot Password?",
style: TextStyle(
color: Color.fromRGBO(214, 0, 27, 1)),)),
],
),
)
],
),
),
)
),
);
}
}
class SecondActivity extends StatelessWidget {
gotoRegister(BuildContext context){
Navigator.push(
context,
MaterialPageRoute(builder: (context) =>Register()),
);
}
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Container(
child: Container(
height: 174,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/patient_list.png'),
)
),
child: Stack(
children: <Widget>[
Container(
alignment: Alignment.center,
height: 128,
child: Text(
'Patient List',
style: TextStyle(
fontWeight: FontWeight.bold,fontSize: 30,
color: Colors.white
),
),
)
],
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
gotoRegister(context);
},
tooltip: 'Increment',
child: Icon(Icons.add),
backgroundColor: Color.fromRGBO(214, 0, 27,1),
),
),
);
}
}
class Register extends StatelessWidget {
goBack(BuildContext context) {
Navigator.pop(context);
}
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Container(
child:Container(
height: 174,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/patient_list.png'),
)
),
child: Stack(
children: <Widget>[
Container(
alignment: Alignment.center,
height: 128,
child: Text(
'Registration
style: TextStyle(
fontWeight: FontWeight.bold,fontSize: 30,
color: Colors.white
),
)
),
Container(
padding: EdgeInsets.all(8.0),
decoration: BoxDecoration(
border: Border(bottom: BorderSide(
color: Colors.grey[100]))
),
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Email or Phone number",
hintStyle: TextStyle(
color: Colors.grey[400])
),
),
),
],
),
),
)
),
);
}
}
I searched for this but cant seem to find the solution to my problem.
I have almost tried all the solutions that i can think of but those don't work
Just set the textAlign property to your TextField and also add a border in your decoration.
Sample:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Column(
children: <Widget>[
const SampleTextField(hintText: 'Enter Name'),
const SizedBox(height: 10),
const SampleTextField(hintText: 'Enter MR-Number'),
const SizedBox(height: 10),
const SampleTextField(hintText: 'Enter Phone Number'),
const SizedBox(height: 10),
const SampleTextField(hintText: 'Enter Hospital Name'),
const SizedBox(height: 10),
FlatButton(
onPressed: () {},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
// materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
// visualDensity: VisualDensity.compact,
padding: const EdgeInsets.symmetric(vertical: 20),
color: Colors.red,
child: const Center(
child: Text('Registration'),
),
),
],
),
),
),
),
);
}
}
class SampleTextField extends StatelessWidget {
const SampleTextField({
this.controller,
this.hintText = '',
});
final TextEditingController controller;
final String hintText;
#override
Widget build(BuildContext context) {
return TextField(
controller: controller,
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(
width: 1,
color: Colors.black54,
),
),
hintText: hintText,
hintStyle: const TextStyle(
color: Colors.black54,
),
contentPadding: const EdgeInsets.only(left: 20),
),
// textAlign: TextAlign.center, // Align vertically and horizontally
);
}
}
You are using a stack widget so if you want to align and positioned your widget inside the stack see the below options
Wrap widget with Positioned widget if you want to change position
Wrap widget with Align widget for alignment
Check out this Video for how to use Positioned widget
Check out this Video for how to use Align widget

I want to make a button like this but not getting the desired output

I want to make a text form field and button inside a container and the click of a button text in the form should be copied to clipboard. How can I achieve this?
My Requirement is like this
Container(
height: 65.0,
width: 270.0,
child: Row(
children: <Widget>[
Expanded(
child: TextField(
decoration: InputDecoration(
hintText: "https://",
border: OutlineInputBorder(
borderRadius:
BorderRadius
.circular(10.0),
borderSide:
BorderSide()))),
),
Container(
child: FlatButton(
onPressed: () {},
child: Text("Copy Link")),
)
],
),
)
You have two things to learn to achieve, what you want, these are:
Clipboard class => Which does the clipboard copy. Also, do import this import 'package:flutter/services.dart'; in your file to use this Class
suffixIcon in InputDecoration, which will add the item to the end inside your TextField()
FINAL SOLUTION:
// mandatory for Clipboard class
import `'package:flutter/services.dart';
class _MyHomePageState extends State<MyHomePage> {
final key = new GlobalKey<ScaffoldState>();
final TextEditingController _controller = new TextEditingController();
#override
Widget build(BuildContext context){
return Scaffold(
key: key,
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Container(
height: 65.0,
width: 270.0,
child: TextField(
controller: _controller,
decoration: InputDecoration(
hintText: "https://",
suffixIcon: FlatButton(
onPressed: () {
// Here what you have to do the operation using Clipboard
Clipboard.setData(new ClipboardData(text: _controller.text.toString()));
key.currentState.showSnackBar(
new SnackBar(content: new Text("Copied to Clipboard")));
},
child: Text("Copy Link")
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: BorderSide()
)
)
)
)
),
);
}
}
RESULT:
You need to add the border to the Container and not the Textfield
Container(
height: 50.0,
width: 270.0,
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey,
),
borderRadius: BorderRadius.circular(10.0),
),
child: Row(
children: <Widget>[
Expanded(
child: TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.only(left: 10.0),
hintText: "https://",
border: InputBorder.none,
),
),
),
Container(
height: 50.0,
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey,
),
borderRadius: BorderRadius.circular(6.0),
),
child: FlatButton(onPressed: () {}, child: Text("Copy Link")),
),
],
),
)
Try this:
Container(
height: 65.0,
width: 270.0,
decoration: BoxDecoration(
border: Border.all(),
borderRadius: BorderRadius.circular(20.0)),
child: Row(
children: <Widget>[
Expanded(
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: "https://")),
),
Container(
child: FlatButton(
onPressed: () {},
child: Text("Copy Link")),
)
],
),
)
);
this will give