Want capture image remain in container of flutter app - android

I have three tab. One of the tab is for edit photo page (retrieve image which already have in API, edit and return capture image to API with Update button in that page). All is work and fine. But after capture image with camera, and change to other tab and return back to this tab (in this state not save), Already capture image not show and only API image show. I capture again to save. I want to remain the capture image in container although I don't save to API and change tab.
This is picture of my app contain tab bar view which contain edit image tab bar
This is my tab bar view dart file.
var width = MediaQuery.of(context).size.width;
final tabText = TextStyle(fontSize: width * 0.03);
return Scaffold(
appBar: new AppBar(
title: new Text(
'EDIT CLIENT',
style: new TextStyle(color: accentColor, fontFamily: 'Dosis'),
),
bottom: PreferredSize(
preferredSize: Size(40, 40),
child: Container(
height: getScreenHeightRation(40.0),
decoration: BoxDecoration(
color: Color(0xFFF0C185),
border: Border.all(color: Colors.grey[600]),
//0xFFF0C185
),
child: TabBar(
indicatorPadding: EdgeInsets.symmetric(horizontal: 40),
//isScrollable: true,
//change here
labelPadding: EdgeInsets.only(left: 10),
indicatorSize: TabBarIndicatorSize.tab,
indicatorColor: Colors.transparent,
indicator: BoxDecoration(
color: Color(0xFFD2A368),
),
tabs: [
Container(
decoration: BoxDecoration(
border: Border(right: BorderSide(color: Colors.grey))),
child: Tab(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ImageIcon(
AssetImage('assets/images/icon_ext/menu.png'),
size: 12,
),
SizedBox(
width: 5.0,
),
Text('Customer Data',style: tabText, ),
],
),
),
),
Container(
decoration: BoxDecoration(
border: Border(right: BorderSide(color: Colors.grey))),
child: Tab(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ImageIcon(
AssetImage('assets/images/icon_ext/image.png'),
size: 12,
),
SizedBox(
width: 5.0,
),
Text('Profile',style: tabText, )
],
),
),
),
Container(
child: Tab(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ImageIcon(
AssetImage('assets/images/icon_ext/placeholder.png'),
size: 12,
),
SizedBox(
width: 5.0,
),
Text('Location',style: tabText, )
],
),
),
)
],
controller: tabController,
),
),
),
iconTheme: new IconThemeData(color: accentColor),
centerTitle: true,
),
body: TabBarView(
controller: tabController,
children: [
EditClientInformation(
customerNo: widget.customerNo,
branchId: _branchId,
defaultBranchId: _defaultBranchId,
userId: _userId,
systemFormatDate: _systemFormatDate,
),
EditClientProfile(
customerNo: widget.customerNo,
branchId: _branchId,
defaultBranchId: _defaultBranchId,
userId: _userId,
systemFormatDate: _systemFormatDate,
),
EditClientMap(
customerNo: widget.customerNo,
branchId: _branchId,
defaultBranchId: _defaultBranchId,
userId: _userId,
systemFormatDate: _systemFormatDate,
),
],
),
);
}
This is capture image tab.
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Stack(
children: [
Container(
width: 300.0,
height: 170.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(20)),
border:
Border.all(width: 1, style: BorderStyle.solid),
),
child: Center(
child: Container(
width: 170.0,
height: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(20),
topLeft: Radius.circular(10),
bottomLeft: Radius.circular(10),
bottomRight: Radius.circular(10)),
//border: Border.all(width: 1, style: BorderStyle.solid),
image: DecorationImage(
image: _profileCaptImg == ""
? NetworkImage(_profileImg)
: FileImage(profile),
fit: BoxFit.cover,
),
),
),
),
),
Positioned(
right: 62.0,
top: 0.0,
child: _profileCaptImg != ''
? GestureDetector(
onTap: () {
setState(() {
profile = null;
_profileCaptImg = '';
});
},
child: Container(
width: 20.0,
height: 20.0,
child: Icon(
Icons.close,
color: Colors.white,
size: 20.0,
),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.black,
),
),
)
: Container(),
),
],
),
Container(
width: 50.0,
height: 50.0,
child: FloatingActionButton(
onPressed: profileImgPicker,
heroTag: null,
child: new Icon(Icons.camera_alt),
)),
],
),

Try this solution:
/// Add with AutomaticKeepAliveClientMixin:
class _YourWidgetState extends State<YourWidget> with AutomaticKeepAliveClientMixin {
/// Add these 2 lines:
#override
bool get wantKeepAlive => true;
/// Add super.build(context) to your build method
#override
Widget build(BuildContext context) {
super.build(context);
return YourWidgets();
}
}

Related

How can I add an Icon to to Box Decoration?

I want to add an Icon to Box Decoration like this you are seeing images on left side.
How do I add this with box decoration
Here is the code:
Container(
width: 307,
decoration: BoxDecoration(
border: Border.all(color: Colors.blueAccent),
borderRadius: BorderRadius.circular(10.0),
shape: BoxShape.rectangle,
),
child: CountryListPick(
onChanged: (list){
print(list?.name);
},
theme: CountryTheme(
labelColor: Colors.white,
isShowFlag:true,
isShowCode: false,
isShowTitle:true,
isDownIcon: true,
showEnglishName: true,
),
),
),
You can use this widget for a textfield with boxdecoration and icon:
TextFormField(
key: Key(key),
controller: controller,
decoration: InputDecoration(
prefixIcon: Icon(icon), // <-- left icon
hintText: hintText,
border: OutlineInputBorder( //<--- decoration border
borderRadius: BorderRadius.all(Radius.circular(90.0)),
borderSide: BorderSide.none,
),
filled: true,
),
)
You can use a row as a children of container
Container(
width: 307,
decoration: BoxDecoration(
border: Border.all(color: Colors.blueAccent),
borderRadius: BorderRadius.circular(10.0),
shape: BoxShape.rectangle,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Flexible(
child: Image.asset(
"assets/images/cover_placeholder.png",
height: 30,
width: 30,
fit: BoxFit.contain,
),
),
SizedBox(width: 12,),
Flexible(
child: CountryListPick(
onChanged: (list){
print(list?.name);
},
theme: CountryTheme(
labelColor: Colors.white,
isShowFlag:true,
isShowCode: false,
isShowTitle:true,
isDownIcon: true,
showEnglishName: true,
),
),
),
],
),
),
So you can use SizedBox or Container -
SizedBox(
width: 300.0,
height: 120.0,
child: Padding(
padding: const EdgeInsets.all(5.0),
child: Container(
child: Row(
children: <Widget>[
Material(
type: MaterialType.transparency,
child: Stack(
children: <Widget>[
Column(
children: <Widget>[
Container(
padding: const EdgeInsets.only(
top: 1.0, bottom: 1.0, right: 5.0),
height: 50.0,
width: 50.0,
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(15.0),
color: Colors.green[50],
),
child: IconButton(
icon: Icon(Icons.favorite),
color: Colors.red[700],
highlightColor: Colors.red,
onPressed: () {},
),
),
],
),
],
),
),
],
),
),
),
),

Container text and icons alignment- need to align this icon to right of this container

I need to make this favourite icon to the right of the container. I can use padding but is it ok? I mean is it going to work with all devices. Is there any solid way to align these 3 containers? I made a list view because I am adding more stuff like this one. can you guys help me with this?
Here is the image
Here is my code
class _OrdersState extends State<Orders> {
#override
Widget build(BuildContext context) {
return Material(
child: SafeArea(
child: Stack(
children: [
Background(),
Positioned(
top: 10,
left: 5,
child: SizedBox(
// width: 10,
// height: 10,
child: Container(
color: Colors.transparent,
child: IconButton(
icon: Icon(Icons.arrow_back),
color: Colors.white,
//go back
onPressed: () => Navigator.of(context).pop(),
),
),
),
),
Positioned(
top: 90,
left: 22,
right: 22,
child: SizedBox(
width: 350,
height: 900,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
topRight: Radius.circular(10),
),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 3,
blurRadius: 7,
),
],
),
child: Row(
children: [
Container(
color: Colors.blue,
margin: EdgeInsets.all(2),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'3:32',
style: TextStyle(fontSize: 20),
),
),
),
Container(
color: Colors.red,
child: Text(
'Order 1',
style: TextStyle(fontSize: 20),
),
),
Container(
color: Colors.amber,
child: Icon(Icons.favorite),
)
],
),
),
),
),
],
),
),
);
}
}
In the Row try to use and Expanded widget like this
Row(
children: [
Expanded(
child: Row(
children: [
Container(
color: Colors.blue,
margin: EdgeInsets.all(2),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'3:32',
style: TextStyle(fontSize: 20),
),
),
),
Container(
color: Colors.red,
child: Text(
'Order 1',
style: TextStyle(fontSize: 20),
),
),
],
),
),
Container(
color: Colors.amber,
child: Icon(Icons.favorite),
)
],
)

flutter: Add a Text at the bottom of Scaffold

I am new to flutter. In my home screen I want to add a text at the bottom of the Screen displayed
home page code
Scaffold buildUnAuthScreen(){
return Scaffold(
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
colors: [
Theme.of(context).accentColor,
Theme.of(context).primaryColor,
]
),
),
alignment: Alignment.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text('FriendsHive',
style: TextStyle(
fontFamily: 'Signatra',
fontSize: 90.0,
color: Colors.white,
) ,
),
GestureDetector(
onTap: login,
child: Container(
width: 260.0,
height: 60.0,
decoration: BoxDecoration(
image: DecorationImage(image: AssetImage('assets/images/google_signin_button.png'),
fit: BoxFit.cover,
),
),
),
),
],
),
),
);
}
result
In this screen I want to add a text that will be displayed at the bottom. I tried an example but when I apply that, text is shown at bottom but the main text and the button goes up, I don't want that to happen.
you can use this code
Expanded(
child: Align(
alignment: FractionalOffset.bottomCenter,
child: Text('You can try'),
),
),
or
bottomNavigationBar: BottomAppBar(
color: Colors.transparent,
child: Text('something'),
elevation: 0,
),
you can wrap your column with stack and in stack use positioned widget like code below
Scaffold(
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
colors: [
Theme.of(context).accentColor,
Theme.of(context).primaryColor,
]),
),
alignment: Alignment.center,
child: Stack(
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
'FriendsHive',
style: TextStyle(
fontFamily: 'Signatra',
fontSize: 90.0,
color: Colors.white,
),
),
GestureDetector(
onTap: () {},
child: Container(
width: 260.0,
height: 60.0,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/images/google_signin_button.png'),
fit: BoxFit.cover,
),
),
),
),
],
),
Positioned(
bottom: 0,
right: 0,
left: 0,
child: Center(child: Text('test')),
)
],
)),
);

I have a problem with the spaces on Flutter

I can't understand what I'm doing wrong.
I have created a small detail page for an application that I am developing on vegan recipes.
I have a space that I can't take away and I don't understand what generated it. Space is what you see circled in red.
Can you help me ?
Thank you,
Vincenzo
class _CookDetailState extends State<CookDetail> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: IconButton(
icon: Icon(Icons.arrow_back, color: Colors.white),
onPressed: () => Navigator.of(context).pop(),
),
title: Text(this.widget.ricetta.title),
backgroundColor: AppColors.darkModeBackgroundColor),
body: Stack(
children: <Widget>[
Positioned(
top: 0,
left: 0,
right: 0,
bottom: 0,
child: Hero(
tag: this.widget.ricetta.title,
child: Container(
decoration:
BoxDecoration(image: DecorationImage(image: NetworkImage("https://cdn.pixabay.com/photo/2017/09/16/19/21/salad-2756467__340.jpg"),
fit: BoxFit.cover)),
),
),
),
// white container
Positioned(
left: 24.0,
right: 24.0,
bottom: 16.0,
child: Container(
//height: MediaQuery.of(context).size.height * 0.75,
//height: 650,
child: ClipRect(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 100, sigmaY: 200),
child: Container(
padding: EdgeInsets.all(16.0),
height: 500,
decoration: BoxDecoration(borderRadius: BorderRadius.circular(16.0), color: Colors.white.withOpacity(0.2)),
child: SingleChildScrollView(
child: Container(
padding: EdgeInsets.all(16.0),
height: 800,
decoration: BoxDecoration(borderRadius: BorderRadius.circular(16.0), color: Colors.white.withOpacity(0.2)),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[
Text(
this.widget.ricetta.title,
style: TextStyle(color: Colors.white, fontSize: 20.0, fontWeight: FontWeight.bold),
),
Spacer(),
Icon(
Icons.favorite_border,
size: 24.0,
color: Colors.white,
),
],
),
new Container(
child: ListView(
shrinkWrap: true,
children: <Widget>[
this._generateList(this.widget.ricetta.listIngredieti),
this._generateStep(this.widget.ricetta.listPassaggio),
],
),
),
],
),
),
),
),
),
),
),
),
],
),
);
}
Widget _generateList(List<Ingrediente> listIngrediente){
return Column(
children: <Widget>[
for ( var myElement in listIngrediente ) Text(
myElement.title + " " + myElement.quantita,
style: TextStyle(color: Colors.white, fontSize: 12, fontWeight: FontWeight.w600))
],
);
}
Widget _generateStep(List<StepRicetta> listStep){
return Column(
children: <Widget>[
for (var myStep in listStep) CheckboxListTile(title: AutoSizeText(myStep.title),
value: false, onChanged: (bool selected){
print("Valore selected");
},
secondary: const Icon(Icons.hourglass_empty),
)
],
);
}
}
My concept would be to leave the writing "Recipe 1", blocked, scrolling only and exclusively the list concerning the list of ingredients, such as "Put the bread", "Put 300 g of water"
I think your second EdgeInsets.all(16.0) create the space, do you have try this : EdgeInset.only(left: 16.0, right: 16.0) ?

SingleChildScrollView height to max height with image background in flutter

In the Login screen, there is a background image and all stuff will be scrollable but SingleChildScrollView is not showing macth_parent height. My aim is to design like here
class MyLoginOne extends StatelessWidget {
#override
Widget build(BuildContext context) {
return new Scaffold(
body: new Container(
decoration: new BoxDecoration(
image: new DecorationImage(
fit: BoxFit.cover,
image:new NetworkImage('https://i.pinimg.com/originals/c2/47/e9/c247e913a0214313045a8a5c39f8522b.jpg')
)
),
child: new BackdropFilter(
filter:new ImageFilter.blur(sigmaX: 1.1,sigmaY:1.1),
child: new Container(
decoration: new BoxDecoration(color: Colors.black45.withOpacity(0.5)),
child: new SingleChildScrollView(
child: new Container(
child: new Column(
children: <Widget>[
new Container(
height: 200.0,
child: new Stack(
children: <Widget>[
new Align(
alignment: AlignmentDirectional.center,
child:new Container(
height: 120.0,
width: 120.0,
decoration: new BoxDecoration(
shape: BoxShape.circle,
color: Colors.white30
),
)
),
new Align(
alignment: AlignmentDirectional.center,
child: new Container(
child: new Text("Farha",style: new TextStyle(
color: Colors.white,
fontSize: 14.0,
fontFamily: "WorkSansLight"
),),
),),],))],),),)),), ));}}
my circle container height is about 200.0 but SingleChildScrollView is not showing full height.
Code of the required layout - its not 100% but get the job Done. You can Complete it as required.
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: <Widget>[
Container(
decoration: new BoxDecoration(
image: new DecorationImage(
fit: BoxFit.cover,
image: new NetworkImage(
'https://i.pinimg.com/originals/c2/47/e9/c247e913a0214313045a8a5c39f8522b.jpg'))),
),
Center(
child: SingleChildScrollView(
padding: EdgeInsets.all(30.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
CircleAvatar(
radius: 58.0,
child: Text('Travel'),
),
SizedBox(
height: 20.0,
),
TextFormField(
decoration: InputDecoration(
prefixIcon: Icon(
Icons.person,
color: Colors.white,
),
hintStyle: TextStyle(color: Colors.white),
filled: true,
fillColor: Colors.black45,
hintText: 'Username'),
),
SizedBox(
height: 10.0,
),
TextFormField(
decoration: InputDecoration(
filled: true,
prefixIcon: Icon(Icons.lock, color: Colors.white),
hintStyle: TextStyle(color: Colors.white),
fillColor: Colors.black45,
hintText: 'Password'),
),
SizedBox(
height: 15.0,
),
FlatButton(
onPressed: () {},
child: Text(
'Forgot your Password?',
style: TextStyle(color: Colors.white),
)),
SizedBox(
height: 15.0,
),
RaisedButton(
onPressed: () {},
child: Padding(
padding: EdgeInsets.all(15.0),
child: Text('LOGIN')),
color: Colors.redAccent,
textColor: Colors.white,
),
SizedBox(
height: 10.0,
),
RaisedButton(
onPressed: () {},
child: Padding(
padding: EdgeInsets.all(15.0),
child: Text('REGISTER')),
color: Colors.grey,
textColor: Colors.white,
),
SizedBox(
height: 12.0,
),
Row(
children: <Widget>[
Expanded(
child: Divider(
color: Colors.white,
height: 8.0,
),
),
SizedBox(
width: 8.0,
),
Text(
'OR',
style: TextStyle(color: Colors.white),
),
SizedBox(
width: 8.0,
),
Expanded(
child: Divider(
color: Colors.white,
height: 8.0,
),
)
],
),
Row(
children: <Widget>[
// TODO Social Icons
],
),
],
),
),
),
],
),
);
}
OutPut:
A Container widget will size themselves to its child, unless specified.
In your case:
...
Container(
height: double.infinity, // <-----
decoration: new BoxDecoration(
image: new DecorationImage(
fit: BoxFit.cover,
image: new NetworkImage(
'https://i.pinimg.com/originals/c2/47/e9/c247e913a0214313045a8a5c39f8522b.jpg')))
...

Categories

Resources