Normally all things is good but when I want to add setState() it show overflow. I am making an BMI calculator app and i create a custom button and i think there the problem started.
import 'package:flutter/material.dart';
class RoundIconButton extends StatelessWidget {
RoundIconButton({required this.icon, required this.tap});
final IconData icon;
final Function tap;
#override
Widget build(BuildContext context) {
return RawMaterialButton(
onPressed: tap(),
child: Icon(
icon,
color: Color(0xffFF8B00),
),
elevation: 6.0,
constraints: BoxConstraints.tightFor(
width: 40.0,
height: 47.0,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
fillColor: Colors.black,
);
}
}
import 'package:bmi_calculator/round_icon_button.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'reusable_card.dart';
import 'iconText.dart';
import 'constants.dart';
enum Gender {
male,
female,
}
class InputPage extends StatefulWidget {
const InputPage({Key? key}) : super(key: key);
#override
State<InputPage> createState() => _InputPageState();
}
class _InputPageState extends State<InputPage> {
Gender? selectedGender;
int height = 180;
int weight = 50;
int age = 18;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
backgroundColor: Colors.black,
title: Text('BMI Calculator'),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: Row(
children: [
Expanded(
child: GestureDetector(
onTap: () {
setState(() {
selectedGender = Gender.male;
print('Male tapped');
});
},
child: ReuseableCard(
colour: selectedGender == Gender.male
? kactiveCardColor
: kinactiveCardColor,
cardChild: iconText(
icon: FontAwesomeIcons.mars,
lable: 'Male',
),
),
),
),
Expanded(
child: GestureDetector(
onTap: () {
setState(() {
selectedGender = Gender.female;
print('Female Tapped');
});
},
child: ReuseableCard(
colour: selectedGender == Gender.female
? kactiveCardColor
: kinactiveCardColor,
cardChild: iconText(
icon: FontAwesomeIcons.venus,
lable: 'FeMale',
),
),
),
),
],
),
),
Expanded(
child: ReuseableCard(
colour: Color(0xffFF8B00),
cardChild: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Height'.toUpperCase(),
style: klableTextStylet,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: [
Text(
height.toString(),
style: kNumberTextStyle,
),
Text('cm'),
],
),
SliderTheme(
data: SliderTheme.of(context).copyWith(
overlayColor: Colors.red,
thumbShape: RoundSliderThumbShape(enabledThumbRadius: 15),
overlayShape: RoundSliderOverlayShape(overlayRadius: 30),
),
child: Slider(
value: height.toDouble(),
max: 220.0,
min: 50.0,
inactiveColor: Colors.yellow,
activeColor: Colors.black,
thumbColor: Colors.red,
onChanged: (double newValue) {
setState(() {
height = newValue.round();
print(newValue);
});
},
),
),
],
),
),
),
Expanded(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: ReuseableCard(
colour: Color(0xffFF8B00),
cardChild: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Weight'.toUpperCase(),
style: klableTextStylet,
),
Text(
weight.toString(),
style: kNumberTextStyle,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RoundIconButton(
tap: (){
setState(() {
weight++;
});
},
icon: FontAwesomeIcons.plus,
),
SizedBox(
width: 10,
),
RoundIconButton(
tap: (){
setState(() {
weight--;
});
},
icon: FontAwesomeIcons.minus,
),
],
),
],
),
),
),
Expanded(
child: ReuseableCard(
colour: Color(0xffFF8B00),
cardChild: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Age'.toUpperCase(),
style: klableTextStylet,
),
Text(
age.toString(),
style: kNumberTextStyle,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RoundIconButton(
tap: (){
setState(() {
age++;
});
},
icon: FontAwesomeIcons.plus,
),
SizedBox(
width: 10,
),
RoundIconButton(
tap: (){
setState(() {
age--;
});
},
icon: FontAwesomeIcons.minus,
),
],
),
],
),
),
),
],
),
),
Container(
child: Center(
child: Text(
'Your BMI Calculator',
style: TextStyle(
color: Color(0xffFF8B00),
),
)),
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(15), topRight: Radius.circular(15)),
),
width: double.infinity,
height: kbottomContainerHeight,
margin: EdgeInsets.only(top: 10),
),
],
),
);
}
}
In above code i want to add setstate function in RoundIconButton but when i try to add this it show overflow.I am expecting this But getting this
try Wrapping your scaffold body's Column with SingleChildScrollView it should fix the issue!
There are two possible solutions.
wrap your widget with SingleChildScrollview.
for example
body: SingelChildScrollView(
scrolldirection : Axis.horizontal
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: Row(
children: [
Expanded(
child: GestureDetector(
onTap: () {
setState(() {
selectedGender = Gender.male;
print('Male tapped');
});
},
Remove above expanded you are using two Expanded widgets and both need some space on screen and the first Expanded is covering whole screen remove one of the extra Expanded widgets and wrap whole row with one single expanded.
I got the answer. Its about the old version of flutter. On flutter 2.0 we can do:
final Function tap;
onPresed: tap(),
but in flutter 3.0+ we have to do:
final Function() tap;
onPresed: tap,
class RoundIconButton extends StatelessWidget {
RoundIconButton({required this.icon, required this.tap});
final IconData icon;
final Function() tap; // add bracket here ?
#override
Widget build(BuildContext context) {
return RawMaterialButton(
onPressed: tap(),
child: Icon(
icon,
color: Color(0xffFF8B00),
),
elevation: 6.0,
constraints: BoxConstraints.tightFor(
width: 40.0,
height: 47.0,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
fillColor: Colors.black,
);
}
}
Related
I need than when the male is selected its color will change to activecolor while the female will change to inactivecolor and vice versa when female is selected. However, it seems like it doesn't work well. This page is my input page.
import 'package:bmi_calculator/result_page.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:bmi_calculator/new_widgets.dart';
import 'package:bmi_calculator/constants.dart';
import 'package:bmi_calculator/compute.dart';
const Color activeColor = Color(0xFF1D1E33);
const Color inactiveColor = Color(0xFF111328);
Color maleColor = activeColor;
Color femaleColor = inactiveColor;
int height = 170;
int weight = 80;
int age = 20;
class InputPage extends StatefulWidget {
#override
_InputPageState createState() => _InputPageState();
}
class _InputPageState extends State<InputPage> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('BMI CALCULATOR'),
backgroundColor: Color(0XFF070A1A),
),
body: Column(
children: [
Expanded(
child: Row(
children: [
Expanded(
child: GestureDetector(
onTap: (){
setState(() {
maleColor = activeColor;
femaleColor = inactiveColor;
});
},
child: CardWidget(
cardColor: maleColor,
cardChild: GenderWidget(
genderString: 'MALE',
genderIcon: FontAwesomeIcons.mars,
),
),
),
),
Expanded(
child: GestureDetector(
onTap: (){
setState(() {
maleColor = inactiveColor;
femaleColor = activeColor;
});
},
child: CardWidget(
cardColor: femaleColor,
cardChild: GenderWidget(
genderString: 'FEMALE',
genderIcon: FontAwesomeIcons.venus,
),
),
),
),
],
),
),
Expanded(
child: CardWidget(
cardColor: activeColor,
cardChild: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'HEIGHT',
style: labelStyle,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: [
Text(
height.toString(),
style: numberStyle,
),
Text(
'cm',
style: labelStyle,
),
],
),
SliderTheme(
data: SliderThemeData(
inactiveTrackColor: Color(0xff8d8e98),
activeTrackColor: Colors.white,
thumbColor: Color(0xffeb1555),
thumbShape: RoundSliderThumbShape(
enabledThumbRadius: 15.0,
),
overlayColor: Color(0x29eb1555),
overlayShape: RoundSliderOverlayShape(
overlayRadius: 30.0,
),
),
child: Slider(
min: 120,
max: 220,
value: height.toDouble(),
onChanged: (double newValue){
setState(() {
height = newValue.round();
});
},
),
),
],
),
),
),
Expanded(
child: Row(
children: [
Expanded(
child: CardWidget(
cardColor: activeColor,
cardChild: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'WEIGHT',
style: labelStyle,
),
Text(
weight.toString(),
style: numberStyle,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ButtonWidget(
buttonIcon: FontAwesomeIcons.minus,
buttonFunction: (){
setState(() {
weight--;
});
},
),
SizedBox(
width: 10.0,
),
ButtonWidget(
buttonIcon: FontAwesomeIcons.plus,
buttonFunction: (){
setState(() {
weight++;
});
},
),
],
),
],
),
),
),
Expanded(
child: CardWidget(
cardColor: activeColor,
cardChild: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'AGE',
style: labelStyle,
),
Text(
age.toString(),
style: numberStyle,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ButtonWidget(
buttonIcon: FontAwesomeIcons.minus,
buttonFunction: (){
setState(() {
age--;
});
},
),
SizedBox(
width: 10.0,
),
ButtonWidget(
buttonIcon: FontAwesomeIcons.plus,
buttonFunction: (){
setState(() {
age++;
});
},
),
],
),
],
),
),
),
],
),
),
CalculateWidget(
calcFunction: (){
Compute calc = new Compute(height, weight);
String bmi = calc.getBMI();
String result = calc.getResult();
String interpret = calc.getInterpretation();
Navigator.push(context, MaterialPageRoute(builder: (context){
return ResultPage(bmi: bmi, bmiresu: result, bmiinter: interpret);
}));
},
calcString: 'CALCULATE',
),
],
),
);
}
}
I tried to use onpress but it won't allow me. I need help how am I going to fix this?
You need to define new variable and call it isMaleSelected instead of maleColor and femaleColor:
bool isMaleSelected = false;
and use it like this:
Expanded(
child: Row(
children: [
Expanded(
child: GestureDetector(
onTap: () {
setState(() {
isMaleSelected = true; //change this
});
},
child: CardWidget(
cardColor: isMaleSelected ?activeColor: inactiveColor, //change this
cardChild: GenderWidget(
genderString: 'MALE',
genderIcon: FontAwesomeIcons.mars,
),
),
),
),
Expanded(
child: GestureDetector(
onTap: () {
setState(() {
isMaleSelected = false; //change this
});
},
child: CardWidget(
cardColor: isMaleSelected ? inactiveColor : activeColor, //change this
cardChild: GenderWidget(
genderString: 'FEMALE',
genderIcon: FontAwesomeIcons.venus,
),
),
),
),
],
),
),
import 'package:customizedapp/reuseable_card.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'icon_content.dart';
import 'constants.dart';
enum Gender {
male,
female,
}
class InputPage extends StatefulWidget {
const InputPage({Key? key}) : super(key: key);
#override
State<InputPage> createState() => _InputPageState();
}
class _InputPageState extends State<InputPage> {
Gender? selectedGender;
double height = 0.0;
int weight = 0;
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(
title: Text(
'BMI Calculator',
style: TextStyle(fontSize: 20.0),
),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: Row(
children: [
Expanded(
child: ReusableCard(
colour: selectedGender == Gender.male
? kActiveReusealeContainerColor
: kInactiveReusealeContainerColor,
containChild: IconContent(FontAwesomeIcons.mars, 'MALE'),
onPress: () {
setState(() {
selectedGender = Gender.male;
});
},
),
),
Expanded(
child: ReusableCard(
colour: selectedGender == Gender.female
? kActiveReusealeContainerColor
: kInactiveReusealeContainerColor,
containChild:
IconContent(FontAwesomeIcons.venus, 'FEMALE'),
onPress: () {
setState(() {
selectedGender = Gender.female;
});
},
),
),
],
),
),
Expanded(
child: ReusableCard(
colour: kActiveReusealeContainerColor,
containChild: Column(
children: [
Text(
'Height',
style: kLabelTextStyle,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: [
Text(
height.toStringAsFixed(2),
style: kNumberDisplayTextStyle,
),
Text(
'ft',
style: kLabelTextStyle,
),
],
),
SliderTheme(
data: SliderThemeData(
activeTrackColor: Colors.white,
inactiveTrackColor: Color(0xff8E8E9C),
thumbShape: RoundSliderThumbShape(
enabledThumbRadius: 12.0, elevation: 5),
overlayShape:
RoundSliderOverlayShape(overlayRadius: 24),
thumbColor: Color(0xffDF4068),
overlayColor: Color(0x29DF4068),
),
child: Slider(
value: height,
min: kMinSliderValue,
max: kMaxSliderValue,
onChanged: (double newValue) {
setState(() {
height = newValue;
});
}),
),
],
),
),
),
Expanded(
child: Row(
children: [
Expanded(
child: ReusableCard(
colour: kActiveReusealeContainerColor,
containChild: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Weight',
style: kLabelTextStyle,
),
Text(
weight.toString(),
style: kNumberDisplayTextStyle,
),
'here in the row I'm getting error, i've tried by wrapping row and children in Expanded widget but doesn't works either'
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RoundButton(
icon: FontAwesomeIcons.add,
onPressed: () {
setState(() {
weight++;
});
}),
SizedBox(
width: 10,
),
RoundButton(
icon: FontAwesomeIcons.minus,
onPressed: () {
setState(() {
weight--;
});
}),
],
),
],
),
),
),
Expanded(
child: ReusableCard(
colour: kActiveReusealeContainerColor,
containChild: Container(),
),
),
],
),
),
Container(
height: kBottomContainerHeight,
margin: EdgeInsets.only(top: 10),
width: double.infinity,
color: kBottomContainerColor,
),
],
),
),
);
}
}
class RoundButton extends StatelessWidget {
const RoundButton({Key? key, required this.icon, required this.onPressed})
: super(key: key);
final IconData icon;
final Function onPressed;
#override
Widget build(BuildContext context) {
return RawMaterialButton(
onPressed: onPressed(),
child: Icon(icon),
fillColor: kInactiveReusealeContainerColor,
constraints: BoxConstraints(minWidth: 56, minHeight: 56),
shape: CircleBorder());
}
}
'this error occurs'
This InputPage widget cannot be marked as needing to build because the framework is already in the process of building widgets. A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase.
The widget on which setState() or markNeedsBuild() was called was: InputPage
state: _InputPageState#98c9c
The widget which was currently being built when the offending call was made was: RoundButton
dirty'
Replace onPressed: onPressed(), with onPressed: onPressed,. You like to call the event when the button is pressed instead of build time.
I have the next widget, which is rendered with overflow. I have tried to solve, but i don't know. Can anyone help me? The aim is to do a custom card inside listview.
I have tried to wrap with expanded buth then, the error is referenced with constraints.
import 'package:flutter/material.dart';
import '../../shared/AppTheme.dart';
class ComandaScreen extends StatefulWidget {
const ComandaScreen({Key? key}) : super(key: key);
#override
State<ComandaScreen> createState() => _ComandaScreenState();
}
class _ComandaScreenState extends State<ComandaScreen> {
bool expanded = false;
int unidades = 0;
final List<Map<String, dynamic>> _items = List.generate(
10, (index) => {'id': index, 'Nombre': 'Nuggets $index',
'isExpanded': false, "unidades": 8});
#override
Widget build(BuildContext context) {
final ButtonStyle flatButtonStyle = TextButton.styleFrom(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(4.0)),
),
);
return Scaffold(
appBar: AppBar(
title: const Text('Comanda'),
backgroundColor: AppTheme.backgroundColor,
foregroundColor: AppTheme.primaryTextColor,
elevation: 0,
),
body: SingleChildScrollView(
child: ExpansionPanelList(
elevation: 3,
// expandedHeaderPadding: const EdgeInsets.all(10),
expansionCallback: (index, isExpanded) {
setState(() {
_items[index]['isExpanded'] = !isExpanded;
});
},
animationDuration: const Duration(milliseconds: 200),
children: _items
.map(
(item) => ExpansionPanel(
canTapOnHeader: true,
// backgroundColor: item['isExpanded'] == true ? Colors.cyan[100] : Colors.white,
headerBuilder: (context, isExpanded) {
return Container(
margin: const EdgeInsets.all(10),
child: Row(children: [
const CircleAvatar(
child: Text(
'1',
textAlign: TextAlign.center,
)),
const SizedBox(
width: 10,
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Nuggets',
style: TextStyle(color: Colors.black, fontWeight: FontWeight.w600),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: const [
Text(
'Unidades: ${7}',
style: TextStyle(color: Colors.black),
),
Text(
'Pendientes: 400',
style: TextStyle(color: Colors.black),
),
],
),
const SizedBox(
width: 20,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
'Precio: 10 €',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: Colors.black),
),
Text(
'Total: 70 €',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: Colors.black),
),
],
),
],
),
],
),
),
]),
);
},
body: ButtonBar(
alignment: MainAxisAlignment.spaceAround,
buttonHeight: 52.0,
buttonMinWidth: 90.0,
children: <Widget>[
TextButton(
style: flatButtonStyle,
onPressed: () {
setState(() {
item['unidades'] += 1;
});
},
child: Column(
children: const <Widget>[
Icon(
Icons.add,
color: AppTheme.grismedio,
),
// Padding(
// padding: EdgeInsets.symmetric(vertical: 2.0),
// ),
// Text('Más'),
],
),
),
TextButton(
style: flatButtonStyle,
onPressed: () {
setState(() {
item['unidades'] -= 1;
});
},
child: Column(
children: const <Widget>[
Icon(
Icons.remove,
color: AppTheme.grismedio,
),
// Padding(
// padding: EdgeInsets.symmetric(vertical: 2.0),
// ),
// Text('Menos'),
],
),
),
TextButton(
style: flatButtonStyle,
onPressed: () {},
child: Column(
children: const <Widget>[
Icon(
Icons.edit_outlined,
color: AppTheme.grismedio,
),
// Padding(
// padding: EdgeInsets.symmetric(vertical: 2.0),
// ),
// Text('Editar'),
],
),
),
TextButton(
style: flatButtonStyle,
onPressed: () {},
child: Column(
children: const <Widget>[
Icon(
Icons.delete_outline_outlined,
color: AppTheme.grismedio,
),
// Padding(
// padding: EdgeInsets.symmetric(vertical: 2.0),
// ),
// Text('Eliminar'),
],
),
),
TextButton(
style: flatButtonStyle,
onPressed: () {},
child: Column(
children: const <Widget>[
Icon(
Icons.card_giftcard_outlined,
color: AppTheme.grismedio,
),
// Padding(
// padding: EdgeInsets.symmetric(vertical: 2.0),
// ),
// Text('Invitar'),
],
),
)
],
),
isExpanded: item['isExpanded'],
),
)
.toList(),
// Card_lineaComanda(flatButtonStyle),
),
),
);
}
}
I 've edited the code to show all screen widget.
Image of result of code before:
For desktop applications, you can prevent the resize with breakpoint, so the error won't happen. In the pubsec.yaml file, add the following dependency.
window_size:
git:
url: https://github.com/google/flutter-desktop-embedding.git
path: plugins/window_size
And in your main method before runapp add this code with min-width and min-height below which the app won't resize.
const double desktopMinWidth = 800.0;
const double desktopMinHeight = 600.0;
if (Platform.isMacOS || Platform.isWindows) {
setWindowMinSize(const Size(desktopMinWidth, desktopMinHeight));
setWindowMaxSize(Size.infinite);
}
Note: Once done restart your app.
For mobile, it is entirely a different case. You might need to restructure the design
I am trying to use ImagePicker. When an image is selected, it is not displayed on the screen. Value seems to be null. Below, you will find the full source code. I have done some research, but I have not find what mistake I am doing. If you could point me in the right direction, it would be great and appreciated. Many thanks.
class CaptureV2 extends StatefulWidget {
CaptureV2({Key key}) : super(key: key);
#override
_CaptureV2State createState() => _CaptureV2State();
}
class _CaptureV2State extends State<CaptureV2> {
GlobalKey<FormState> _captureFormKey = GlobalKey<FormState>();
bool isOn = true;
String _valueTaskNameChanged = '';
String _valueTaskNameToValidate ='';
String _valueTaskNameSaved='';
File imageFile;
_openGallery(BuildContext context) async{
imageFile = await ImagePicker().getImage(source: ImageSource.gallery) as File;
this.setState(() {
});
}
_openCamera(BuildContext context) async {
imageFile = await ImagePicker().getImage(source: ImageSource.camera) as File;
this.setState(() {
});
}
Widget _showImageView(context){ //Even when I am selecting an image I always get null
if(imageFile ==null) {
return Text('No attachment');
}else{
return Image.file(imageFile, width: 200, height: 200,);
}
}
#override
Widget build(BuildContext context) {
return Material(
child: Scaffold(
drawer: MyMenu(),
appBar: AppBar(
centerTitle: true,
title: Text('CAPTURE'),
actions: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(0,22,0,0),
child: Text("On/Off"),
),
Switch(
value: isOn,
onChanged: (value) {
setState(() {
isOn = value;
});
},
activeTrackColor: Colors.green,
activeColor: Colors.green,
),
],
),
//==================
body: isOn?
SingleChildScrollView(
child: Column(
// crossAxisAlignment: CrossAxisAlignment.end,
// mainAxisAlignment: MainAxisAlignment.end,
children: [
Form(
key: _captureFormKey,
child: Column(
// crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(8.0, 0.0, 15.0, 1.0),
child: TextFormField(
decoration: InputDecoration(hintText: "Task Name"),
maxLength: 100,
maxLines: 3,
onChanged: (valProjectName) => setState(() => _valueTaskNameChanged = valProjectName),
validator: (valProjectName) {
setState(() => _valueTaskNameToValidate = valProjectName);
return valProjectName.isEmpty? "Task name cannot be empty" : null;
},
onSaved: (valProjectName) => setState(() => _valueTaskNameSaved = valProjectName),
),
),
SizedBox(
height: 50.0,
),
//########ATTACHEMENT & PHOTOS
Card(
child:
Container(
// color: Colors.red,
alignment: Alignment.center,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children:[
//Attachement
FlatButton(
onPressed: () {
},
child:
InkWell(
child: Container(
// color: Colors.white,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.attach_file),
Text('Attachement'),
],
)
),
onTap: () {
_openGallery(context);
},
),
),
//Photo
FlatButton(
onPressed: () {(); },
child:
InkWell(
child: Container(
// color: Colors.white,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.add_a_photo_rounded),
Text('Photo'),
],
)
),
onTap: () {
},
),
),
//Voice Recording
FlatButton(
onPressed: () { },
child:
InkWell(
child: Container(
// color: Colors.white,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ConstrainedBox(
constraints: BoxConstraints(
minWidth: iconSize,
minHeight: iconSize,
maxWidth: iconSize,
maxHeight: iconSize,
),
child: Image.asset('assets/icons/microphone.png', fit: BoxFit.cover),
),
Text('Recording'),
],
)
),
onTap: () {
MyApp_AZERTY();
},
),
),
],
),
)
),
]
),
),
Container(
child:
_showImageView(context)
),
SizedBox(
height: 150.0,
),
//CANCEL & SAVE
Container(
decoration: const BoxDecoration(
border: Border(
top: BorderSide(width: 1.0, color: Colors.grey),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Container(
child:
FlatButton(
child: Text("Cancel",style: TextStyle(
fontSize: 18.0,fontWeight: FontWeight.bold,color: Colors.grey
)
),
onPressed: (){
final loForm = _captureFormKey.currentState;
loForm.reset();
},
),
),
Container(
child: FlatButton(
child: Text("Save",style: TextStyle(
fontSize: 18.0,fontWeight: FontWeight.bold,color: Colors.blue
)),
// Border.all(width: 1.0, color: Colors.black),
onPressed: (){}
loForm.reset();
showSimpleFlushbar(context, 'Task Saved',_valueTaskNameSaved, Icons.mode_comment);
}
loForm.reset();
},
),
),
]
),
),
],
),
) :
The problem is getImage does not return a type of file, but a type of
Future<PickedFile>
So you need to do the following.
final image = await ImagePicker().getImage(source: ImageSource.gallery);
this.setState(() {
imageFile = File(image.path);
});
How can i make one time choice custom radio button like in the picture
import 'package:flutter/material.dart';
class HomeScreen extends StatefulWidget {
#override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
int _selection = 0;
selectTime(int timeSelected) {
setState(() {
_selection = timeSelected;
});
}
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(
title: Text("Home"),
),
body: Container(
padding: EdgeInsets.all(30),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
InkWell(
onTap: () {
setState(() {
_selection = 1;
});
},
child: Stack(
children: <Widget>[
Container(
height: 40,
width: 150,
color: _selection == 1 ? Colors.green : Colors.white,
),
Row(
children: <Widget>[
Radio(
focusColor: Colors.white,
groupValue: _selection,
onChanged: selectTime,
value: 1,
),
Text(
"11:00 - 12:00",
style: TextStyle(fontWeight: FontWeight.bold),
),
],
),
],
),
),
InkWell(
onTap: () {
setState(() {
_selection = 2;
});
},
child: Stack(
children: <Widget>[
Container(
height: 40,
width: 150,
color: _selection == 2 ? Colors.green : Colors.white,
),
Row(
children: <Widget>[
Radio(
focusColor: Colors.white,
groupValue: _selection,
onChanged: selectTime,
value: 2,
),
Text(
"12:00 - 13:00",
style: TextStyle(fontWeight: FontWeight.bold),
),
],
),
],
),
)
],
),
],
)),
));
}
}