How to Add Rounded Rectangle Border?
Below Code didn't result in any border on screen.
Container(margin: EdgeInsets.only(top: 10.0, right: 10.0, left: 10.0),
width: double.infinity,
// decoration: ShapeDecoration(
// shape: RoundedRectangleBorder(
// borderRadius:BorderRadius.all(Radius.circular(5.0)),
// ),
child: DropdownButtonHideUnderline(
child: Container(
margin: EdgeInsets.only(
left: 10.0, right: 10.0),
child: new DropdownButton<UserTest>(...),
),
),
),
With the form field variant, you can use the OutlineInputBorder InputBorder, used normally for input text fields:
DropdownButtonFormField(
...
decoration: const InputDecoration(
border: OutlineInputBorder(),
),
),
The way the form field does this can be replicated and used with the regular DropdownButton:
InputDecorator(
decoration: const InputDecoration(border: OutlineInputBorder()),
child: DropdownButtonHideUnderline(
child: DropdownButton(
...
),
),
),
You need to specify the side: property. By default it is BorderSide.none.
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
side: BorderSide(width: 1.0, style: BorderStyle.solid),
borderRadius: BorderRadius.all(Radius.circular(5.0)),
),
),
If what you want is this...
Then here you go
import 'package:flutter/material.dart';
class RoundedBorderDropdown extends StatelessWidget {
final List<String> _dropdownValues = [
"One",
"Two",
"Three",
"Four",
"Five"
]; //The list of values we want on the dropdown
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Rounded Border Button in AppBar'),
),
body: Center(
child: Container(
padding: EdgeInsets.symmetric(horizontal: 10.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15.0),
border: Border.all(
color: Colors.red, style: BorderStyle.solid, width: 0.80),
),
child: DropdownButton(
items: _dropdownValues
.map((value) => DropdownMenuItem(
child: Text(value),
value: value,
))
.toList(),
onChanged: (String value) {},
isExpanded: false,
value: _dropdownValues.first,
),
),
),
);
}
}
That is courtesy inducesmile
Happy Coding...
Column(
crossAxisAlignment : CrossAxisAlignment.start,
children: <Widget> [
Text('Gender:'),
InputDecorator(
decoration: InputDecoration(
border: OutlineInputBorder(borderRadius: const BorderRadius.all(Radius.circular(4.0)),
contentPadding: EdgeInsets.all(10),
),
child: DropdownButtonHideUnderline(
child: DropdownButton<String>(
value: gender,
isDense: true,
isExpanded: true,
items: [
DropdownMenuItem(child: Text("Select Gender"), value: ""),
DropdownMenuItem(child: Text("Male"), value: "Male"),
DropdownMenuItem(child: Text("Female"), value: "Female"),
],
onChanged: (newValue) {
setState(() {
});
},
),
),
),
]
),
You can try with this
Container(
padding: EdgeInsets.symmetric(horizontal: 5),
decoration: BoxDecoration(
border: Border.all(color: Colors.blueGrey),
borderRadius: BorderRadius.circular(5),
),
child: DropdownButtonHideUnderline(
child: DropdownButton<String>(
borderRadius: BorderRadius.circular(12),
isExpanded: true,
items: <String>[
'1 km',
'2 km',
'3 km',
'4 km',
'5 km'
].map((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
hint:
ourtext("Select area", fontSize: 14),
onChanged: (_) {},
),
),
),
Container(width: 200.0,
height: 50.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(7.0),
border: Border.all(color: Colors.blueGrey)),
child: DropdownButton<String>(
hint: Text("Messaging"),
items: <String>['Messaging', 'Chating', 'No Longer Interested', 'Document Request'].map((String value) {
return new DropdownMenuItem<String>(
value: value,
child: new Text(value),
);
}).toList(),
onChanged: (_) {},
),
)
Wrap it in a Material and remove DropDown borders
Material(
borderRadius: BorderRadius.circular(40),
child: SizedBox(
width: MediaQuery.of(context).size.width / 1.08,
child: DropdownButton(
style: style.copyWith(color: Colors.black),
isExpanded: true,
underline: DropdownButtonHideUnderline(child: Container()),
value: value,
items: ...
),
)
In case you want to make rounded corners for the menu itself, just add borderRadius properties in DropdownButton:
DropdownButton(
borderRadius:BorderRadius.circular(12),
items: ...
)
String selectedValue
String selected value;
Widget createRoundedDropDown (){
return Container(
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(),
borderRadius: BorderRadius.circular(20),
),
child: Padding(
padding: const EdgeInsets.all(5.0),
child: DropdownButtonHideUnderline(
child: DropdownButton<String>(
borderRadius: BorderRadius.circular(10),
style: TextStyle(color: Colors.black,fontSize: 14,),
hint: Text("hint text"),
value: selectedValue,
isDense: true,
onChanged: (newValue) {
setState(() {
selectedValue = newValue;
});
},
items: listItems.map((document) {
return DropdownMenuItem<String>(
value: document.name,
child: FittedBox(fit:BoxFit.fitWidth,
child: Text(document.name,
style:TextStyle(fontSize: 16))),
);
}).toList(),
),
),
),
);}
Related
I am trying to send data to API, But I can't make it to work. I use model to get data from users.
Here is the model
class SurgeryModel {
String id;
String name;
DateTime date;
String eye;
SurgeryModel(
{required this.id,
required this.date,
required this.name,
required this.eye});
}
And I am adding data like this.
void addNewSurgeryRecord(BuildContext ctx) {
showDialog(
context: context,
builder: (context) {
// we use statefulbilder because we need to use setState to update the dropdown menu state.
return StatefulBuilder(builder: (context, setState) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
10.0,
),
),
content: SingleChildScrollView(
child: Column(
children: [
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Container(
child: Text(
'Surgery Name',
style: TextStyle(
color: Colors.black,
fontSize: 16.0,
),
),
),
TextField(
keyboardType: TextInputType.multiline,
maxLength: 1000,
maxLines: null,
controller: sNameController,
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(
15.0,
),
),
focusedBorder: OutlineInputBorder(
borderRadius:
BorderRadius.all(Radius.circular(15.0)),
borderSide: BorderSide(color: Colors.blue),
),
// labelText: 'Drug name',
// labelStyle: TextStyle(color: Colors.blue[200]),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.blueAccent,
),
borderRadius: BorderRadius.circular(
15.0,
),
),
),
),
],
),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Container(
child: Text(
'Date',
style: TextStyle(
color: Colors.black,
fontSize: 16.0,
),
),
),
TextFieldContainer(
child: DateTimeField(
format: format,
onChanged: (getPrescriptionDate) {
formattedTodate = getPrescriptionDate!;
},
onShowPicker: (context, currentValue) {
return showDatePicker(
context: context,
firstDate: DateTime(1900),
initialDate: currentValue ?? DateTime.now(),
lastDate: DateTime(2100));
},
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Select Date of Visited',
hintStyle: TextStyle(
fontSize: 15, fontWeight: FontWeight.normal),
),
initialValue: formattedTodate.toLocal(),
validator: (dateOfBirthValue) {
// dob = dateOfBirthValue.toString();
return null;
},
),
),
// TextFieldContainer(
// keyboardType: TextInputType.multiline,
// maxLength: 1000,
// maxLines: null,
// // controller: surgeryDateController,
// decoration: InputDecoration(
// border: OutlineInputBorder(
// borderRadius: BorderRadius.circular(
// 15.0,
// ),
// ),
// focusedBorder: OutlineInputBorder(
// borderRadius:
// BorderRadius.all(Radius.circular(15.0)),
// borderSide: BorderSide(color: Colors.blue),
// ),
// // labelText: 'Drug name',
// // labelStyle: TextStyle(color: Colors.blue[200]),
// enabledBorder: OutlineInputBorder(
// borderSide: BorderSide(
// color: Colors.blueAccent,
// ),
// borderRadius: BorderRadius.circular(
// 15.0,
// ),
// ),
// ),
// ),
],
),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Container(
child: Text(
'Eye',
style: TextStyle(
color: Colors.black,
fontSize: 16.0,
),
),
),
TextFieldContainer(
child: DropdownButtonHideUnderline(
child: DropdownButton(
icon: Visibility(
visible: false,
child: Icon(Icons.arrow_downward)),
isExpanded: true,
value: dropDownValue,
items: eyeSide.map((value) {
return DropdownMenuItem(
value: value,
child: Text(value),
);
}).toList(),
onChanged: ((String? value) {
setState(() {
print(value);
dropDownValue = value!;
print(' print 2$value');
});
}),
),
),
),
// TextField(
// keyboardType: TextInputType.multiline,
// maxLength: 1000,
// maxLines: null,
// controller: sEyeController,
// decoration: InputDecoration(
// border: OutlineInputBorder(
// borderRadius: BorderRadius.circular(
// 15.0,
// ),
// ),
// focusedBorder: OutlineInputBorder(
// borderRadius:
// BorderRadius.all(Radius.circular(15.0)),
// borderSide: BorderSide(color: Colors.blue),
// ),
// // labelText: 'Drug name',
// // labelStyle: TextStyle(color: Colors.blue[200]),
// enabledBorder: OutlineInputBorder(
// borderSide: BorderSide(
// color: Colors.blueAccent,
// ),
// borderRadius: BorderRadius.circular(
// 15.0,
// ),
// ),
// ),
// ),
],
),
],
),
),
actions: [
Align(
alignment: Alignment.bottomRight,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.green,
onPrimary: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
),
onPressed: () {
widget.addSurgery(
sNameController.text,
dropDownValue,
formattedTodate,
);
// _addNewSurgery(sNameController.text, sEyeController.text);
print(sNameController.text);
print(sEyeController.text);
print(formattedTodate.toString());
Navigator.of(context).pop();
},
child: Text('Done'),
),
),
],
);
});
});
}
Below function is in another screen I pass this function to the above code screen.
void _addNewSurgery(String sName, String sEye, DateTime date) {
final newProp = SurgeryModel(
date: date,
name: sName,
eye: sEye,
id: DateTime.now().toString(),
);
setState(() {
widget.surgeData.add(newProp);
});
}
With help of these codes I am sending data to the web like below code
testFunction() async {
var localStorage = await SharedPreferences.getInstance();
var data = {
'surgeryHistory ': surgeData.toList(),
};
print('viewing pres data $data');
var res = await Network().authData(data, '/route');
debugPrint('printing before response ${res.body}');
var body = json.decode(res.body);
debugPrint('printing coming response ${body}');
}
I am getting this data like this on the web side(in laravel)
public function testWebFunction(Request $request)
{
$surgery_history = $request->get('surgeryHistory');
$surgery_history_index = $surgery_history;
return $surgery_history;
}
But I am getting error like this,
Am I doing something wrong here? I need to get those data to the web and save that data in to the database using for loop. In backend side I am using foreach to save data but i cant get sizeof the variable. Any answer will help me to overcome this situation. Thank You.
import 'package:flutter/material.dart';
import 'package:smart_uild/assets.dart';
class Myprofile extends StatelessWidget {
const Myprofile({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: const Color(0xff384A62),
leading: IconButton(
icon: const Icon(Icons.arrow_back, color: Colors.white),
onPressed: () => Navigator.of(context).pop(),
),
title: const Text("My Profile"),
elevation: 0,
),
body: Padding(
padding: const EdgeInsets.only(
left: 18.0,
top: 18,
),
child: Card(
color: Colors.grey[900],
shape: RoundedRectangleBorder(
side: const BorderSide(color: Color(0xff384A62), width: 1),
borderRadius: BorderRadius.circular(10),
),
child: Container(
width: 350,
height: 151,
color: Colors.white,
child: Row(
children: [
Center(
child: Padding(
padding: const EdgeInsets.all(10),
child: Expanded(
child: Image.asset(
image1,
width: 100,
height: 100,
),
flex: 2,
),
),
),
Expanded(
child: Container(
alignment: Alignment.topLeft,
child: Padding(
padding: const EdgeInsets.only(top: 38.0),
child: Column(
children: [
const Expanded(
flex: 5,
child: ListTile(
title: Text(
"Genova",
style: TextStyle(
color: Color(0xff384A62),
fontSize: 20,
fontWeight: FontWeight.w400),
),
),
),
Expanded(
flex: 5,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
const SizedBox(
width: 8,
),
TextButton.icon(
style: TextButton.styleFrom(
textStyle:
const TextStyle(color: Colors.white),
backgroundColor: const Color(0xffFF0000),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6.0),
),
),
onPressed: () => {},
icon: const Icon(
Icons.power_off,
color: Colors.white,
),
label: const Text(
'DUTY SIGN OFF',
style: TextStyle(
color: Colors.white,
fontSize: 14,
fontWeight: FontWeight.w400),
),
),
const SizedBox(
width: 8,
),
],
),
),
const SizedBox(
width: 8,
),
],
),
),
),
),
],
),
),
elevation: 0,
margin: const EdgeInsets.all(10),
),
),
);
}
}
I am making meme generator app . And i need to show multiple texts over the images , I am able to get one draggable text but i want the user to add multiple text . can you please help me out .
I am fetching the image via my api and i have created a stacked layout on which i have added my text .
I have provided some text customization option to users . I want users to add multiple text and they can also customize them
import 'dart:io';
import 'dart:math';
import 'dart:typed_data';
import 'dart:convert';
import 'package:admob_flutter/admob_flutter.dart';
import 'package:bordered_text/bordered_text.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';
import 'package:meme_app/Screens/CustomMemes.dart';
import 'package:meme_app/Services/admob_services.dart';
import 'dart:ui' as ui;
import 'package:meme_app/image editor/lists.dart';
import 'package:path_provider/path_provider.dart';
class CustomSceen3 extends StatefulWidget {
final String imgUrl;
final File imgFile;
CustomSceen3({
this.imgUrl,
this.imgFile,
});
#override
_CustomSceen3State createState() => _CustomSceen3State();
}
class _CustomSceen3State extends State<CustomSceen3> {
GlobalKey<ScaffoldState> scaffoldState = GlobalKey();
Size size = Size(600, 800);
List<Widget> data = <Widget>[];
Offset offset = Offset.zero;
String addedText = '';
String newText;
int total=0;
//settings
Color pickerColor = Color(0xffffffff);
Color currentColor = Color(0xffffffff);
double textSize = 28.0;
String customFont = 'Aileron-Black';
GlobalKey _key = GlobalKey();
File _imageFile;
Random rng = new Random();
int whiteSpace = 0;
bool strike = false;
double strokeSize = 2.0;
Color strokePickerColor = Color(0xff000000);
Color strokeCurrentColor = Color(0xff000000);
TextEditingController myController = TextEditingController()
..text = "";
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(
children: [
Expanded(
child: Container(
color: Colors.black,
child: Center(
child: SingleChildScrollView(
child: Container(
color: Colors.white,
child: RepaintBoundary(
key: _key,
child: Stack(
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
height: whiteSpace.toDouble() * 5,
color: Colors.white,
),
widget.imgFile == null
? Image(
image: NetworkImage(widget.imgUrl),
)
: Image.file(widget.imgFile, height: 300,
width: MediaQuery
.of(context)
.size
.width,
fit: BoxFit.fill,),
],
),
Positioned(
left: offset.dx,
top: offset.dy,
child: GestureDetector(
onPanUpdate: (details) {
setState(() {
offset = Offset(
offset.dx + details.delta.dx, offset.dy + details.delta.dy);
});
},
child: Container(
child: BorderedText(
strokeColor: strokeCurrentColor,
strokeWidth: strokeSize ,
child: Text(
addedText,
style: TextStyle(
fontFamily: customFont,
fontSize: textSize,
color: currentColor
),
),
),
),
),
),
],
),
),
),
),
),
)
),
Container(
color: Colors.black,
height: 80.0,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.all(5.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
DropdownButton<int>(
style: TextStyle(
color: Colors.white,
),
value: whiteSpace,
dropdownColor: Colors.black87,
isDense: true,
icon: Icon(Icons.padding, color: Colors.white,),
iconSize: 30,
onChanged: (int newValue) {
setState(() {
whiteSpace = newValue;
});
},
items: whiteSpaceList
.map<DropdownMenuItem<int>>((int value) {
return DropdownMenuItem<int>(
value: value,
child: Text(value.toString() + "%"),
);
}).toList(),
),
Center(
child: Text(
"Add Space", maxLines: 2, overflow: TextOverflow
.clip,
style: TextStyle(
fontSize: 11, color: Colors.white),
),
)
],
),
),
Padding(
padding: EdgeInsets.all(5.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
IconButton(
icon: Icon(Icons.text_format, color: Colors.white,
size: 30,),
onPressed: () {
TextDialog();
}
),
Text(
"Text", maxLines: 2, overflow: TextOverflow.clip,
style: TextStyle(fontSize: 11, color: Colors.white),
)
],
),
),
Padding(
padding: EdgeInsets.all(5.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
IconButton(
icon: Icon(
Icons.emoji_emotions_outlined, color: Colors
.white, size: 30,),
onPressed: null
),
Text(
"Sticker", maxLines: 2, overflow: TextOverflow.clip,
style: TextStyle(fontSize: 11, color: Colors.white),
)
],
),
),
Padding(
padding: EdgeInsets.all(5.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
IconButton(
icon: Icon(Icons.download_outlined, color: Colors
.white, size: 30,),
onPressed: null
),
Text(
"Save", maxLines: 2, overflow: TextOverflow.clip,
style: TextStyle(fontSize: 11, color: Colors.white),
)
],
),
),
Padding(
padding: EdgeInsets.all(5.0),
child: GestureDetector(
onTap: (){
setTextStyle();
},
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text(
"Aa",style:TextStyle(
fontSize: 30,color: Colors.white,fontFamily: 'ComicRelief'
),
),
Text(
"Font", maxLines: 2, overflow: TextOverflow.clip,
style: TextStyle(fontSize: 11, color: Colors.white),
)
],
),
),
),
],
)
)
],
),
),
);
}
Widget setTextStyle(){
showDialog(
context: context,
builder: (BuildContext context){
return Dialog(
backgroundColor: Colors.black54,
child: Padding(
padding: const EdgeInsets.all(5.0),
child: SizedBox(
height: 400,
child: Center(
child: Column(
children: [
CustomTextStyle(
tittle: "Black Text",
color: Colors.white,
strokecolor: Colors.white,
font: 'OpenSans-Regular',
strokewidth: 0.0,
onTap: (){
setState(() {
strokeSize= 0.0;
currentColor=Colors.black;
customFont= 'OpenSans-Regular';
strokeCurrentColor=Colors.white;
Navigator.of(context).pop();
});
},
),
CustomTextStyle(
tittle: "STANDARD MEME",
color: Colors.white,
strokecolor: Colors.black,
font: 'Anton',
strokewidth: 3.0,
onTap: (){
setState(() {
strokeSize= 3.0;
currentColor=Colors.white;
customFont= 'Anton';
strokeCurrentColor=Colors.black;
addedText=addedText.toUpperCase();
Navigator.of(context).pop();
});
},
),
CustomTextStyle(
tittle: "Modern Meme",
color: Colors.black,
strokecolor: Colors.white,
font: 'OpenSans-Regular',
strokewidth: 3.0,
onTap: (){
setState(() {
strokeSize= 3.0;
currentColor=Colors.black;
customFont= 'OpenSans-Regular';
strokeCurrentColor=Colors.white;
Navigator.of(context).pop();
});
},
),
CustomTextStyle(
tittle: "Dark Modern Meme",
color: Colors.white,
strokecolor: Colors.black,
font: 'OpenSans-Regular',
strokewidth: 3.0,
onTap: (){
setState(() {
strokeSize= 3.0;
currentColor=Colors.white;
customFont= 'OpenSans-Regular';
strokeCurrentColor=Colors.black;
Navigator.of(context).pop();
});
},
),
CustomTextStyle(
tittle: "Black Object White Outline",
color: Colors.black,
strokecolor: Colors.white,
font: 'Aileron-Bold',
strokewidth: 3.0,
onTap: (){
setState(() {
strokeSize= 3.0;
currentColor=Colors.black;
customFont= 'Aileron-Bold';
strokeCurrentColor=Colors.white;
Navigator.of(context).pop();
});
},
),
CustomTextStyle(
tittle: "White Object Black Outline",
color: Colors.white,
strokecolor: Colors.black,
font: 'Aileron-Bold',
strokewidth: 3.0,
onTap: (){
setState(() {
strokeSize= 3.0;
currentColor=Colors.white;
customFont= 'OpenSans-Regular';
strokeCurrentColor=Colors.black;
Navigator.of(context).pop();
});
},
),
CustomTextStyle(
tittle: "Yellow Subtittle",
color: Color(0xfeFFE400),
strokecolor: Colors.black,
font: 'OpenSans-Regular',
strokewidth: 3.0,
onTap: (){
setState(() {
strokeSize= 3.0;
currentColor=Color(0xfeFFE400);
customFont= 'OpenSans-Regular';
strokeCurrentColor=Colors.black;
Navigator.of(context).pop();
});
},
)
],
),
),
),
),
);
}
);
}
Widget TextDialog() {
showDialog(
context: context,
barrierDismissible: true, // user must tap button!
builder: (BuildContext context) {
return ListView(
children:[ Container(color: Colors.black54,
child: Dialog(
backgroundColor: Colors.transparent,
child: Padding(
padding: const EdgeInsets.all(5.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Row(
children: [
IconButton(
icon: Icon(Icons.invert_colors, color: Colors.white),
onPressed: null),
IconButton(
icon: Icon(Icons.add_circle, color: Colors.white),
onPressed: null),
IconButton(
icon: Icon(Icons.remove_circle, color: Colors.white),
onPressed: null),
IconButton(icon: Icon(Icons.format_align_center_outlined), onPressed: null)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
OutlineButton(
borderSide: BorderSide(width: 1.0,
color: Colors.white,
style: BorderStyle.solid),
onPressed: () {
setState(() {
addedText = myController.text;
Navigator.of(context).pop();
}
);
},
child: Text(
"Got it", style: TextStyle(color: Colors.white),
),
)
],
)
],
),
textfield(),
Container(height: 50,
color: Colors.black,
child: ListView.builder(
itemCount: colors.length,
scrollDirection: Axis.horizontal, physics: ScrollPhysics(),
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.all(5.0),
child: GestureDetector(
onTap: () {
setState(() {
currentColor = colors[index];
Navigator.of(context).pop();
TextDialog();
});
},
child: Container(
width: 40.0,
decoration: BoxDecoration(
color: colors[index], //this is the important line
shape: BoxShape.circle,
border: Border.all(
width: 2.0, color: Colors.white60)
),
),
),
);
},
),
),
],
),
),
),
),
],
);
}
);
}
Widget textfield() {
return TextField(
controller: myController,
maxLines: 10,
);
}
}
class CustomTextStyle extends StatelessWidget {
CustomTextStyle({this.color,this.tittle,this.strokecolor,this.font,this.strokewidth,this.onTap
});
final Color color;
final Color strokecolor;
final double strokewidth;
final String tittle;
final String font;
final Function onTap;
#override
Widget build(BuildContext context) {
return ListTile(
onTap: onTap,
title: BorderedText(
strokeColor: strokecolor,
strokeWidth: strokewidth,
child: Text(
tittle,
style: TextStyle(
color: color,fontFamily: font,fontSize: 17,letterSpacing: 1.05
),
),
),
);
}
}
I have often found really quick and very competent help here. And hope you can help me again.
I have had an error message for three days, which I cannot get solved.
I explained the problem to you in a small video.
The link to the video is: "https://drive.google.com/file/d/1T9uOnEaNp5W6_kcO6eV9o64Fp3sRkB3f/view?usp=sharing"
I really hope you see the mistake I don't see!
This is the code of the Foodcard, which according to Flutter should cause the error:
The method '-' was called on null.
Receiver: null
Tried calling: -(30.0)
The relevant error-causing widget was:
FoodCard file:///C:/Users/stefa/AndroidStudioProjects/cronum_app_web%20-%20Kopie/lib/Components/ProviderComponents.dart:298:9
FoodCard:
class FoodCard extends StatelessWidget {
FoodCard({
#required this.description,
#required this.imagePath,
#required this.price,
#required this.foodName,
#required this.foodItem,
#required this.increaseCallback,
#required this.decreaseCallback,
this.count = 0,
});
final double radius = 40;
static double listViewHeight;
final double margin = 15;
final double containerHeight = 130;
final int count;
final String imagePath;
final String foodName;
final String price;
final String description;
final FoodItem foodItem;
final Function increaseCallback;
final Function decreaseCallback;
#override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 10, vertical: margin),
width: 220,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(radius),
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.topRight,
colors: ([
gradientColor1.withOpacity(opacityOfHeader),
primaryColor.withOpacity(opacityOfHeader),
gradientColor2.withOpacity(opacityOfHeader),
]),
),
boxShadow: [
BoxShadow(
blurRadius: 8,
color: Colors.black.withOpacity(0.3),
offset: Offset(5, 5),
),
],
color: Colors.white,
),
child: Column(
children: <Widget>[
Stack(
alignment: Alignment.center,
children: <Widget>[
Column(
children: <Widget>[
SizedBox(
height: listViewHeight - margin * 2 - containerHeight,
),
Container(
height: containerHeight,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(radius),
topRight: Radius.circular(radius),
bottomLeft: Radius.circular(radius),
bottomRight: Radius.circular(radius),
),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.2),
offset: Offset(0, -5),
blurRadius: 8)
],
color: Colors.white),
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 40),
child: Center(
child: Text(
foodName,
style: TextStyle(
color: Colors.black,
fontSize: 17,
fontWeight: FontWeight.w900,
),
),
),
),
Padding(
padding: EdgeInsets.symmetric(
horizontal: 20, vertical: 15),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailPage(
foodItem: foodItem,
increaseCount: increaseCallback,
decreaseCount: decreaseCallback,
),
),
);
},
child: Container(
height: 30,
width: 80,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
offset: Offset(5, 5),
color: Colors.black.withOpacity(0.3),
blurRadius: 8)
],
color: buttonColor,
borderRadius: BorderRadius.circular(25),
),
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 7, vertical: 5),
child: Center(
child: Text(
'Details',
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
),
),
),
Container(
color: Colors.grey.withOpacity(0.5),
height: 25,
width: 1,
),
Container(
height: 30,
width: 80,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25),
color: buttonColor,
boxShadow: [
BoxShadow(
blurRadius: 8,
color: Colors.black.withOpacity(0.3),
offset: Offset(5, 5),
),
],
),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceAround,
children: <Widget>[
InkWell(
onTap: decreaseCallback,
child: Container(
height: 22,
width: 22,
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(5),
color: buttonColor,
),
child: Center(
child: Icon(
Icons.remove,
color: Colors.white,
size: 22,
),
),
),
),
Text(
count.toString(),
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.w900,
),
),
InkWell(
onTap: increaseCallback,
child: Container(
height: 22,
width: 22,
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(15),
color: Colors.white,
),
child: Center(
child: Icon(
Icons.add,
color: buttonColor,
size: 22,
),
),
),
),
],
),
),
],
),
),
],
),
),
],
),
Positioned(
top: 30,
child: InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailPage(
foodItem: foodItem,
increaseCount: increaseCallback,
decreaseCount: decreaseCallback,
),
),
);
},
child: Image(
height: listViewHeight / 2,
width: listViewHeight / 2,
image: AssetImage(imagePath),
),
),
),
],
)
],
),
);
}
If it is not because of the FoodCard, the function with which I create the list of Foodcards could also be the problem.
I am amazed by the error message because it is so extremely non-specific. Before I automated the creation of the list, everything worked wonderfully.
List<Widget> buildEntdeckenCards() {
List<Widget> foodCardList = [];
for (FoodItem foodItem in top10) {
print(foodItem.foodName);
foodCardList.add(
FoodCard(
description: foodItem.description,
foodName: foodItem.foodName,
foodItem: foodItem,
price: foodItem.price,
imagePath: foodItem.imagePath,
decreaseCallback: () {
decreaseCount(foodItem);
},
increaseCallback: () {
increaseCount(foodItem);
},
),
);
}
return foodCardList;
}
I think your listViewHeight variable is null, and you are trying to use it in expression
SizedBox(height: listViewHeight - margin * 2 - containerHeight,),
I think that's why you see the following error The method '-' was called on null. Assign some value to listViewHeight before using it.
I've been working on a toy reminders app and wish to implement a dropdown menu for the user to select a given time interval.
I have the button loaded and can click on it with the correct menu popping up. The problem is the appearance of the button on the screen. It is the same color as the parent Widget and does not display the text of selected item at all.
How can I get the dropdown button to have a white background and black text?
Here is a screenshot:
And here is the code that builds this view:
#override
Widget build(BuildContext context) {
return new Container(
child: new Row(
children: <Widget>[
new Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
_buildInformationRow(),
_buildReminderRow(),
],
)
)
],
)
);
}
Widget _buildInformationRow() {
return new Container(
padding: const EdgeInsets.all(10.0),
child: new Row(
children: <Widget>[
new Column(
children: <Widget>[
new Container(
padding: const EdgeInsets.all(10.0),
child: new Text(
"This app can remind you to do stuff\non a regular basis",
style: new TextStyle(
color: Colors.white,
fontSize: 18.0,
)
),
)
],
)
],
),
);
}
Widget _buildReminderRow() {
return new Container(
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
new Column(
children: <Widget>[
new Container(
child: new Text(
"Remind me",
style: new TextStyle(
color: Colors.white,
fontSize: 18.0,
)
),
)
],
),
new Column(
children: <Widget>[
new Container(
child: new DropdownButton<String>(
style: new TextStyle(
color: Colors.black,
fontSize: 18.0,
),
items: <String>["Never", "Daily", "Hourly", "Every 30 Minutes"].map((String value) {
return new DropdownMenuItem <String>(
value: value,
child: new Text(value)
);
}).toList(),
onChanged: null
)
)
],
)
],
),
);
}
Have you tried wrapping your Dropdown in a Container with a white color, then just ensure the child on the DropdownButton style attribute has a TextStyle with black color.
new Container(
color: Colors.white,
child: DropdownButtonHideUnderline(
child: ButtonTheme(
alignedDropdown: true,
child: DropdownButton<T>(
items: dropdownItems,
onChanged: this.onChanged,
value: this.preSelected,
style: new TextStyle(
color: Colors.black,
),
),
)
),
),
Note: I use the ButtonTheme to ensure the dropdown fills the width of the Container.
And you can also wrap the container around a Theme to change the background of the actual dropdown when active and displaying the menu items.
new Theme(
data: Theme.of(context).copyWith(
canvasColor: Theme.of(context).primaryColor
),
child: // Your Dropdown Code Here,
),
Theme(
data: new ThemeData(
canvasColor: Colors.red,
primaryColor: Colors.black,
accentColor: Colors.black,
hintColor: Colors.black),
child: DropdownButton(
iconEnabledColor: Colors.white,
style: TextStyle(color: _selectedColor,fontSize: 16),
underline: Text(''),
value: selectedCurrency,
isExpanded: true,
iconSize: 40,
items: currencies.entries
.map<DropdownMenuItem<String>>(
(MapEntry<String, String> e) =>
DropdownMenuItem<String>(
value: e.key,
child: Text(e.value),
))
.toList(),
onChanged: (String newKey) {
setState(() {
_selectedColor = Colors.white;
selectedCurrency = newKey;
});
},
))
Use hint instead of value
Example
hint: dropdownValue == null ? Text("Select one", style: TextStyle(color: Colors.red)): Text(dropdownValue, style: TextStyle(color: Colors.green)),
dropdownValue is the value that I selected
You can use the following code to give your customized color to DropDownButton hint
DropdownButton<String>(
isExpanded: true,
hint: Text('Your hint',style: TextStyle(color: Color(0xFFF5F5F5)),),
icon: Icon(Icons.arrow_downward),
iconSize: 20,
elevation: 12,
style: TextStyle(color: Colors.lightBlue),
underline: Container(
height: 0,
),
items: _currencies
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(
value,
style: TextStyle(fontSize: 14.0, color: Color(0xFFF5F5F5)),
),
);
}).toList(),
onChanged: (String valueSelected) {
onDropDownItemChanged(valueSelected);
},
value: dropdownValue,
//00000value: dropdownValue,
),
You can do it by
DropdownButtonHideUnderline(
child: Theme(
data: ThemeData(
primaryColor: Colors.white,
),
child: DropdownButton<String>(
isExpanded: true,
value: _selectedMetalColor,
onChanged: (String newValue) {
setState(() {
_selectedMetalColor = newValue;
//dropdownValue = newValue;
});
},
// hint: Text(
// teethMetalColors[0],
// style: TextStyle(
// color: Colors.white,
// ),
// ),
icon: Container(
margin: EdgeInsets.only(right: 12.0),
child: Icon(
// Add this
Icons.keyboard_arrow_down, // Add this
color: Colors.white, // Add this
size: 35.0,
),
),
style: TextStyle(
color: Colors.black, fontSize: 16.0),
selectedItemBuilder:
(BuildContext context) {
return teethMetalColors
.map((String value) {
return Padding(
padding: const EdgeInsets.only(
top: 12.0, left: 16.0),
child: Text(
_selectedMetalColor,
style:
TextStyle(color: Colors.white),
),
);
}).toList();
},
items: teethMetalColors
.map<DropdownMenuItem<String>>(
(String value) {
return DropdownMenuItem<String>(
value: value,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
value,
style:
TextStyle(color: Colors.black),
),
),
);
}).toList(),
),
),
)
try this, and replace the Container's color in the theme color:
Container(
padding: const EdgeInsets.only(left: 0.0, right: 10.0),
decoration: BoxDecoration(
color: Colors.cyanAccent,
),
child: DropdownButtonHideUnderline(
child: new DropdownButton<String>(
style: new TextStyle(
color: Colors.black,
fontSize: 18.0,
),
items: <String>["Never", "Daily", "Hourly", "Every 30 Minutes"].map((String value) {
return new DropdownMenuItem <String>(
value: value,
child: new Text(value)
);
}).toList(),
onChanged: null
),
),
)