flutter Dismissible widget variable dependency - background

Edit: Fixed it.. Look down
Old problem:
I am experimenting with the Dismissible widget.
I can successfully monitor the state of the direction, which is stored in directionVar.
It outputs something like DismissDirection.endToStart
I want to use this information, to change the placement of the icon that I show.
When removing an item, the background is red, with an icon on the right to it. Something in the style like Gmail.
Widget build(BuildContext context) {
DismissDirection directionVar;
return ListView.builder(
itemBuilder: (BuildContext context, int index) {
return Dismissible(
key: Key(products[index]['title']), //Should be unique.
onDismissed: (DismissDirection direction) {
directionVar = direction;
},
My issue is this part:
background: Container(
color: Colors.red,
padding: EdgeInsets.only(left: 20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Icon(
Icons.delete,
)
],
),
),);});}
I want this part to change dependent on the directionVar value.
The padding should change dependent on the value of directionVar, together with the mainAxisAlignment.
Something along these lines:
if(directionVar == DismissDirection.endToStart){
} else if (directionVar == DismissDirection.startToEnd){
}
But I can't access the background: and padding property in these statements, since they are a property of the Dismissible widget and can't be changed inside onDismissed(){}
This seems like simple problem but can't seem to solve it.
Edit: Fixed it.. Very easy.. Just added this:
secondaryBackground: Container(
color: Colors.red,
padding: EdgeInsets.only(right: 20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Icon(
Icons.delete,
)
],
),
),

There are a few ways that you can achieve this. For example, you can create a method that handles the direction dynamically and then update it accordingly in your widget tree. Something like
List<dynamic> _resolveDirection(DismissDirection direction) {
switch (direction) {
case DismissDirection.endToStart:
return [MainAxisAlignment.center, 20.0];
break;
case DismissDirection.startToEnd:
return [MainAxisAlignment.start, 10.0];
break;
case DismissDirection.vertical:
return [MainAxisAlignment.end, 5.0];
break;
// And so on...
default:
return [];
}
}
and then replace your tree with
background: Container(
color: Colors.red,
padding: _resolveDirection(directionVar)[1],
child: Row(
mainAxisAlignment: _resolveDirection(directionVar)[0],
children: <Widget>[
Icon(
Icons.delete,
)
],
),
),);});}
In the end, all you have to do everytime a swipe occurs, is just rebuild your tree with the direction updated
setState(() => directionVar = direction);

Related

Style teaching bubble with different background color than it's coachmark

I am using a teaching bubble inside a coach mark, same as the example in here
enter link description here
How can I have the teaching bubble in white instead of blue?
You can pass in the styles prop to the TeachingBubbleContent that contain this object:
{
closeButton: {
color: 'red',
selectors: {
':hover': {
background: 'gainsboro',
color: 'red'
},
':active': {
background: 'darkGray',
color: 'red'
}
}
},
content: {
border: '1px solid black',
background: 'white',
},
headline: {
color: 'black'
},
subText: {
color: 'black'
}
}
Example here in this codepen: https://codepen.io/vitalius1/pen/xoEPzg.
The only thing thing you can't do easily is to change the Coachmark's drop color in a way that is still visible. You can try by passing color prop to it and specify white, but because there is no border or shadow around the drop all you'll see is the beacon animation. And if you try give it a border it won't look nice (see codepen) because of how the drop is constructed. Also, there is currently a bug in passing the beaconColorOne and beaconColorTwo props to change the beacon color that I am fixing right now :)
Hope that helps!

Can Office Fabric DetailsList column headers be styled?

I was looking through the office fabric documentation, there seems to be clear information on how to style the items/content inside the DetailsList (https://developer.microsoft.com/en-us/fabric#/components/detailslist/customitemcolumns has an example) but no information on how to style the column headers (or if it's possible).
It seems like a pretty common use case (I'm trying to center my column headers instead of having them left aligned and make them larger), so not sure if I'm just missing something?
One option to customize column headers would be to override the rendering of headers via onRenderDetailsHeader event and then render header tooltip with a custom styling as demonstrated below
<DetailsList
items={sortedItems as any[]}
setKey="set"
columns={columns}
onRenderDetailsHeader={this.renderDetailsHeader}
/>
private renderDetailsHeader(detailsHeaderProps: IDetailsHeaderProps) {
return (
<DetailsHeader
{...detailsHeaderProps}
onRenderColumnHeaderTooltip={this.renderCustomHeaderTooltip}
/>
);
}
private renderCustomHeaderTooltip(tooltipHostProps: ITooltipHostProps) {
return (
<span
style={{
display: "flex",
fontFamily: "Tahoma",
fontSize: "14px",
justifyContent: "center",
}}
>
{tooltipHostProps.children}
</span>
);
}
Demo
You can style the columns headers with the IDetailsColumnStyles interface.
Example:
...
const headerStyle: Partial<IDetailsColumnStyles> = {
cellTitle: {
color: "#c00"
}
}
const columns: IColumn[] = [
{ styles: headerStyle, key: 'name', name: 'Name', fieldName: 'name', minWidth: 120 },
...
Look at the definition of IDetailsColumnStyles to see what can be styled.
The IColumn interface has a property named headerClassName which can be used to style the column header. Example:
/* CSS */
.headerClass > span {
/* right aligned header should have padding */
padding-right: 15px;
}
.headerClass span {
/* bolder font */
font-weight: 900;
/* Right Align the column header */
justify-content: flex-end;
text-align: right;
/* green color */
color: green;
/* background color */
background: pink;
}
//JSX
const columns = [
{
key: 'column1',
name: 'Name',
fieldName: 'name',
minWidth: 100,
maxWidth: 200,
isResizable: true,
heaerClassName: 'headerClass',
},
{
key: 'column2',
name: 'Value',
fieldName: 'value',
minWidth: 100,
maxWidth: 200,
isResizable: true,
},
];
<DetailsList
items={items}
columns={columns}
setKey='set'
/>
Demo

Why can't I print out an image on flutter?

By using the following code, I'm unable to print out the same results as the example I've listed. Does anyone know why?
My code What I'm actually gettingWhat it should look like
First, ensure that you added the reference of your image inside the file pubspec.yaml (I guess you have a typo btw -> assets instead of assests
flutter:
assets:
- assets/vegetables.jpg
After that I added some properties to your Column widget
mainAxisSize: MainAxisSize.min,
To avoid your Column fill all the space in vertical, it's like wrap_content in Android
crossAxisAlignment: CrossAxisAlignment.stretch
To expand the child full width.
textAlign: TextAlign.center
To align the text to the center
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("FBLA Quizz!!"),
),
body: Card(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Image.asset("assets/vegetables.jpg"),
Text(
"Food Paradise",
textAlign: TextAlign.center,
)
],
),
),
);
}

Automatic row wrapping on elements in QML layout

Is there a QML layout or some configuration that will automatically wrap QML items to the next row if the width of the next element exceeds the width of the specified layout?
When I use a QML GridLayout, the items just go off the edge of the window and are clipped:
GridLayout {
id: header_focused_container;
width: parent.width;
anchors.margins: 20;
Text {
text: "header_focused_container.width=" +
header_focused_container.width +
" and my width is =" + width
}
Rectangle { height:20; width:250; color: "red" }
Rectangle { height:20; width:250; color: "blue" }
Rectangle { height:20; width:250; color: "green" }
}
When I look at Qt's documentation page labeled "Scalability" I see very manual scaling going on. Basically, they're suggesting that I need compute the needed columns.
Is there some sort of layout type or configuration that will do auto-wrapping of the items?
You can use Flow:
import QtQuick 2.5
import QtQuick.Window 2.0
Window {
visible: true
width: 400
height: 200
Flow {
id: header_focused_container
anchors.fill: parent
Text {
text: "blah"
}
Rectangle { height:20; width:250; color: "red" }
Rectangle { height:20; width:250; color: "blue" }
Rectangle { height:20; width:250; color: "green" }
}
}

How to enable button focus on touchStart?

I have created a button, I need some response from button like, on touch of the button, the button focus should enable like change in background color. How can I do that?
My code is,
View:
<Button class="button" id="proceedButton" onClick="openQuestionnaire">Proceed</Button>
Style:
".button":{
width: '50%',
top: '25dp',
borderRadius: 8,
borderWidth: 1,
borderColor: '#808080',
backgroundGradient: {
type: "linear",
startPoint: { x: "0%", y:"0%"},
endPoint: { x: "0%", y:"100%"},
colors: [
{ color: "#4F94CD", offset: 0.0 },
{ color: "#4F94CD", offset: 1.0 }
]
}
}
Controller:
$.proceedButton.addEventListener('touchstart', function() {
$.proceedButton.isFocused = true;
});
$.proceedButton.addEventListener('touchend', function() {
$.proceedButton.isFocused = false;
});
The above code is not working. Just I need to slight chage in background color while touch of the button.
Any solution!!
Use this property and pass colour code
backgroundSelectedColor : "RED"
focusable must be true for normal views.
for more you can refer this http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.Button-property-backgroundSelectedColor
I hope it may help you,
Alloy xml would be like this
<Button class="button" id="proceedButton" onClick="openQuestionnaire">Proceed</Button>
Then the button property would be like this
".button":{
width: '50%',
top: '25dp',
borderRadius: 8,
borderWidth: 1,
borderColor: '#808080',
backgroundSelectedColor : "red",
backgroundSelectedImage : "/my_image.png",
backgroundGradient: {
type: "linear",
startPoint: { x: "0%", y:"0%"},
endPoint: { x: "0%", y:"100%"},
colors: [
{ color: "#4F94CD", offset: 0.0 },
{ color: "#4F94CD", offset: 1.0 }
]
}
}
You can set your selected image or background color on touch focus.
You wont need the controller code you have written in the controller.
Also for some object you can also have selectedColor.
You can also set backgroundFocusedImage,
As #CodeForFun mentioned you can use backgroundSelectedColor property of button.
Also following are all the states which can be used by a button in Titanium.
Disabled : backgroundDisabledImage and backgroundDisabledColor
Normal : backgroundImage and backgroundColor
Focus : backgroundFocusedImage and backgroundFocusedColor
Selected : backgroundSelectedImage and backgroundSelectedColor
Hope this would be helpful.
Edit : An example of usage:
View :
<Button class="button" >Proceed</Button>
TSS :
".button":{
width: '50%',
top: '25dp',
backgroundSelectedColor : "#4F94CD" //usage
}