Add image to listview from Gallery in Flutter/dart - flutter

This is currently what I have achived,
#override
Widget build(BuildContext context) {
_height = MediaQuery.of(context).size.height;
return Scaffold([![enter image description here][1]][1]
resizeToAvoidBottomInset: false,
extendBodyBehindAppBar: true,
appBar: AppBar(
leading: GestureDetector(
child: Image.asset('graphics/back_arrow.png'),
onTap: () {
Get.back();
},
),
backgroundColor: Colors.transparent,
elevation: 0,
title: Text(
'Ask The Internet',
style: GoogleFonts.montserrat(
fontSize: 20,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.bold,
color: Colors.white),
),
),
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("graphics/login.png"),
fit: BoxFit.cover,
),
),
child: Column(
children: [
Container(
width: double.infinity,
height: _height * 0.15,
),
Container(
padding:
EdgeInsets.only(top: 64, left: 16, right: 16, bottom: 16),
height: _height * 0.85,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(64),
topRight: Radius.circular(64),
),
),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Align(
alignment: Alignment.center,
child: Text(
'Ask The Internet',
style: GoogleFonts.montserrat(
fontSize: 16,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.w600,
color: loginPageTitleColor),
),
),
SizedBox(
height: _height * 0.04,
),
Text(
'Upload Content for UP',
style: GoogleFonts.montserrat(
fontSize: 14,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.normal,
color: askInternetPageTitleColor),
),
SizedBox(
height: _height * 0.01,
),
Row(
children: [
GestureDetector(
child: Image.asset('graphics/add.png'),
onTap: () {
_pickImages();
},
),
],
),
Align(
alignment: Alignment.center,
child: Image.asset('graphics/divider.png')),
SizedBox(
height: _height * 0.04,
),
Text(
'Upload Content for DOWN',
style: GoogleFonts.montserrat(
fontSize: 14,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.normal,
color: askInternetPageTitleColor),
),
SizedBox(
height: _height * 0.01,
),
Image.asset('graphics/add.png'),
Align(
alignment: Alignment.center,
child: Image.asset('graphics/divider.png')),
SizedBox(
height: _height * 0.06,
),
TextFieldInput(
titleText: 'Text up to 140 characters',
hintText: 'Enter Question',
inputType: TextInputType.visiblePassword,
textEditingController: controller.questionController,
titleTextStyle: GoogleFonts.montserrat(
fontSize: 15,
fontWeight: FontWeight.normal,
color: editProfivePageTitleColor),
),
SizedBox(
height: _height * 0.04,
),
Align(
alignment: Alignment.center,
child: Text(
'Ask The Community',
style: GoogleFonts.montserrat(
fontSize: 16,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.w600,
color: loginPageTitleColor),
),
),
SizedBox(
height: _height * 0.04,
),
Text(
'Select The Community',
style: TextStyle(fontSize: 20, color: Colors.black38),
),
Obx(
() => DropdownButton<CommunityItem>(
isExpanded: true,
value: controller.item.value,
items:
controller.communityRows.map((CommunityItem value) {
return DropdownMenuItem<CommunityItem>(
value: value,
child: Text(value!.name!),
);
}).toList(),
onChanged: (value) {
controller.item.value = value!;
},
),
),
SizedBox(
height: _height * 0.04,
),
GestureDetector(
child: Container(
width: double.maxFinite,
height: 55,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(4.0),
),
color: Colors.black,
image: DecorationImage(
image: AssetImage("graphics/btn.png"),
fit: BoxFit.cover),
),
child: Center(
child: Text(
"Save",
style: GoogleFonts.montserrat(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.white),
),
) // button text
),
onTap: () {
print("you clicked me");
},
),
],
),
),
),
],
),
),
);
}
I want when user click on plus icon he can add images from gallery, just like this.
I tried to use Listview builder but it was not prefect.

Related

Flutter remove extra space left and right of appbar

So I have been trying to work around this but couldn't I have a search box inside my appbar in flutter and I have a PreferredSize to help with the height my I have extra space as shown with the blue line in the image below. Can someone help on how to remove this padding-like space as I want the content to align with the content below the search box? Below is the screenshot and my code snippet.
appBar: PreferredSize(
preferredSize: Size.fromHeight(40.0),
// here the desired height
child: AppBar(
centerTitle: true,
backgroundColor: colorGreen,
title: Container(
height: 35,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
),
child: Center(
child: SizedBox(
height: 40,
width: double.infinity,
child: Row(
children: <Widget>[
// Expanded(
Container(
padding: EdgeInsets.only(bottom:6),
width: 240,
alignment: Alignment.centerLeft,
child: TextField(
readOnly: true,
onTap: (){
},
textAlign: TextAlign.left,
controller: controller,
cursorColor: Colors.grey,
style: TextStyle(
color: Colors.grey,
fontSize: 16,
fontFamily: 'Montserrat'),
onChanged:
onSearchTextChanged,
decoration: InputDecoration(
hintText: "Search",
hintStyle: TextStyle(
color: Colors.grey,
fontSize: 13,fontWeight: FontWeight.normal,
fontFamily:
'Montserrat'),
border: InputBorder.none,
prefixIcon: Container(
padding: EdgeInsets.only(top: 5),
child:Icon(
Icons.search,
color: Colors.grey,
size: 15,
)),
suffixIcon: Visibility(
visible: backClear,
child:InkWell(
onTap: () {
},
child: Container(
padding: EdgeInsets.only(top: 5),
child:Icon(
Icons.backspace,
color: Colors.grey,
size: 12,
)))),
labelStyle: TextStyle(
color: Colors.grey,
fontSize: 14,fontWeight: FontWeight.normal,
fontFamily:
'Montserrat'),
// hintText:Center(child: Text(""),), //contentPadding: EdgeInsets.only(top: 2),
),
),
),
new Container(
width: 2.0,
height: 100.0,
color: colorGreen,
),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.center,
child: new Theme(
data: Theme.of(context)
.copyWith(
canvasColor:colorGray,
),
child:Directionality(
textDirection: TextDirection.ltr,
child: DropdownButtonHideUnderline(
child: ButtonTheme(
alignedDropdown: true,
child: DropdownButton(
//iconSize: 15,
isDense: false,
icon: Container(
padding: EdgeInsets.all(0),
child:Icon(
//Icons.arrow_drop_down,
Icons.location_on,
color: Colors.grey,
size: 15,
)),
hint: Center(
child: Text(
"All Cities",
textAlign: TextAlign
.center,
style: TextStyle(
color: Colors
.grey,
fontWeight:
FontWeight
.normal,
fontFamily:
'Montserrat',
fontSize: 12),
)),
style: TextStyle(
color: Colors
.grey,
fontWeight:
FontWeight
.normal,
fontFamily:
'Montserrat',
fontSize: 12),
//value: selectedCountry,
onChanged: (newVal) {
setState(() {
});
},
value: _mySelection,
items:
data.map((item) {
return new DropdownMenuItem(
child: Container(
child: Container(
padding: EdgeInsets.all(0),
child: Center(
child: Text(
""
))),
),
value: item['id']
.toString(),
);
}).toList(),
isExpanded: true,
),
),
)
),
)
),
)
],
),
))),
),
),
Add titleSpacing 0 and automaticallyImplyLeading false as below:
AppBar(
automaticallyImplyLeading: false,
titleSpacing: 0
)
Note: It will remove leading icon , you can add your own custom Leading icon.
Make center title to false and add leadingWidth: 0,
centerTitle: false,
appBar: PreferredSize(
preferredSize: Size.fromHeight(40.0),
// here the desired height
child: AppBar(
leadingWidth: 0,
centerTitle: true,
backgroundColor: colorGreen,
title: Container(
height: 35,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
),
child: Center(
child: SizedBox(
height: 40,
width: double.infinity,
child: Row(
children: <Widget>[
// Expanded(
Container(
padding: EdgeInsets.only(bottom:6),
width: 240,
alignment: Alignment.centerLeft,
child: TextField(
readOnly: true,
onTap: (){
},
textAlign: TextAlign.left,
controller: controller,
cursorColor: Colors.grey,
style: TextStyle(
color: Colors.grey,
fontSize: 16,
fontFamily: 'Montserrat'),
onChanged:
onSearchTextChanged,
decoration: InputDecoration(
hintText: "Search",
hintStyle: TextStyle(
color: Colors.grey,
fontSize: 13,fontWeight: FontWeight.normal,
fontFamily:
'Montserrat'),
border: InputBorder.none,
prefixIcon: Container(
padding: EdgeInsets.only(top: 5),
child:Icon(
Icons.search,
color: Colors.grey,
size: 15,
)),
suffixIcon: Visibility(
visible: backClear,
child:InkWell(
onTap: () {
},
child: Container(
padding: EdgeInsets.only(top: 5),
child:Icon(
Icons.backspace,
color: Colors.grey,
size: 12,
)))),
labelStyle: TextStyle(
color: Colors.grey,
fontSize: 14,fontWeight: FontWeight.normal,
fontFamily:
'Montserrat'),
// hintText:Center(child: Text(""),), //contentPadding: EdgeInsets.only(top: 2),
),
),
),
new Container(
width: 2.0,
height: 100.0,
color: colorGreen,
),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.center,
child: new Theme(
data: Theme.of(context)
.copyWith(
canvasColor:colorGray,
),
child:Directionality(
textDirection: TextDirection.ltr,
child: DropdownButtonHideUnderline(
child: ButtonTheme(
alignedDropdown: true,
child: DropdownButton(
//iconSize: 15,
isDense: false,
icon: Container(
padding: EdgeInsets.all(0),
child:Icon(
//Icons.arrow_drop_down,
Icons.location_on,
color: Colors.grey,
size: 15,
)),
hint: Center(
child: Text(
"All Cities",
textAlign: TextAlign
.center,
style: TextStyle(
color: Colors
.grey,
fontWeight:
FontWeight
.normal,
fontFamily:
'Montserrat',
fontSize: 12),
)),
style: TextStyle(
color: Colors
.grey,
fontWeight:
FontWeight
.normal,
fontFamily:
'Montserrat',
fontSize: 12),
//value: selectedCountry,
onChanged: (newVal) {
setState(() {
});
},
value: _mySelection,
items:
data.map((item) {
return new DropdownMenuItem(
child: Container(
child: Container(
padding: EdgeInsets.all(0),
child: Center(
child: Text(
""
))),
),
value: item['id']
.toString(),
);
}).toList(),
isExpanded: true,
),
),
)
),
)
),
)
],
),
))),
),
),
You can replace the title with flexibleSpace
AppBar(
centerTitle: true,
backgroundColor: Colors.green,
flexibleSpace: Container(
// height: 35, <-- adjust height here
margin: EdgeInsets.zero,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
),
child: Center(
....
)
),
)

NavigationBar is imported from both 'package:flutter/src/material/navigation_bar.dart' and 'package:flutter_onboarding_slider/navigation_bar.dart'

**i am facing error while running error is this because of packges or something else i have remove all the old code and add new still facing following error.
Error: 'NavigationBar' is imported from both 'package:flutter/src/material/navigation_bar.dart' and 'package:flutter_onboarding_slider/navigation_bar.dart'.
appBar: NavigationBar(
^^^^^^^^^^^^^
: Warning: Operand of null-aware operation '?.' has type 'GoogleMapController' which excludes null.
lib/…/map/map.dart:62
'GoogleMapController' is from 'package:google_maps_flutter/google_maps_flutter.dart' ('/D:/flutter/.pub-cache/hosted/pub.dartlang.org/google_maps_flutter-2.1.7/lib/google_maps_flutter.dart').
package:google_maps_flutter/google_maps_flutter.dart:1
_controller?.animateCamera(CameraUpdate.newCameraPosition(CameraPosition(
^
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_onboarding_slider/flutter_onboarding_slider.dart';
import 'package:fyppedometer/mainScreens/Navigation/navigationBar.dart';
import 'package:fyppedometer/widgets/constants.dart';
import 'package:fyppedometer/widgets/text.dart';
class MyHome extends StatefulWidget {
const MyHome({Key? key}) : super(key: key);
#override
State<MyHome> createState() => _MyHomeState();
}
class _MyHomeState extends State {
final Color kDarkBlueColor = Colors.cyan;
// ignore: non_constant_identifier_names
List<String> numbers_Height = [
for (var i = 1.1; i <= 10.0; i = i + 0.1) i.toString()
];
// ignore: non_constant_identifier_names
List<String> numbers_Weight = [for (var i = 1; i <= 1000; i++) i.toString()];
int _groupValue = -1;
String _selectedGender = 'male';
#override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Container(
// color: Colors.amber,
child: OnBoardingSlider(
buttonText: 'Start',
onFinish: () {
Navigator.push(
context,
CupertinoPageRoute(
builder: (context) => Navbar(),
),
);
},
buttonTextColor: Colors.cyan,
// skipTextButton: Text(
// 'Skip',
// style: TextStyle(
// fontSize: 16,
// color: kDarkBlueColor,
// fontWeight: FontWeight.w600,
// ),
// ),
// trailing: Text(
// 'Login',
// style: TextStyle(
// fontSize: 16,
// color: kDarkBlueColor,
// fontWeight: FontWeight.w600,
// ),
// ),
// trailingFunction: () {
// // Navigator.push(
// // context,
// // CupertinoPageRoute(
// // builder: (context) => LoginPage(),
// // ),
// // );
// },
controllerColor: kDarkBlueColor,
totalPage: 3,
headerBackgroundColor: liteblue,
pageBackgroundColor: liteblue,
background: [
Padding(
padding: const EdgeInsets.only(top: 210, left: 80),
child: Image.asset(
'assets/gender.png',
height: MediaQuery.of(context).size.height * 0.6,
width: MediaQuery.of(context).size.width * 0.6,
),
),
Padding(
padding: const EdgeInsets.only(top: 160, left: 60),
child: Image.asset(
'assets/walking.png',
height: MediaQuery.of(context).size.height * 0.7,
width: MediaQuery.of(context).size.width * 0.7,
),
),
Padding(
padding: const EdgeInsets.only(top: 200, left: 60),
child: Image.asset(
'assets/human.png',
height: MediaQuery.of(context).size.height * 0.6,
width: MediaQuery.of(context).size.width * 0.6,
),
),
],
speed: 1.8,
pageBodies: [
Container(
// padding: EdgeInsets.symmetric(horizontal: 40),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
const Text(
'What’s Your Gender',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 24.0,
fontWeight: FontWeight.w600,
),
),
const SizedBox(
height: 10,
),
const Text(
'Calories & Stride length calculation need it ',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white60,
fontSize: 21.0,
fontWeight: FontWeight.w600,
),
),
const SizedBox(
height: 20,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: size.height * 0.1,
width: size.width * 0.5,
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(25), // radius of 10
color: Color.fromARGB(255, 19, 65, 103),
),
child: Center(
child: ListTile(
leading: Radio<String>(
activeColor: Colors.white,
value: 'male',
groupValue: _selectedGender,
onChanged: (value) {
setState(() {
_selectedGender = value!;
});
},
),
title: text(
textData: "Male",
color: Colors.white,
fontsize: 20.0,
fontweight: FontWeight.bold),
// Text(_selectedGender == 'male' ? 'Hello gentlement!' : 'Hi lady!')
),
),
),
SizedBox(height: 20),
Container(
height: size.height * 0.1,
width: size.width * 0.5,
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(25), // radius of 10
color: Color.fromARGB(255, 19, 65, 103),
),
child: Center(
child: ListTile(
leading: Radio<String>(
activeColor: Colors.white,
value: 'female',
groupValue: _selectedGender,
onChanged: (value) {
setState(() {
_selectedGender = value!;
});
},
),
title: text(
textData: "Female",
color: Colors.white,
fontsize: 20.0,
fontweight: FontWeight.bold),
// Text(_selectedGender == 'male' ? 'Hello gentlement!' : 'Hi lady!')
),
),
),
],
)
]),
),
Container(
// padding: EdgeInsets.symmetric(horizontal: 40),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
const Text(
'How Tall are you?',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 28.0,
fontWeight: FontWeight.w600,
),
),
const SizedBox(
height: 10,
),
const Text(
'To Personalize Your Fitness Goal ',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white60,
fontSize: 20.0,
fontWeight: FontWeight.w600,
),
),
const SizedBox(
height: 20,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Center(
child: Container(
height: size.height * 0.10,
width: size.width * 0.5,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: Color.fromARGB(255, 145, 174, 225))),
child: Center(
child: text(
textData: "Height",
fontsize: 30.0,
fontweight: FontWeight.bold,
color: Color.fromARGB(255, 147, 148, 152)),
),
),
),
SizedBox(
height: 30,
),
Center(
child: Container(
height: size.height * 0.13,
width: size.width * 0.5,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: Color.fromARGB(255, 92, 89, 89)),
// color: Colors.white,
),
child: ListWheelScrollView.useDelegate(
itemExtent: 100,
// controller: fixedExtentScrollController,
physics: FixedExtentScrollPhysics(),
onSelectedItemChanged: (i) {
print(numbers_Height[i]);
},
childDelegate: ListWheelChildLoopingListDelegate(
children: <Widget>[
...numbers_Height.map((String number) {
return Center(
child: Text(
number,
style: const TextStyle(
fontSize: 28.0,
color: Colors.white,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
decoration: TextDecoration.none),
),
);
})
],
),
),
),
)
],
)
]),
),
Container(
// padding: EdgeInsets.symmetric(horizontal: 40),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
const Text(
'How much do you Weight?',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 28.0,
fontWeight: FontWeight.w600,
),
),
const SizedBox(
height: 10,
),
const Text(
'To Personalize Your Fitness Goal ',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white60,
fontSize: 20.0,
fontWeight: FontWeight.w600,
),
),
const SizedBox(
height: 20,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Center(
child: Container(
height: size.height * 0.10,
width: size.width * 0.5,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: Color.fromARGB(255, 145, 174, 225))),
child: Center(
child: text(
textData: "Weight",
fontsize: 30.0,
fontweight: FontWeight.bold,
color: Color.fromARGB(255, 147, 148, 152)),
),
),
),
SizedBox(
height: 30,
),
Center(
child: Container(
height: size.height * 0.13,
width: size.width * 0.5,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: Color.fromARGB(255, 92, 89, 89)),
),
child: ListWheelScrollView.useDelegate(
itemExtent: 100,
physics: FixedExtentScrollPhysics(),
onSelectedItemChanged: (i) {
print(numbers_Weight[i]);
},
childDelegate: ListWheelChildLoopingListDelegate(
children: <Widget>[
...numbers_Weight.map((String number) {
return Center(
child: Text(
number, //Here is the child value I would like to get
style: const TextStyle(
fontSize: 28.0,
color: Colors.white,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
decoration: TextDecoration.none),
),
);
})
],
),
),
),
)
],
)
]),
),
],
),
);
}
}
Use show and hide to import part of a library.
// Import only foo.
import 'package:lib1/lib1.dart' show foo;
// Import all names EXCEPT foo.
import 'package:lib2/lib2.dart' hide foo;
See Using libraries for details.

Flutter: How to add item to favourite and display favourites in listview

I am working on an e-commerce demo project that uses woocommerce for its backend. I have a product card widget for listing all products displayed in a grid or list view.
This is the code for the product card
InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ProductDetails(
product: data,
productName: data.name,
)));
},
child: Column(
children: [
Stack(children: [
Center(
child: Container(
width: 160,
height: 185,
alignment: Alignment.center,
decoration: BoxDecoration(
shape: BoxShape.rectangle,
border: Border.all(color: Colors.white, width: 2),
borderRadius: BorderRadius.circular(8),
color: Colors.white,
image: DecorationImage(
image: NetworkImage(
data.images[0].src,
),
fit: BoxFit.fill,
))),
),
Positioned(
top: 7,
left: 20,
child: Visibility(
visible: data.calculateDiscount() > 0,
child: Align(
alignment: Alignment.topLeft,
child: Container(
padding: const EdgeInsets.all(5),
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(50),
),
child: Text(
'-${data.calculateDiscount()}%',
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.normal,
),
),
),
)),
),
]),
Container(
width: 100,
alignment: Alignment.center,
child: Column(
children: [
const SizedBox(
height: 3,
),
Center(
child: Text(
data.name,
maxLines: 2,
style: const TextStyle(
height: 1,
fontSize: 14,
fontWeight: FontWeight.w500,
),
textAlign: TextAlign.center,
),
),
Text(
data.type == "variable"
? (data.attributes[0].name +
": " +
data.attributes[0].options.join("-").toString())
: '₦${data.regularPrice}',
style: TextStyle(
color: data.type == "variable" ? Colors.black : Colors.red,
fontSize: data.type == "variable" ? 12 : 14,
fontWeight: FontWeight.w600,
decoration: data.type == "variable"
? TextDecoration.none
: TextDecoration.lineThrough,
),
textAlign: TextAlign.center,
),
Text(
data.type == "variable"
? '₦${data.price}'
: '₦${data.salePrice}',
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
),
textAlign: TextAlign.center,
),
],
),
),
],
),
);
How can I integrate add to favourite logic on this product card and display all favourites in a listview? I need to have a favourites page in my app. Thanks

Column widget not positioning widgets properly when using Stack widget-Flutter

The first image is the design of the app from Figma. While the next image is the one which I am getting though I am using simple stack and columns. I am not being able to understand why it is coming out as such. The Text Widgets must be under the picture but they are going right at the bottom of the screen. Can anyone help me out with this one?
My code:
import 'package:flutter/material.dart';
import '../../app_theme.dart';
class ProfileScreen extends StatefulWidget {
const ProfileScreen({Key? key}) : super(key: key);
#override
_ProfileScreenState createState() => _ProfileScreenState();
}
class _ProfileScreenState extends State<ProfileScreen> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: AppTheme.lightBlue,
title: Text(
'Profile',
style: TextStyle(color: AppTheme.black100),
),
elevation: 0,
),
body: Column(
children: [
SizedBox(
height: 50,
),
Stack(
alignment: Alignment.center,
clipBehavior: Clip.none,
children: [
Container(
width: double.infinity,
height: 150,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(16),
topLeft: Radius.circular(16),
),
color: AppTheme.lightGrey),
),
Positioned(
top: -50,
child: _buildProfileDetails(),
),
],
)
],
),
backgroundColor: AppTheme.lightBlue,
drawer: Drawer(),
);
}
Widget _buildProfileDetails() {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Stack(
clipBehavior: Clip.none,
children: [
CircleAvatar(
radius: 50,
backgroundImage: AssetImage('assets/images/profile_photo.jpg'),
),
Positioned(
left: 78,
top: 60,
child: CircleAvatar(
radius: 14,
backgroundColor: AppTheme.blue,
child: Icon(Icons.camera_alt_outlined),
),
),
],
),
Text(
'Alexis Sanchez',
style: TextStyle(
color: AppTheme.black100,
fontSize: 22,
fontWeight: FontWeight.w600,
fontStyle: FontStyle.normal,
fontFamily: 'Poppins',
height: 33,
),
textAlign: TextAlign.center,
),
Text(
'Alexis Sanchez',
style: TextStyle(
color: AppTheme.black80,
fontSize: 12,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
fontFamily: 'Poppins',
height: 18,
),
textAlign: TextAlign.center,
),
Text(
'Alexis Sanchez',
style: TextStyle(
color: AppTheme.black80,
fontSize: 12,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
fontFamily: 'Poppins',
height: 18,
),
textAlign: TextAlign.center,
),
],
);
}
}
Stack widget extends and fills all the available space. if you want your stack to be smaller than all available space. wrap it inside a SizedBox widget.
If you need to control height, do like height: 1.2. and use mainAxisSize: MainAxisSize.min, on Column.
I am using different approach to gain this and will contain some extra widget for future purpose. Mostly describe on code-comment. If you face any issue while scaling/increasing size, adjust the parent Container size. Used demo color for design purpose.
Run on dartPad.
Result will be:
body: LayoutBuilder(
builder: (context, constraints) {
return Column(
children: [
/// header Part: Name, logo, info
Container(
color: Colors.grey,
height: kToolbarHeight * 3, //adjust box Stack size
child: Stack(
children: [
/// bottom Half background
Align(
alignment: Alignment.bottomCenter,
child: Container(
height: kToolbarHeight * 2,
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topRight: Radius.circular(16),
topLeft: Radius.circular(16),
),
),
),
),
/// center logo with info
Positioned(
bottom: 10,
left: 0,
right: 0,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(
height: 50 * 2, // from your logo radius
width: 50 * 2 +
7, //7 is from `camera_alt_outlined` to align
child: Stack(
children: const [
CircleAvatar(
radius: 50,
backgroundColor: Colors.deepPurple,
// backgroundImage: AssetImage(
// 'assets/images/profile_photo.jpg'),
),
Positioned(
bottom: 7,
right: 0,
child: CircleAvatar(
radius: 14,
backgroundColor: Colors.blue,
child: Icon(Icons.camera_alt_outlined),
),
)
],
),
),
///now rest of Text
const Text(
'Alexis Sanchez',
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.w600,
fontStyle: FontStyle.normal,
fontFamily: 'Poppins',
height: 1.2),
textAlign: TextAlign.center,
),
const Text(
'Alexis Sanchez',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
fontFamily: 'Poppins',
),
textAlign: TextAlign.center,
),
const Text(
'Alexis Sanchez',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
fontFamily: 'Poppins',
),
textAlign: TextAlign.center,
),
],
),
),
],
),
)
],
);
},
));
I would have put child in this container and put everything that I want on this background
Must use screenutil helps for different screen sizes
Container(
width: double.infinity,
height: 150,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(16.sp),
topLeft: Radius.circular(16.sp),
),
color: AppTheme.lightGrey),
),

Why it is not changing the heigth and width of the button

InkWell(
borderRadius: BorderRadius.all(Radius.circular(5)),
onTap: () {},
child: SizedBox(
height: 25,
width: screenWidth *65,
child: Container(
color: Colors.blueAccent,
child: Text(
'Confirm',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
color: Color(0xff000000),
fontWeight: FontWeight.w500),
),
),
),
),
Is this what you are looking for?
Container(
padding: EdgeInsets.all(6),
width: double.infinity,
child: FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(5))
),
color: Colors.blueAccent,
onPressed: () => print('pressed'),
child: Text('Confirm',
style: TextStyle(
fontSize: 15,
color: Color(0xff000000),
fontWeight: FontWeight.w500
),
)
),
),
Remove SizedBox widget as it not of any issue in your current widget tree anyway as you are using container already
and use those height and width parameter inside container widget
try this
InkWell(
borderRadius: BorderRadius.all(Radius.circular(5)),
onTap: () {},
child: Container(
height: 25,
width: screenWidth *65,
color: Colors.blueAccent,
child: Text(
'Confirm',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
color: Color(0xff000000),
fontWeight: FontWeight.w500),
),
),
),