I'm trying to create a back button using an IconButton over a gradient, but the ripple effect shows below the gradient which is not the desired behavior. I've seen similar problems which can be resolved using the Material widget but it can only accept one color and not a gradient.
This image shows how the ripple effect should look like, but it doesn't have the gradient.
This image shows the gradient over the text, but also over the ripple effect.
The correct order should be IconButton > Ripple > Gradient > Text
Is there a way to achieve this?
Here's a minimal code to reproduce the issue:
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 MaterialApp(
home: Scaffold(
body: SafeArea(
child: Stack(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Text("Lorem ipsum", style: TextStyle(fontSize: 28)),
],
),
Container(
width: double.infinity,
height: 72,
decoration: BoxDecoration(
gradient: LinearGradient(
tileMode: TileMode.mirror,
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Theme.of(context).canvasColor,
Theme.of(context).canvasColor.withOpacity(0),
],
),
),
padding: const EdgeInsets.all(12),
child: Align(
alignment: Alignment.topLeft,
child: IconButton(
onPressed: () => print("pop"),
icon: const Icon(Icons.arrow_back),
),
),
),
],
),
),
),
);
}
}
Thanks in advance.
you can try create your own Icon button with InkWell
child: Align(
alignment: Alignment.topLeft,
child: Material(
color: Colors.transparent,
child: InkWell(
borderRadius: BorderRadius.circular(50),
onTap: () {
print("pop");
},
splashColor: Colors.green,
child: Padding(
padding: EdgeInsets.all(12),
child: Icon(
Icons.arrow_back,
),
),
),
),
),
Related
I'm a student new to flutter. I want to add a Text and a button on this background image. how should I do that using flutter. appreciate your help on this.
text -"Hello there"
button - Get Started
image description
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class GetStarted extends StatelessWidget {
const GetStarted({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
color: Colors.black,
child: Stack(
children: [
Positioned.fill(
child: Opacity(
opacity: 0.4,
child:
Image.asset('assets/images/person1.png', fit: BoxFit.cover),
),
)
],
),
),
);
}
}
You can just add the other widgets to the Stack and wrap them in an Align to put them where you want them.
Stack(
children: [
Positioned.fill(
child: Opacity(
opacity: 0.4,
child: Image.asset('assets/images/person1.png', fit: BoxFit.cover),
),
),
Align(
alignment: Alignment.bottomCenter,
child: ElevatedButton(child: Text('Button'), onPressed: () {})
),
Text('ABC'),
],
),
https://api.flutter.dev/flutter/widgets/Align-class.html
https://api.flutter.dev/flutter/widgets/Stack-class.html
Hello Nidew here is a SImple And Basic Example what you want...
hope this will resolve your issue
Scaffold(
body: Stack(
children: [
SizedBox(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: Image.asset('assets/images/app_icon.png',fit: BoxFit.fill,),
),
Column(
children: [
const Align(alignment: Alignment.topLeft,child: Text('Hello',style: TextStyle(fontSize: 50,fontWeight: FontWeight.bold),)),
const Spacer(),
const Align(alignment: Alignment.centerLeft,child: Text('Hello Second Text')),
const Spacer(),
Padding(
padding: const EdgeInsets.only(bottom: 20),
child: Align(
alignment: Alignment.bottomCenter,
child: ElevatedButton(
onPressed: (){
},
child: const Text('Press me'),
style: ElevatedButton.styleFrom(
minimumSize: Size(MediaQuery.of(context).size.width,40)
),
),
),
)
],
),
],
),
)
anyone know how to design this button in flutter? It's a diamond shaped button with a border color.
result
full code
import 'dart:math' as math;
import 'package:flutter/material.dart';
class DimondButton extends StatelessWidget {
const DimondButton({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
body: Center(
child: Transform(
alignment: Alignment.center,
transform: Matrix4.rotationZ(
math.pi / 4,
),
child: Container(
width: 100,
height: 100,
decoration: BoxDecoration(
color: Colors.transparent,
border: Border.all(
width: 3,
color: Colors.amber,
),
),
child: InkWell(
splashColor: Colors.blueAccent,
onTap: () {},
child: Center(
child: Transform(
alignment: Alignment.center,
transform: Matrix4.rotationZ(
-math.pi / 4,
),
child: Text(
"Click",
style: TextStyle(color: Colors.white),
),
),
),
),
),
),
),
);
}
}
you have multiple approaches
you can create a container with border color and transparent inner and transform it using transform.translate
the other one is using custom paint which is a bit harder
You should try to use below code, add this dependency to your pubspec.yaml file flutter_custom_clippers: ^1.1.2 package found here
ClipPath(
clipper: ParallelogramClipper(),
child: Container(
height: 50,
width: 50,
color: Colors.pinkAccent,
child: TextButton(
onPressed: () {
print('object');
},
child: Text('OK'),
),
),
),
I trying to create a gradient button in flutter but in ElevatedButton shows some shadow or its strucuture there even when the color was set to transparent.
Here I have used DecoratedBox for applying gradient color is there any way to apply gradient in ElevatedButton?
The Code I have used
child: DecoratedBox(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.red,
Colors.blue,
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
)),
child: ElevatedButton(
onPressed: () {
// Navigator.of(context).push(MaterialPageRoute(
// builder: (BuildContext context) => RegisterScreen()));
},
style: ElevatedButton.styleFrom(
primary: Colors.transparent,
onPrimary: Colors.transparent),
child: Text(
"Register",
style: TextManager.btnText,
)),
),
by setting elevation to 0 resolved but when I click the button the thing is also visible. Setting splash color to transparent also didn't work.
The output button is here
You can simply wrap your child property with an Ink widget. By doing so you will be able to apply a gradient and keep the elevated effect from the button.
Code Sample
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return ElevatedButton(
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.all(0.0),
elevation: 5,
),
onPressed: () {},
child: Ink(
decoration: BoxDecoration(
gradient: LinearGradient(colors: [Colors.blue, Colors.cyan]),
),
child: Container(
padding: const EdgeInsets.all(10),
constraints: const BoxConstraints(minWidth: 88.0),
child: const Text('OK', textAlign: TextAlign.center),
),
),
);
}
}
Screenshot
Try the full test code on DartPad
Click here for picture
hi everyone, i need help making my profile page in flutter look like the image above. im not really know how make it bc there so much details in it.
this is the code i make so far:
import 'package:flutter/material.dart';
void main() => runApp(new UserDetails());
class UserDetails extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'User Details',
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.green,
leading: Icon(Icons.arrow_back),
title: Text('Edward',
style: TextStyle(color: Colors.black),
),
actions: <Widget>[
Icon(Icons.more_vert, color: Colors.white,),
],
),
body: Stack(
alignment: Alignment.center,
children: <Widget>[
Column(
children: <Widget>[
Container(
height: 200.0,
color: Colors.green,
child: Center(
child: Icon(Icons.person, size: 250.0 ),
),
)
],)
]
),
),
);
}
}
You can achieve that adding a border radius to the Container, then use a Column to position and arrange your texts: a Column widget in this case. You need, also, set theAppBar in the Scaffold to same background color which Container has, and set elevation to zero to avoid the shadow over the containter, if you need help with this latter, let me know.
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
height: 260,
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(25),
bottomRight: Radius.circular(25),
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
CircleAvatar(
backgroundColor: Colors.grey,
child: Align(
alignment: Alignment.bottomCenter,
child: Icon(Icons.people, size: 50),
),
radius: 35,
),
Text("#edward"),
Text("email#email.com"),
Text("No: 00X-XXX-XXX"),
],
),
);
}
}
I'm wondering what the best approach could be to achieve the effect of the rounded icon button on the bottom right.
Do notice the icon is transparent and reveals the image background.
I tried using the Stack widget, but I could not position it properly nor get the color to be transparent.
Currently I have this:
class Banner extends StatelessWidget {
final String src;
const Banner(this.src, {Key key}) : super(key: key);
#override
Widget build(BuildContext context) {
return AspectRatio(
aspectRatio: 16 / 9,
child: Stack(children: <Widget>[
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
),
child: Stack(
children: <Widget>[
Image.network(src),
LayoutBuilder(
builder: (context, constraints) {
var calculatedOverlay = constraints.maxHeight / 3;
return Align(
alignment: Alignment.bottomRight,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(calculatedOverlay),
),
color: Colors.white,
),
height: calculatedOverlay,
width: calculatedOverlay,
),
);
},
),
],
),
),
Material(
type: MaterialType.transparency,
child: InkWell(
onTap: () {},
),
),
]),
);
}
}
Which results in this:
Thanks in advance.