Related
I want to insert a text to my container I tried this code segment. but it is not displaying. first image showing how it display now. image two showing how I need it to be implement. also the image icon need to have padding from the corner. how can I do this.
child: Text(
"Activity",
style: TextStyle(color: textWhite, fontSize: 2)),
///////////////// //////////////////////////////////////////////////////////
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
padding: const EdgeInsets.all(20),
height: 45,
width: 180,
decoration: BoxDecoration(
color: Colors.grey.withOpacity(0.4),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
bottomLeft: Radius.circular(10),
),
image: DecorationImage(
alignment: Alignment.centerLeft,
image: AssetImage(
'assets/images/running.png',
),
),
),
child: Text(
"Activity",
style: TextStyle(color: textWhite, fontSize: 20),
),
),
Container(
height: 45,
width: 180,
decoration: BoxDecoration(
color: Colors.grey.withOpacity(0.4),
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(10),
topRight: Radius.circular(10),
),
image: DecorationImage(
alignment: Alignment.centerLeft,
image: AssetImage('assets/images/medal.png'),
),
),
)
],
),
)
Use Following Code But You need to edit the style according to you
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 50,
width: 200,
// You can set width of container here
decoration: BoxDecoration(
border: Border.all(),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(15),
bottomLeft: Radius.circular(15),
),
),
child: Padding(
// Following padding to give space around the icon and text
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
'assets/running.png',
),
SizedBox(
width: 15,
),
Text(
"Activity",
style: TextStyle(
color: Colors.black,
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
Container(
height: 50,
width: 200,
decoration: BoxDecoration(
border: Border.all(),
borderRadius: BorderRadius.only(
topRight: Radius.circular(15),
bottomRight: Radius.circular(15),
),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
'assets/medal.png',
),
SizedBox(
width: 15,
),
Text(
"Achievement",
style: TextStyle(
color: Colors.black,
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
],
),
You will get following response
This image is similar to your goal. run on DartPad.
You can change Image.network to Image.asset
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return const MaterialApp(home: HomePage());
}
}
class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
// backgroundColor: Colors.blue[700],
body: Container(
height: 45,
decoration: BoxDecoration(
color: Colors.grey.withOpacity(0.4),
borderRadius: BorderRadius.circular(10),
),
margin: const EdgeInsets.symmetric(vertical: 5, horizontal: 15),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
iconRowText('https://picsum.photos/45', 'Activity'),
Container(
height: 45,
width: 0.4,
color: Colors.black,
),
iconRowText('https://picsum.photos/45', 'Achievements'),
],
),
),
);
}
Row iconRowText(String image, String text) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Image.network(image, height: 45, width: 45, fit: BoxFit.cover),
),
Text(text),
],
);
}
}
https://i.stack.imgur.com/rQYu0.png
I'm new to flutter, and I've been trying to build this ui but it's way out of my league !
Here's my code so far:
(by the way I didn't use any specific package...)
My biggest challenge are the angles of that circle !
How can I create that circle? Is there a package for it ?
class NowPlaying extends StatefulWidget {
#override
_NowPlayingState createState() => _NowPlayingState();
}
class _NowPlayingState extends State<NowPlaying> {
#override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Scaffold(
backgroundColor: Colors.white,
body: Column(
children: <Widget>[
Container(
color: btmGreen,
height: 60,
width: size.width,
child: Row(
children: <Widget>[
GestureDetector(
child:
cbutton(back),
onTap: (){
Navigator.push(context, MaterialPageRoute(builder: (context)=>NowPlaying()));
},
),
Spacer(),
Container(
height: 35,
width: 300,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
// topLeft: Radius.circular(30),
bottomLeft: Radius.circular(260)),
color : PrimaryGreen,
),
)
],
),
),
Container(
// color: Colors.white,
child: Row(
children: <Widget>[
buildVerticalMenu(size),
ClipRRect(
borderRadius: BorderRadius.circular(370),
child: Container(
color: Orange,
height: 400,
width: 400,
child: ClipRRect(
borderRadius: BorderRadius.circular(370),
child: Container(
// padding: EdgeInsets.fromLTRB(110, 110, 0.0, 110),
height: 360,
width: 360,
decoration: BoxDecoration(
color: PrimaryGreen,
borderRadius: BorderRadius.all(Radius.circular(200)),
image: DecorationImage(
alignment: Alignment.bottomCenter,
fit: BoxFit.fill,
image: AssetImage("assets/images/hiphop.jpg"),
),
),),
),
),
),
],
),
)
],
),
);
}
Widget buildVerticalMenu(Size size){
return Container(alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(topRight: Radius.circular(60)),
color: Colors.white,
),
height: size.height*0.3,
width: 70,
child: RotatedBox(
quarterTurns: -1,
child: Text('Now Playing', style: TextStyle(fontSize: 20 , fontWeight: FontWeight.w700,color: PrimaryGreen),)),
);
}
}
I have an input screen developed in flutter where i need to get the user image uploaded/selected. for this in the Screen UI i want to have a design like this in the picture.
The code and what i have come up with the screen background is as follows. How can i add this kind of a circle in my code to enable image selection.
final form =
Container(
alignment: Alignment.center,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 32.0, vertical: 4.0),
child: Column(
children: <Widget>[
SizedBox(height: 12.0),
title,
SizedBox(height: 16.0),
email,
SizedBox(height: 12.0),
userName,
SizedBox(height: 12.0),
password,
SizedBox(height: 12.0),
address,
SizedBox(height: 12.0),
country_dropdown,
SizedBox(height: 12.0),
phone,
SizedBox(height: 24.0),
continue_btn,
],
),
), ),
);
final body = Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
stops: [0.5, 1.0],
colors: [
Color(0xFF03B898),
Color(0xFF01816B),
],
),
),
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
flex: 1,
child: Container(
alignment: Alignment.center,
child: Center(
child: Image.asset(
'assets/images/pawfect_logo.png',
height: 150.0,
width: 150.0,
fit: BoxFit.contain,
),
),
),
),
Expanded(
flex: 4,
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
color: Colors.white,
),
borderRadius: BorderRadius.only(
topRight: Radius.circular(50),
topLeft: Radius.circular(50),
),
),
child: form, //Text('this text here'),
),
),
],
),
));
return Scaffold(
body: body,
);```
Check out this example :
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(home: HomePage());
}
}
class HomePage extends StatefulWidget {
#override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
#override
Widget build(BuildContext context) {
final form = Container(
height: MediaQuery.of(context).size.height*0.75,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 32.0, vertical: 4.0),
child: Column(
children: <Widget>[
SizedBox(height: 90.0),
Text('Name'),
SizedBox(height: 16.0),
Text('email'),
SizedBox(height: 12.0),
Text('username'),
SizedBox(height: 12.0),
Text('password'),
SizedBox(height: 12.0),
Text('Address'),
SizedBox(height: 12.0),
Text('Dropdown'),
SizedBox(height: 12.0),
Text('Phone'),
SizedBox(height: 24.0),
Text('con btn'),
],
),
),
);
final body = Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
stops: [0.5, 1.0],
colors: [
Color(0xFF03B898),
Color(0xFF01816B),
],
),
),
child: Stack(
children: <Widget>[
Column(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height * 0.25,
),
Container(
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
color: Colors.white,
),
borderRadius: BorderRadius.only(
topRight: Radius.circular(50),
topLeft: Radius.circular(50),
),
),
child: form, //Text('this text here'),
),
],
),
Positioned(
right: 30,
top: 150,
child: Container(
width: 100,
height: 100,
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(50)),
alignment: Alignment.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
Icons.camera_alt,
color: Colors.white,
),
Text(
'Upload Image',
style: TextStyle(fontSize: 10, color: Colors.white),
)
],
),
),
),
],
));
return Scaffold(
body: SingleChildScrollView(child: body),
);
}
}
Let me know if it works
You can use the following snippet to create a button on click of which the user will be prompted to select an image (either from gallery or camera)
class Layout extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xFF03B898),
body: Stack(
children: <Widget>[
Card(
margin: EdgeInsets.only(top: 150),
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topRight: Radius.circular(50),
topLeft: Radius.circular(50),
),
),
child: Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
),
),
Positioned(
top: 120,
right: 30,
child: RawMaterialButton(
shape: CircleBorder(),
fillColor: Color(0xFF03B898),
onPressed: () async {
final pickedFile = await ImagePicker().getImage(source: ImageSource.gallery);
},
padding: EdgeInsets.all(30.0),
child: Icon(
Icons.camera_alt,
color: Colors.white,
),
),
),
],
),
);
}
}
I have used the Image Picker library to select the image.
i have this button inside a container like below :
enter image description here
and i want to make that container change to a textfeild in the same container after clicking to that button like below :
enter image description here
so please ! any ideas to help ! and thanks
Container(
height: 96,
width: MediaQuery.of(context).size.width - 24,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: colorPrimary,
border:
Border.all(width: 0.5, color: Colors.redAccent)),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
InkWell(
onTap: () {
setState(() {});
},
child: Container(
height: 62,
width: 62,
decoration: BoxDecoration(
color: Colors.white,
borderRadius:
BorderRadius.circular(60),
border: Border.all(
width: 0.5,
color: Colors.grey[300],
)),
child: Icon(
Icons.phone,
size: 30,
color: Colors.purple[100],
)),
),
Text(
'Composer numéro',
style: TextStyle(fontSize: 12),
)
],
),
],
)),
),
You can use a use a bool to decide which widget to currently show. Set the bool to true or false using setState depending on which widget you want to show.
bool showTextField = false;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Container(
alignment: Alignment.center,
height: 96,
width: MediaQuery.of(context).size.width - 24,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: Colors.white,
border: Border.all(width: 0.5, color: Colors.redAccent)),
child: showTextField ? phoneTextInput() : button(),
),
),
);
}
Widget phoneTextInput() {
return TextField(
textAlign: TextAlign.center,
decoration: InputDecoration(
hintText: "Numero",
border: InputBorder.none,
),
);
}
Widget button() {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Row(children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
InkWell(
onTap: () {
setState(() {
showTextField = true;
});
},
child: Container(
height: 62,
width: 62,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(60),
border: Border.all(
width: 0.5,
color: Colors.grey[300],
)),
child: Icon(
Icons.phone,
size: 30,
color: Colors.purple[100],
)),
),
Text(
'Composer numéro',
style: TextStyle(fontSize: 12),
)
],
),
],
)
]),
);
}
Result:
I really need you because I don't have even start idea how to implement these, and also I am not sure how it is called.
Actually, I want to implement something similar like on image (this little circle in each of cards - that is like chain between two cards).
With help of key I have made image from up with this code:
class InfoPage extends StatefulWidget {
InfoPage();
#override
_InfoPageState createState() => _InfoPageState();
}
class _InfoPageState extends State<InfoPage> {
InfoItemModel infoData = dataSourceInfoUser;
double basicSize = 70;
#override
initState() {
super.initState();
}
#override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: Text('Example'),
),
body: Container(
color: Colors.white,
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
width: double.infinity,
height: 150,
child: AppCardField(
child: Text('Something'),
),
),
_buildCardWithCircle(
bgCircleX: 0.78,
bgCirceY: -2.0,
innerContainerX: 0.756,
innerContainerY: -1.78,
colorInner: Colors.orange
),
],
),
),
),
);
_buildCardWithCircle({double bgCircleX, double bgCirceY, double innerContainerX, double innerContainerY, Color colorInner}) => Container(
width: double.infinity,
height: 150,
child: Stack(
children: <Widget>[
Container(
width: double.infinity,
height: 150,
child: AppCardField(
child: Text('Something'),
),
),
Align(
alignment: Alignment(bgCircleX, bgCirceY),
child: Container(
height: basicSize,
width: basicSize,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(50.0),
),
),
),
Align(
alignment: Alignment(innerContainerX, innerContainerY),
child: Container(
height: basicSize - 10,
width: basicSize - 10,
decoration: BoxDecoration(
color: colorInner,
borderRadius: BorderRadius.circular(50.0),
),
child: Icon(Icons.vertical_align_center),
),
),
],
),
);
}
class AppCardField extends StatelessWidget {
final Widget child;
final double height;
final double paddingVertical, paddingHorizontal;
final double paddingVerticalChild, paddingHorizontalChild;
AppCardField({
this.child,
this.height,
this.paddingVertical = 8,
this.paddingHorizontal = 16,
this.paddingVerticalChild = 8,
this.paddingHorizontalChild = 16,
Key key})
: super(key: key);
#override
Widget build(BuildContext context) => Padding(
padding: EdgeInsets.symmetric(
vertical: paddingVertical, horizontal: paddingHorizontal),
child: Container(
height: height,
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
borderRadius: BorderRadius.all(Radius.circular(8)),
boxShadow: [
BoxShadow(
color: Colors.red,
blurRadius: 15.0,
offset: Offset(0.0, 5.0),
),
],
),
child: Padding(
padding: EdgeInsets.symmetric(
vertical: paddingVerticalChild,
horizontal: paddingHorizontalChild),
child: child,
),
));
}
But here, I have problem with shadow of the card and strongly white background of circle, OFC I need this shadow to be also in this white space, question is how to solve this?
Something like this
MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("Some Stuff"),
),
body: Column(
children: <Widget>[
Container(
width: double.infinity,
height: 150.0,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.red,
blurRadius: 20.0
)
]
),
child: Card(
elevation: 20.0,
color: Colors.blueGrey,
child: Text('Something'),
),
),
SizedBox(height: 10.0,),
Container(
width: double.infinity,
height: 150.0,
child: Stack(
children: <Widget>[
Container(
width: double.infinity,
height: 150.0,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.red,
blurRadius: 20.0
)
]
),
child: Card(
elevation: 20.0,
color: Colors.blueGrey,
child: Text('Something'),
),
),
Align(
alignment: Alignment(0.9,-1.5),
child: Container(
height: 50.0,
width: 50.0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(25.0),
),
),
),
Align(
alignment: Alignment(0.88,-1.35),
child: Container(
height: 40.0,
width: 40.0,
decoration: BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.circular(25.0),
),
),
),
Align(
alignment: Alignment(0.85, -1.2),
child: Icon(Icons.access_alarms, color: Colors.white,)
),
],
),
),
],
),
),
);
then you just reaped the card for the other once with different alignment values.