Flutter: IOS style datepicker in flutter - flutter

How could i add iosstyle datepicker in flutter and set it into a textfield. I tried few things but failed..getting android style datepicker and setting it up has many solutions but ios style datepicker doesnt have much solutions..Thanks for the help

use this
void _showIOS_DatePicker(ctx) {
showCupertinoModalPopup(
context: ctx,
builder: (_) => Container(
height: 190,
color: Color.fromARGB(255, 255, 255, 255),
child: Column(
children: [
Container(
height: 180,
child: CupertinoDatePicker(
initialDateTime: DateTime.now(),
onDateTimeChanged: (val) {
setState(() {
dateSelected = val.toString();
});
}),
),
],
),
));
}

flutter_datetime_picker:
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
String _date = "Date of Birth";
Padding(padding: EdgeInsets.symmetric(
vertical: 10.0, horizontal: 16.0),
child: Column(
children: <Widget>[
SizedBox(
height: 60.0,
child: FlatButton(
shape: RoundedRectangleBorder(
side: BorderSide(
color: Colors.orangeAccent
),
borderRadius: BorderRadius.circular(5.0)),
onPressed: () {
DatePicker.showDatePicker(context,
theme: DatePickerTheme(
containerHeight: 210.0,
),
showTitleActions: true,
minTime: DateTime(1900, 1, 1),
maxTime: DateTime.now(), onConfirm: (date) {
print('confirm $date');
_date = '${date.day}/${date.month}/${date.year}';
setState(() {});
}, currentTime: DateTime.now(), locale: LocaleType.en);
},
child: Container(
alignment: Alignment.center,
height: 50.0,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
Container(
child: Row(
children: <Widget>[
Icon(
Icons.cake,
color: Colors.black54,
),
Text(
" $_date",
style: TextStyle(
color: Colors.black,
fontSize: 17.0,
fontStyle: FontStyle.normal),
),
],
),
)
],
),
Icon(Icons.date_range,color: Colors.black45,)
],
),
),
color: Colors.white,
),
),
// datetime()
],
),
),

Related

Flutter cupertino datetime picker - on time selected "call to action"

How can I call to action in flutter dateTime picker? I have got working state that updates current time to selected time but I am not sure how to execute selected time to do something.(if _time = current Time.now => Do something")Any help will be much appreciated.Do I need to implement counter or update timer every minute first?
String _time = "Set Timer";
Padding(
padding: const EdgeInsets.all(35.0),
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
// const SizedBox(
// height: 10.0,
// ),
ElevatedButton(
onPressed: () {
DatePicker.showTimePicker(context,
theme: const DatePickerTheme(
containerHeight: 210.0,
),
showTitleActions: true,
onConfirm: (time) {
_time =
'${time.hour} : ${time.minute}';
setState(() {});
},
currentTime: DateTime.now(),
locale: LocaleType.en);
setState(() {});
},
style: ElevatedButton.styleFrom(
backgroundColor: Color.fromARGB(121, 126, 239, 234),
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
textStyle: const TextStyle(
fontSize: 22,)),
//Visual Look of Timer Displayed
child: Container(
alignment: Alignment.center,
height: 30.0,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
Row(
children: <Widget>[
const Icon(
Icons.access_time,
size: 18.0,
color: Color.fromARGB(255, 255, 255, 255),
),
Text(
" $_time",
style: const TextStyle(
color: Color.fromARGB(255, 255, 255, 255),
fontSize: 18.0),
),
],
)
],
),
const Text(
" Change",
style: TextStyle(
color: Color.fromARGB(255, 255, 255, 255),
fontWeight: FontWeight.bold,
fontSize: 18.0),
),
],
),
),
)
],
),
),

Delete button does not delete the content

There are no error messages, but the delete button does not delete the selected content when I click on Delete.
The page shows a series of activities in sequence. The user should be able to edit or delete the individual activity when selected.
I do not find and understand the problem, can you help me find the error please ?
This is the code:
class AllTasksView extends GetView<HomeController> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
height: Get.height,
width: Get.width,
color: Theme.of(context).scaffoldBackgroundColor,
//padding: EdgeInsets.symmetric(horizontal: 30, vertical: 50),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.only(top: 50, left: 25, right: 25),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'All Tasks',
style: kSubHeadTextStyle.copyWith(
color: Theme.of(context).primaryColorDark),
),
IconButton(
icon: Icon(
// FontAwesomeIcons.history,
FontAwesomeIcons.clockRotateLeft,
color: Theme.of(context).primaryColor,
size: 24,
),
onPressed: () {
Get.to(() => PastTasksView());
},
),
],
),
),
SizedBox(height: Get.height * 0.012),
GetBuilder<HomeController>(
id: 1,
builder: (controller) {
return Expanded(
child: ListView.builder(
itemBuilder: (context, index) {
final task = controller.commingTasks[index]!;
return Slidable(
// actionPane: SlidableBehindActionPane(),
// actionExtentRatio: 0.2,
// controller: controller.slideC,
child: ExpandedContainer(
icon: task.taskImage,
title: task.taskTitle,
time: task.startTime,
desc: task.taskDesc,
ifDate: true,
date: DateFormat.yMMMd().format(task.taskDate!),
),
startActionPane: ActionPane(
motion: BehindMotion(),
children: [
SlidableAction(
onPressed: (context) {
// controller.slideC.activeState?.close();
Slidable.of(context)?.close();
controller.preUpdateTask(task);
showModalBottomSheet(
backgroundColor: Colors.transparent,
isScrollControlled: true,
context: context,
builder: (context) {
return BottomSheetContent(
buttonText: 'Update Task',
onSubmit: () {
controller.updateTask(task);
},
);
},
) as IconData;
},
label: "Update",
),
],
),
endActionPane: ActionPane(
motion: BehindMotion(),
children: [
SlidableAction(
onPressed: (context) {
// controller.slideC.activeState?.close();
Slidable.of(context)?.close();
controller.customDialogDel(context, task);
},
label: "Delete",
),
],
),
);
},
itemCount: controller.commingTasks.length,
),
);
},
),
],
),
),
);
}
}
This is the code to delete task by id
/// [ function to delete task by ID ]
deleteTask(Task task) async {
int index = allTasks.indexOf(task);
allTasks.removeAt(index);
taskRoutine();
reWriteTasks();
update([1, true]);
print(index);
}
And this is the code to delete where is the confirm dialog:
/// [ function to delete confirm dialog ]
Future<dynamic> customDialogDel(BuildContext context, Task task) {
return Get.dialog(Container(
margin: EdgeInsets.symmetric(
vertical: Get.height * 0.35, horizontal: Get.width * 0.18),
padding: EdgeInsets.all(20),
width: Get.width * 0.8,
height: Get.width * 0.8,
decoration: BoxDecoration(
color: Theme.of(context).scaffoldBackgroundColor,
borderRadius: BorderRadius.circular(20),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(20),
child: Scaffold(
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
body: Center(
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
'Delete Task!',
style: kSubHeadTextStyle.copyWith(
fontSize: 20,
color: Theme.of(context).primaryColorDark,
),
),
SizedBox(height: 20),
Text(
'Are you sure?',
style: kSubHeadTextStyle.copyWith(
fontSize: 16,
color: Theme.of(context).primaryColorDark,
),
),
SizedBox(height: 40),
Container(
width: 140,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
GestureDetector(
onTap: () {
Get.back();
},
child: Container(
padding: EdgeInsets.symmetric(
vertical: 10, horizontal: 15),
child: Text(
'No',
style: kSubHeadTextStyle.copyWith(
fontSize: 16,
color: Theme.of(context).primaryColorDark,
),
),
decoration: BoxDecoration(
color: Colors.transparent,
border: Border.all(
color: Theme.of(context).primaryColor),
borderRadius: BorderRadius.circular(10),
)),
),
SizedBox(width: 20),
GestureDetector(
onTap: () {
// slideC.activeState?.close();
Slidable.of(context)?.close();
deleteTask(task);
Get.back();
},
child: Container(
padding: EdgeInsets.symmetric(
vertical: 10, horizontal: 15),
child: Text(
'Yes',
style: kSubHeadTextStyle.copyWith(
fontSize: 16,
color: Theme.of(context).primaryColorDark,
),
),
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(10),
)),
)
]),
),
],
),
),
),
),
));
}
}

flutter alertdialog with background image

Folloing is my alert dialog box code, i need to set an background image for the alert dialog instead of blue color, need to show a design
AlertDialog(
backgroundColor: Colors.blue,
titlePadding: EdgeInsets.all(0),
contentPadding: EdgeInsets.all(0),
title: Container(
decoration: BoxDecoration(
color: profile_edit_toolbar_color,
borderRadius: BorderRadius.all(Radius.circular(8))),
width: MediaQuery.of(context).size.width * 0.7,
height: MediaQuery.of(context).size.height * 0.5,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.all(18),
child: Text(
'Select countries to show',
style: TextStyle(
color: Colors.yellow[300],
fontSize: 20,
fontFamily: fontFamily_3),
// style: CustomStyle.balooCustom(20, Colors.white)
),
),
IconButton(
onPressed: () {
Navigator.of(context).pop();
},
icon: Icon(
Icons.close,
size: 25,
color: Colors.white,
)),
],
),
Row(
children: [
Expanded(
child: Container(
height: 120,
child: DisplayCountriesForm(
countriesList: eventResponse.countriesList,
num: 0,
displayCountries: displayCountries,
onValueChanged: (updatedList) {
},
),
)),
Expanded(
child: Container(
height: 120,
child: DisplayCountriesForm(
countriesList: eventResponse.countriesList,
num: 1,
displayCountries: displayCountries,
onValueChanged: (updatedList) {
},
),
)),
Expanded(
child: Container(
height: 120,
child: DisplayCountriesForm(
countriesList: eventResponse.countriesList,
num: 2,
displayCountries: displayCountries,
onValueChanged: (updatedList) {
},
),
)),
],
),
],
),
),
);
Try below code I have add background image of the alert dialog hope your problem is solved , Use your widget also and change background image on your need
TextButton(
child: Text('Pressed Me'),
onPressed: () => showDialog(
context: context,
builder: (context) => AlertDialog(
content: Stack(
alignment: Alignment.center,
children: <Widget>[
Image.network(
'https://www.kindpng.com/picc/m/355-3557482_flutter-logo-png-transparent-png.png',
),
Text(
'Add Your Text Here',
style: TextStyle(
fontSize: 24,
),
),
],
),
),
),
),
Your Result Screen->

Dialog is not work properly with singlechildscrollview and soft keyboard in flutter

Dialog is not working properly with singlechildscrollview and soft keyboard in flutter.
Problems:
Dialog design is gone under the soft keyboard
Scroll is not properly working when open soft keyboard
My dialog is here:-
Future<void> ShowMessageDetail(
BuildContext context, String name, String message, String date, int id) async {
txtController.text = message;
edit = false;
return showDialog(
context: context,
builder: (context) {
return StatefulBuilder(
builder: (BuildContext context, void Function(void Function()) setState) {
return AlertDialog(
contentPadding: EdgeInsets.only(left: 25, right: 25),
content: Wrap(
children: [
Column(
children: [
Container(
height: 50,
width: double.infinity,
color: Colors.blue,
child: Center(
child: Text(
"Detail",
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 20),
)),
),
Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 10, bottom: 10),
child: Row(
children: [
Text(
"Name : ",
style: TextStyle(
color: Colors.blue,
),
),
Text(name)
],
),
),
Divider(
color: Colors.grey,
),
Padding(
padding: const EdgeInsets.only(top: 10, bottom: 8),
child: Row(
children: [
Text(
"Date : ",
style: TextStyle(
color: Colors.blue,
),
),
Text(date.substring(0, 10))
],
),
),
Divider(
color: Colors.grey,
),
Padding(
padding: const EdgeInsets.only(top: 8, bottom: 8),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Align(
alignment: Alignment.centerLeft,
child: Text(
"Message : ",
style: TextStyle(
color: Colors.blue,
),
),
),
Row(
children: [
Container(
decoration: BoxDecoration(
color: edit ? Colors.blue : Colors.white,
borderRadius: BorderRadius.circular(30),
border: Border.all(color: Colors.blue, width: 2),
),
child: IconButton(
onPressed: () {
setState(() {
edit ? edit = false : edit = true;
});
},
icon: Icon(
Icons.edit_outlined,
color: edit ? Colors.white : Colors.blue,
)),
),
Container(
width: 15,
),
Container(
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(30),
),
child: IconButton(
onPressed: () {
copy(message);
},
icon: Icon(
Icons.copy,
color: Colors.white,
)),
)
],
),
],
),
ConstrainedBox(
constraints: BoxConstraints(
maxHeight: 300,
),
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Padding(
padding: const EdgeInsets.only(top: 10),
child: Container(
child: TextFormField(
controller: txtController,
textAlign: TextAlign.justify,
focusNode: contentFocus,
decoration: InputDecoration.collapsed(
hintText: 'Start typing...',
hintStyle: TextStyle(
color: Colors.grey.shade400,
fontSize: 16,
fontWeight: FontWeight.w500,
),
border: InputBorder.none,
),
enabled: edit ? true : false,
maxLines: null,
keyboardType: TextInputType.multiline,
style: TextStyle(
fontSize: 15,
height: 1.2,
),
),
),
),
),
)
],
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Visibility(
visible: edit ? true : false,
child: MaterialButton(
onPressed: () {
updateMessage(name, txtController.text.toString(), id);
},
color: Colors.blue,
child: Text(
"Update",
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
),
),
),
Container(
width: 15,
),
MaterialButton(
onPressed: () {
Navigator.pop(context);
},
color: Colors.blue,
child: Text(
"Cancel",
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
),
),
],
)
],
),
],
),
],
),
);
},
);
});
}
I use scrollController for scrolling but this does not work.
Please help me to solve my dialog design problem.
wrap your Alert Dialog with SingleChildScrollview
SingleChildScrollView(
child: AlertDialog());

Duplicate GlobalKey detected in Widget Tree or Multiple Widgets used the same GlobalKey

I've tried to create form to input something from textfield to database using rest service, it worked just fine from the first try, but it got error the next time I tried, the error said there was something wrong with the GlobalkKey, so it's maybe around here.
class _DeliveryRecieverState extends State<DeliveryReciever> {
List datas;
File imagePath;
bool validasi = false;
String namaPenerima;
final _keyFormReceiver = GlobalKey<FormState>();
#override
Widget build(BuildContext context) {
datas = this.datas;
print(datas);
return DefaultTabController(
length: 1,
child: Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
bottom: TabBar(
tabs: <Widget>[
Tab(
icon: Icon(Icons.local_shipping),
text: "Bukti Delivery",
),
],
),
elevation: 0.1,
// backgroundColor: Colors.cyan[800],
flexibleSpace: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Color(0xFF17ead9), Color(0xFF6078ea)]),
),
),
title: Text(
"Delivery",
style: TextStyle(
fontFamily: "Popins-Bold",
fontSize: ScreenUtil.getInstance().setSp(46),
letterSpacing: .6,
fontWeight: FontWeight.bold,
),
),
actions: <Widget>[
],
),
body: TabBarView(
children: <Widget>[
SingleChildScrollView(
child: Padding(
padding: EdgeInsets.only(
left: 15.0, right: 15.0, top: 15.0, bottom: 15.0),
child: Column(
children: <Widget>[
Container(
width: double.infinity,
height: ScreenUtil.getInstance().setHeight(470),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8.0),
boxShadow: [
BoxShadow(
color: Colors.black12,
offset: Offset(0.0, 15.0),
blurRadius: 15.0),
BoxShadow(
color: Colors.black12,
offset: Offset(0.0, -10.0),
blurRadius: 10.0)
]),
child: Padding(
padding: EdgeInsets.only(
left: 16.0, right: 16.0, top: 16.0),
child: Form(
key: _keyFormReceiver,
autovalidate: validasi,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"Nama Penerima",
style: TextStyle(
fontSize:
ScreenUtil.getInstance().setSp(30),
fontFamily: "Poppins-Bold",
letterSpacing: .6),
),
SizedBox(
height:
ScreenUtil.getInstance().setHeight(30),
),
TextFormField(
validator: validasiReceivername,
onSaved: (String nama) {
namaPenerima = nama;
},
decoration: InputDecoration(
hintText: "Nama Penerima",
hintStyle: TextStyle(
color: Colors.grey,
fontSize: 12.0)),
),
SizedBox(
height:
ScreenUtil.getInstance().setHeight(50),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(10.0),
child: RaisedButton(
elevation: 7.0,
color: Colors.green,
padding: EdgeInsets.all(20.0),
child: Text("LANJUT"),
textColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(10)),
onPressed: () {
parseData();
},
),
),
],
),
],
),
)),
),
],
),
),
),
],
),
bottomNavigationBar: Container(
height: 55.0,
child: BottomAppBar(
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Color(0xFF17ead9), Color(0xFF6078ea)]),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
IconButton(
icon: Icon(Icons.home, color: Colors.white),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => halamanUtama()),
);
},
),
IconButton(
icon: Icon(Icons.nature_people, color: Colors.white),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => UpcomingDelivery()),
);
},
),
IconButton(
icon: Icon(Icons.local_shipping, color: Colors.white),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ListDelivery()),
);
},
),
],
),
),
),
),
));
}
String validasiReceivername(String value) {
if (value.length == 0) {
//Toast.show("Password more than 4 ", context,duration: Toast.LENGTH_SHORT, gravity: Toast.CENTER);
return "Nama penerima tidak boleh kosong.";
} else {
return null;
}
}
void parseData() async {
if (_keyFormReceiver.currentState.validate()) {
_keyFormReceiver.currentState.save();
_keyFormReceiver.currentState.reset();
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => CustomerSignatureProof(
created_name: widget.created_name,
wmsorders_id: widget.wmsorders_id,
imagePath: widget.imagePath,
imageName: widget.imageName,
receiverName: namaPenerima,
upcoming_id: widget.upcoming_id,
upcoming_sku: widget.upcoming_sku,
upcoming_sak: widget.upcoming_sak,
upcoming_qty: widget.upcoming_qty,
upcoming_shipstatid: widget.upcoming_shipstatid,
upcoming_picname: widget.upcoming_picname,
upcoming_pictelp: widget.upcoming_pictelp,
upcoming_ordermultipleid: widget.upcoming_ordermultipleid,
upcoming_orderdetid: widget.upcoming_orderdetid,
upcoming_coordinatorid: widget.upcoming_coordinatorid,
upcoming_shipmentid: widget.upcoming_shipmentid)));
}
}
}
Here is the error in terminal,
Have anybody face the same probles as me, please give your guidance..