How to make dropdown with a circular border in Flutter? - flutter

I want to make a combo/dropdown with the circular border which looks like this. How to design this in Flutter?

In Flutter, you can create a combo with a circular border using the Container widget and setting the decoration property to a BoxDecoration with a shape of BoxShape.circle.
Here's an example:
Container(
width: 100,
height: 100,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(width: 2, color: Colors.blue)
),
child: ... // add the combo content here
)
You can customize the border width and color by adjusting the width and color properties of the Border object, respectively.

You can achieve this with this code.
Container(
padding: EdgeInsets.symmetric(horizontal: 20.0),
width: displayWidth(context) * 0.8,
height: 40.0,
decoration: BoxDecoration(
border: Border.all(
color: Colors.black, //Change the border color as your choice
),
borderRadius: BorderRadius.circular(20),
),
child: DropdownButton<String>(
value: dropdownValue,
isExpanded: true,
icon: const Icon(Icons.keyboard_arrow_down),
elevation: 16,
style: const TextStyle(color: Colors.deepPurple),
onChanged: (String? value) {
// This is called when the user selects an item.
setState(() {
dropdownValue = value!;
});
},
items: list.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
),

Related

Why are both the text widgets not in the same line inside my table row in flutter?

I am new to Flutter. I am trying to create a table which has two columns. In the first column, there should be a text and in the second one, there should be a dropdown. This is my code:
Container(
margin: const EdgeInsets.all(0),
alignment: Alignment.center,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Colors.orange.shade400,
border: Border.all(
color: Colors.black, // Set border color
width: 1.0), // Set border width
),
child:Table(
border: TableBorder.all(
color: Colors.black,
style: BorderStyle.solid,
width: 2),
children: [
TableRow( children: [
Column(children:const [Text('Bill Type',style:TextStyle(fontSize: 16))]),
Column(children:[DropdownButton<String>(
key:bt,
value: str,
icon: const Icon(Icons.arrow_downward),
iconSize: 16,
style: const TextStyle(color: Colors.black, fontSize: 16,),
onChanged: (String? newValue) {
setState(() {
str = newValue!;
});
},
items: <String>['AC', 'Electric current', 'Electric Arrear']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Center(
child:Text(value,textAlign: TextAlign.center,),
),
);
}).toList(),
)]),
]),
],
),
)
This is the screenshot of my output
As you can see in the screenshot, the text in the left column and the dropdown in the right column are not in the same line. Both of them should be in the center of their respective columns.
Also, the selected value of the dropdown is not aligned in the center. How do I resolve these issues? Please help me.
You have to set the defaultVerticalAlignment property in the Table widget to TableCellVerticalAlignment.middle in order to center the cells' contents vertically. As for centering the value of the DropDownButton just set the alignment property to Alignment.center.

Hide the bottom line and change the style of the selected element Drowdown_button2

I need your help. I'm using dropdown_button2 from pub.dev but I've run into a few issues that I can't resolve. First mistake: how to change the text style of the selected element? I need the text that displays the selected item to be larger. The second mistake: you need to remove the bottom line, which is displayed under the selected element, when the element is not selected, there is no line, only the element is selected - the line appears. Below I have attached screenshots of what I have now and what I need to get in the end. I would appreciate your help.
dropdown
Widget build(BuildContext context) {
return Container(
width: 120,
decoration: BoxDecoration(
border: Border(
bottom: selectedValue != null
? const BorderSide(
color: constants.Colors.white,
)
: BorderSide.none,
),
),
child: DropdownButtonHideUnderline(
child: DropdownButton2(
hint: const Text(
'Select',
style: constants.Styles.bigBookTextStyleWhite,
),
items: widget.items
.map((item) => DropdownMenuItem<String>(
value: item,
child: Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: constants.Colors.white.withOpacity(0.1),
width: 1,
),
),
),
child: Center(
child: Row(
children: [
if (item == selectedValue)
const SizedBox(
width: 0,
),
Expanded(
child: Text(
item,
style: constants.Styles.smallTextStyleWhite,
),
),
if (item == selectedValue)
const Icon(
Icons.check,
color: constants.Colors.purpleMain,
),
],
),
),
),
))
.toList(),
value: selectedValue,
onChanged: (value) {
setState(() {
selectedValue = value as String;
});
},
icon: SvgPicture.asset(constants.Assets.arrowDropdown),
iconSize: 21,
buttonHeight: 27,
buttonElevation: 1,
itemHeight: 47,
dropdownMaxHeight: 191,
dropdownWidth: 140,
dropdownDecoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: constants.Colors.purpleMain,
),
color: constants.Colors.greyDark,
),
selectedItemBuilder: (context) {
return widget.items.map((item) {
return Center(
child: Text(
item,
style: constants.Styles.smallTextStyleWhite,
),
);
}).toList();
},
),
),
);
}
at the moment I have
should be the result
To change text style of the selected element use selectedItemBuilder. It's responsible for how the selected item will be displayed on button.
The bottom line under the selected element is shown by the decoration parameter you're using in the main Container widget. Remove it and bottom line should be gone.

Remove default padding of DropDownButton in flutter?

I want to achieve a result like this where my dropdown button has very less padding.
This is what I currently have
so far I have tried adjusting height of dropDownButton, wrapping with a container, assigning padding but nothing works
here's my code
Container(
child: Center(
child: DropdownButtonHideUnderline(
child: ButtonTheme(
alignedDropdown: true,
child: DropdownButton<String>(
dropdownColor: AppColors().white,
value: value,
style: TextStyles().medium12,
icon: Icon(
Icons.keyboard_arrow_down,
color: AppColors().green,
),
onChanged: (newValue) {
setState(() {
value = newValue!;
});
},
items: <String>[
AppStrings().getString().english_language,
AppStrings().getString().arabic_language,
AppStrings().getString().urdu_language,
].map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(
value,
),
);
}).toList(),
),
),
),
),
padding: EdgeInsets.only(
left: 10.w,
right: 10.w,
),
decoration: BoxDecoration(
border: Border.all(color: AppColors().green, width: 6.w),
borderRadius: BorderRadius.all(
Radius.circular(25.r) // <--- border radius here
),
),
);
can someone please help me? thankyou so much
just set dropdownbutton isDense: true

Open DropDown below the selected value flutter

I need to to show dropdown below the selected value . How can we set Dropdown vertical offset in flutter like we do in android. is there a simple way to it without creating custom dropdown? image is attached and
Here is my drop down code:
Container(
width: percentWidth(77, context),
padding: EdgeInsets.fromLTRB(16, 0, 16, 0),
child: DropdownButton<String>(
isExpanded: true,
value: state.selectedSubject,
underline: Container(
height: 1.0,
decoration: const BoxDecoration(
border: Border(
bottom: BorderSide(
color: Colors.transparent,
width: 0.0))),
),
icon: Icon(Icons.arrow_drop_down),
iconSize: 0,
elevation: 16,
style: TextStyle(color: Colors.black, fontSize: 15),
onChanged: (String data) {
_userFeedbackBloc
.add(UserFeedbackEvent.onDropDownChanged(data));
},
items: spinnerItems.map<DropdownMenuItem<String>>(
(String newValue) {
return DropdownMenuItem<String>(
value: newValue,
child: Text(newValue),
);
}).toList(),
),
),
Ah, here use offset my friend.
offset: Offset(0, 100),
put that good Offset inside PopupMenuButton
You can use CustomDropDown
https://github.com/DhavalRKansara/CustomDropDown/blob/main/custom_drop_down.dart
Copy code from above line and past In dart file
Then you can use it like below
CustomDropdownButton(
value: _selectedCompany,
items: _dropdownMenuItems,
onChanged: onChangeDropdownItem,
),

Flutter TextField height not increasing

I am trying to increase my text field height but it's not increasing I already try wrapping with the container and increase the height of the container but it just increases the background height not text field height.
Also maxLines is working but needs to increase by height so I can add some shadows in container
import 'package:flutter/material.dart';
import 'package:curved_navigation_bar/curved_navigation_bar.dart';
import 'package:mytravel/screens/loginPage.dart';
import 'package:mytravel/screens/guidePlacePage.dart';
import 'package:image_picker/image_picker.dart';
import 'dart:async';
import 'dart:io';
class addPostPage extends StatefulWidget {
#override
_addPostPageState createState() => _addPostPageState();
}
class _addPostPageState extends State<addPostPage> {
File _image;
Future getImage() async {
var image = await ImagePicker.pickImage(source: ImageSource.gallery);
setState(() {
_image = image;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xFFEDF0F6),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 75, right: 10, left: 10),
child: Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(25.0),
),
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.symmetric(vertical: 10.0),
child: Column(
children: <Widget>[
InkWell(
onTap: () {
getImage();
},
child: Container(
margin: EdgeInsets.all(10.0),
width: double.infinity,
height: 400.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25.0),
boxShadow: [
BoxShadow(
color: Colors.black45,
offset: Offset(0, 5),
blurRadius: 8.0,
),
],
image: DecorationImage(
image: _image == null
? AssetImage("assets/images/post0.jpg")
: Image.file(_image),
fit: BoxFit.fitWidth,
),
),
),
),
],
),
),
Container(
height: 200, //here you can see try to increase height
padding: EdgeInsets.only(right: 15, left: 15),
child: TextField(
style: TextStyle(
fontSize: 20,
),
decoration: InputDecoration(
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.green),
borderRadius: BorderRadius.all(Radius.circular(20)),
),
fillColor: Colors.white,
filled: true,
border: InputBorder.none,
hintText: 'Your short story of image',
),
),
)
],
),
),
),
],
),
),
);
}
}
the contentPadding controls the height of the TextField if you want to increase the height of your text then you would alter the height property in TextStyle
TextField(
style: TextStyle(height: 4 // controls the height on main text
),
controller: _controller,
decoration: InputDecoration(
contentPadding: // Text Field height
EdgeInsets.symmetric(
vertical: 25.0, horizontal: 10.0),
hintStyle: TextStyle(
height: 4, //Controls the height of the hint text
),
errorStyle:
TextStyle(), // Controls style of error message
counterStyle:
TextStyle(), //Controls style of the counter if you have one
helperStyle:
TextStyle(), //Controls style of the helper message
labelStyle:
TextStyle(), //Controls style of the label message
prefixStyle:
TextStyle() //Controls the style of the prefix
),
),
let me know if this works
First Option: (Make sure to match the height)
TextField(
style: TextStyle(
height: 1.5, // change this to reflect the effect
fontSize: 20.0
),
hintStyle: TextStyle(
height: 1.5, //Controls the height of the hint text
),
)
Second Option:
TextField(
decoration: const InputDecoration(
contentPadding: const EdgeInsets.symmetric(vertical: 40.0),
)
)
Plus wcyankees424 answer provides more options, even for success,error etc. hints.
Read this page please:
https://api.flutter.dev/flutter/painting/TextStyle/height.html
As it is described you need add a height property for text. So you need add this line after font size:
height:2.0;
When height is null or omitted, the line height will be determined by the font's metrics directly, which may differ from the fontSize. When height is non-null, the line height of the span of text will be a multiple of fontSize and be exactly fontSize * height logical pixels tall.