My code for a page is like this. i need to scroll part below appbar.
#override
Widget build(BuildContext context) {
return Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Colors.deepPurple, Colors.black]
)
),
child: Scaffold(
appBar: AppBar(
backgroundColor: Colors.transparent,
leading: IconButton(
icon: Image.asset("assets/images/logo1.png"),
iconSize: 100,
onPressed: null,
),
title: Text("Home"),
//centerTitle: true
flexibleSpace: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Colors.deepPurple, Colors.white]
)
),
),
//search button for admin pannel
// actions: <Widget>[
// IconButton(
// icon: Icon(Icons.search),
// onPressed: () {
// // your onPressed function here
// },
// ),
// ],
),
),
);
i want the body area to be scrolled, with that gradient background.
You can wrap body parent widget with SingleChildScrollView for scrolling body...
body: SingleChildScrollView(
child: Column(
children: [],
),
),
Use SingleChildScrollView or Listview. if you are using Listview inside a Column, Try to use Shrinkwrap = true in Listview.
Related
i want to build a blur effect on my modal bottom screen with bottomNavigationBar property, i already set the LinearGradient color with 0.5 opacity and extendBody: true in scaffold but nothing works, the blur in the modal just won't go transparent
this is the build widget
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: kWhiteGreyColor,
extendBody: true,
bottomNavigationBar:_buildSeeMore(),
);
}
this is the blur widget
Widget _buildSeeMore() {
return Container(
width: double.infinity,
height: 315,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
kWhiteColor.withOpacity(0.5),
kWhiteColor,
],
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: () {},
child: Text(
'See More',
style: TextStyle(
color: kBlueColor,
fontSize: 16,
fontWeight: semiBold,
),
),
),
],
),
);
}
if you want to do blur effect please use backDropFilter widget and in container give color transparent
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,
),
),
),
),
),
Hy everyone,
I need to know, how can I create gradient on top right of the page like this picture?
I tried with this code, but it's still not working for me:
Scaffold(
backgroundColor: Colors.white,
body: SafeArea(
child: Stack(
children: [
Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.center,
stops: [
0.01,
0.3,
0.4,
],
colors: [
Color(0xff2DBA61),
Colors.yellow,
Colors.white,
],
),
),
),
],
),
),
),
here is the result
Thank you. any kind of help will be appreciated!
Just wrap your Scaffold inside a DecoratedBox or a Container and set its backgroundColor property to Colors.transparent.
Code sample
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return DecoratedBox(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.center,
stops: [0.01, 0.3, 0.4],
colors: [
Color(0xff2DBA61),
Colors.yellow,
Colors.white,
],
),
),
child: Scaffold(
backgroundColor: Colors.transparent,
appBar: AppBar(
elevation: 0,
backgroundColor: Colors.transparent,
leading: const BackButton(color: Colors.black),
),
),
);
}
}
Result
Try the full example on DartPad
so I'm trying to make a registration page with multi fields for name and password and email etc.
my problem is that i couldn't make the page scrollable, can please help me with fixing that
I just want the page to be scrollable
Here is my Code :
class InstRegisterPage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Color(0x47705C53), Color(0x9E36251D)],
stops: [0.1, 0.9],
begin: Alignment.topRight,
end: Alignment.bottomLeft,
),
),
child: Column(
children: [
Container(
child: wLogo(),
),
SizedBox(
height: 75,
),
Expanded(
child: Container(
decoration: BoxDecoration(
color: Color(0xFFF7F6F5),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(26),
topRight: Radius.circular(26)),
),
child: Column(
children: [
SizedBox(
height: 15,
),
CSfield('Particpent Name',''),
CSfieldEmail('Email',''),
CSfield('Password',''),
CSPasswordFiled('Phone Number',''),
CSButton(),
],
),
),
)
],
),
//child: InstHomePageWidgets(),
),
),
);
}
}
You can wrap your Column with a SingleChildScrollView to make it scrollable.
SingleChildScrollView(
child: Column(
children: [...]
),
)
You can check the page here to see all the scrollable widgets.
Also if the keyboard is pushes content up you can check this page
I'd like to wrap a Scaffold with a Container in order to get a gradient background that's also underneath the AppBar. Basically a full screen gradient background. However, my attempt doesn't do anything.
Is there another way of doing it, where I can keep the AppBar functionality but have it on top of a gradient that spans the whole screen?
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Test',
theme: ThemeData(
primarySwatch: Colors.yellow,
),
home: MyHomePage(title: 'Test'),
);
}
}
class MyHomePage extends StatelessWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
stops: [0.1, 0.5, 0.7, 0.9],
colors: [
Colors.yellow[800],
Colors.yellow[700],
Colors.yellow[600],
Colors.yellow[400],
],
),
),
child: Scaffold(
appBar: AppBar(
title: Icon(Icons.menu),
backgroundColor: Color(0x00000000),
elevation: 0.0,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'dummy text',
),
Text(
'5',
style: Theme.of(context).textTheme.display1,
),
FloatingActionButton(
backgroundColor: Colors.white,
foregroundColor: Colors.black45,
elevation: 0.0,
onPressed: () {},
tooltip: 'Play',
child: Icon(Icons.play_arrow),
),
],
),
),
),
);
}
}
You can also add a gradient to the AppBar like this,
new Scaffold(
appBar: AppBar(
title: Center(child: Text('Awesome AppBar')),
flexibleSpace: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
const Color(0xFF3366FF),
const Color(0xFF00CCFF),
],
begin: const FractionalOffset(0.0, 0.0),
end: const FractionalOffset(1.0, 0.0),
stops: [0.0, 1.0],
tileMode: TileMode.clamp),
),
),
child: ...,
),
body: ...,
);
LinearGradient parameters:
colors: an array of the colors to be used in the gradient, in this case, two shades of blue.
begin, end: position of the first color and the last color, in this case,
FractionalOffset allows us to treat the coordinates as a range from 0 to 1 both for x and y. As we want an horizontal gradient, we use same Y for both measures, and the x changes from 0.0 (left) to 1.0 (right).
stops: this array should have the same size than colors. It defines how the colors will distribute. [0.0, 1.0] will fill it from left to right. [0.0, 0.5] will fill the colors from left to half bar, etc.
tileMode: what to do if the stops do not fill the whole area. In this case, we added clamp (it will reuse the last color used), but as our gradient goes from 0.0 to 1.0, it’s not really necessary.
You can also add a child to the Container. e.g: some logo image
child: Align(
alignment: Alignment.center,
child: Image.asset(
"images/logo.png",
width: 128,
height: 128,
)),
),
Hope this helps.
In Your Code - Under Scaffold add - backgroundColor: Colors.transparent,
child: Scaffold(
backgroundColor: Colors.transparent,
appBar: AppBar(
..
Simply add FlexibleSpace in AppBar and Decorate the container. Then the app bar is a gradient in the background.
appBar: AppBar(
title: Text('Flutter Demo'),
flexibleSpace: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: <Color>[
Colors.red,
Colors.blue
],
),
),
),
),
I used this piece of code to set background color as a gradient
return MaterialApp(
home: Scaffold(
body: Container(
decoration: new BoxDecoration(
gradient: new LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color.fromARGB(255, 25,178,238),
Color.fromARGB(255, 21,236,229)
],
)),
child: Align(
alignment: Alignment.center,
child: Image.asset(
"images/app_logo.png",
width: 128,
height: 128,
)),
),
),
);
You simply use FlexibleSpace in the appbar
appBar: AppBar(
centerTitle: true,
title: Text(widget.title),
flexibleSpace: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: <Color>[
Colors.red,
Colors.blue
])
),
),
),
You can use directly below code for gradient color of any container or view
class HomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Dashboard"),
),
body: Container(
alignment: Alignment.center,
decoration: BoxDecoration(
gradient: LinearGradient(colors: [Colors.red, Colors.blue, Colors.black])
)
),
);
}
}