How can I make my Widget gradient with transparency? - flutter

I've got my own widget over here. I use it as my Appbar. I want it to be gradient with opacity but it doesn't work. Actually I thought that when I place the BoxDecoration into that first Container it will work. I am pretty new to flutter. Any advice? The first part is my widget. The second ist my Home class where I set it as my appbar.
Widget customAppBar(double width) {
return PreferredSize(
preferredSize: Size.fromHeight(124),
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color(0xff101010).withOpacity(1),
Color(0xff101010).withOpacity(0.82),
Color(0xff101010).withOpacity(0)
],
),
),
width: width,
// height: 124,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 30, top: 44, bottom: 13),
width: 134,
height: 39,
child: FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5),
),
color: Color(0xffff163c),
child: Text(
"LOCKDOWN",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontFamily: 'Assistant',
),
),
onPressed: () {},
),
),
Container(
margin: EdgeInsets.only(top: 20, right: 12, left: 48),
height: 76,
width: 152,
child: Image.asset(
'assets/images/xy.png',
fit: BoxFit.none,
),
)
],
),
),
);
}
class Home extends StatefulWidget {
#override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
#override
Widget build(BuildContext context) {
MediaQueryData queryData = MediaQuery.of(context);
return Scaffold(
// resizeToAvoidBottomInset: false,
backgroundColor: Color(0xff101010),
// extendBodyBehindAppBar: true,
appBar: customAppBar(queryData.size.width),
body: SingleChildScrollView(
child: Body(),
),
);
}
}

Related

remove border in background in flutter

I'm confused how to make the colored border cut off, when I meet the word "Month", I tried with BoxDecoration(color: Colors.transparent), but it doesn't produce anything, the border still doesn't get cut.
like the following :
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
#override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Container(
decoration: BoxDecoration(color: Colors.blue),
child: Center(
child: Container(
width: 120,
height: 110,
decoration: BoxDecoration(color: Colors.pink),
child: Stack(
children: [
Positioned(
bottom: 0,
child: Container(
height: 55,
width: 120,
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.all(Radius.circular(10)),
border: Border.all(width: 2, color: Colors.white),
),
),
),
Positioned(
left: (120 - 50) / 2,
top: 45,
child: Container(
width: 50,
height: 15,
decoration:
BoxDecoration(color: Colors.black.withOpacity(0.1)),
child: Center(
child: Text("Month"),
),
),
),
],
),
),
),
)),
);}}
I want a look like this:
Please for the guidance, Thank you
A sample quick trick to have the effect you want is to set the background color for your positioned text as the same as your pink container:
child: Container(
width: 50,
height: 15,
padding: const EdgeInsets.all(5.0) <- with this too
decoration:
BoxDecoration(color: Colors.pink,), <- here
child: Center(
child: Text("Month"),
),
try this
Scaffold(
body: Stack(
children: <Widget>[
Container(
width: double.infinity,
height: 200,
margin: EdgeInsets.fromLTRB(20, 20, 20, 10),
padding: EdgeInsets.only(bottom: 10),
decoration: BoxDecoration(
color: Colors.green,
border: Border.all(width: 2, color: Colors.white),
borderRadius: BorderRadius.circular(15),
shape: BoxShape.rectangle,
),
),
Positioned(
left: 100,
top: 12,
child: Container(
padding: EdgeInsets.only(bottom: 10, left: 10, right: 10),
color: Colors.black.withOpacity(0.1),
child: Text(
'Month',
),
),
),
],
),
)

How to implement a Sliver App Bar with Tabs & other widgets above Tabs?

How to implement a SliverAppBar with Tabs & Widgets above Tabs?
How to create a SliverAppBar like Talabat App:
Please, check the below - video.
How to solve it?
What can I do?
I am doing...
https://youtube.com/shorts/HeuOTpdRZYY
I tried the below code:
=========================================================
class HomeScreen extends StatelessWidget {
const HomeScreen({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
var textTheme = Theme.of(context).textTheme;
// return Scaffold(
// body: NestedScrollView(
// headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
// return <Widget>[
// const SliverAppBar(
// backgroundColor: Colors.red,
// flexibleSpace: FlexibleSpaceBar(),
// )
// ];
// },
// body: Container(
// child: Builder(builder: (context) {
// return Column(
// mainAxisAlignment: MainAxisAlignment.start, children: const []);
// }),
// ),
// ),
// );
return Scaffold(
body: CustomScrollView(
slivers: [
SliverAppBar(
pinned: true,
expandedHeight: 500,
toolbarHeight: AppSize.s60,
collapsedHeight: 200,
leading: GestureDetector(
onTap: () {},
child: Center(
child: Container(
width: AppSize.s50,
height: AppSize.s44,
decoration: const BoxDecoration(
color: Palette.kPrimaryColor,
borderRadius: BorderRadius.all(
Radius.circular(AppSize.s10),
),
),
child: Center(
child: SvgPicture.asset(
AppAssets.menu,
height: AppSize.s14,
),
),
),
),
),
title: const Text(
"FASDFASD F",
style: TextStyle(
color: Colors.black,
),
),
actions: [
const SizedBox(width: AppSize.s10),
IconButton(
onPressed: () {},
splashRadius: AppSize.s28,
icon: SvgPicture.asset(
AppAssets.shoppingCart,
height: AppSize.s32,
),
),
],
flexibleSpace: Container(
color: Colors.deepOrange,
// height: 250,
child: Column(
children: [
Container(
height: 100,
color: Colors.green,
margin: const EdgeInsets.all(10),
),
Container(
height: 100,
color: Colors.black,
margin: const EdgeInsets.all(10),
),
Container(
height: 100,
color: Colors.black26,
margin: const EdgeInsets.all(10),
),
Container(
height: 100,
color: Colors.black45,
margin: const EdgeInsets.all(10),
),
Container(
height: 120,
color: Colors.blueGrey,
),
],
),
),
bottom: const CustomAppBarBottom(),
backgroundColor: Palette.kWhiteColor,
),
SliverToBoxAdapter(
child: Column(
children: [
Container(
height: 100,
color: Colors.green,
margin: const EdgeInsets.all(10),
),
Container(
height: 100,
color: Colors.purple,
margin: const EdgeInsets.all(10),
),
Container(
height: 100,
color: Colors.purple,
margin: const EdgeInsets.all(10),
),
Container(
height: 100,
color: Colors.green,
margin: const EdgeInsets.all(10),
),
Container(
height: 100,
color: Colors.purple,
margin: const EdgeInsets.all(10),
),
Container(
height: 100,
color: Colors.purple,
margin: const EdgeInsets.all(10),
),
Container(
height: 100,
color: Colors.green,
margin: const EdgeInsets.all(10),
),
Container(
height: 100,
color: Colors.purple,
margin: const EdgeInsets.all(10),
),
Container(
height: 100,
color: Colors.green,
margin: const EdgeInsets.all(10),
),
Container(
height: 100,
color: Colors.black87,
margin: const EdgeInsets.all(10),
),
],
),
),
],
),
);
}
}
class CustomAppBarBottom extends StatelessWidget
implements PreferredSizeWidget {
const CustomAppBarBottom({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
var outlineInputBorder = OutlineInputBorder(
borderRadius: AppRadius.bottomRadius,
borderSide: BorderSide.none,
);
return Container(
margin: EdgeInsets.symmetric(
horizontal: getUIPadding(context),
vertical: 10,
),
decoration: BoxDecoration(
color: Palette.kWhiteColor,
borderRadius: AppRadius.bottomRadius,
boxShadow: const [
BoxShadow(
color: Color.fromARGB(20, 0, 0, 0),
blurRadius: 7,
)
],
),
child: TextFormField(
style: const TextStyle(
height: 1.2,
),
decoration: InputDecoration(
hintText: "عن ماذا تبحث؟",
hintStyle: const TextStyle(
color: Palette.onboardingDescriptionColor,
),
prefixIcon: Align(
// alignment: Alignment.centerRight,
widthFactor: 1.0,
child: SvgPicture.asset(
AppAssets.search,
width: AppSize.s25,
),
),
isDense: true,
border: outlineInputBorder,
errorBorder: outlineInputBorder,
enabledBorder: outlineInputBorder,
focusedBorder: outlineInputBorder,
disabledBorder: outlineInputBorder,
focusedErrorBorder: outlineInputBorder,
),
),
);
}
#override
Size get preferredSize => const Size.fromHeight(AppSize.s60);
}
This widget give you some sample idea, Also check SliverPersistentHeader for custom header. You can check sliver_tools package for pinned header. Also TabBar can be replace with scroll_to_index.
class TestWidget extends StatefulWidget {
const TestWidget({Key? key}) : super(key: key);
#override
State<TestWidget> createState() => _TestWidgetState();
}
class _TestWidgetState extends State<TestWidget>
with SingleTickerProviderStateMixin {
late final TabController tabController =
TabController(length: 10, vsync: this);
double itemHeight = 120;
double? appBarHeight;
late final ScrollController controller = ScrollController()
..addListener(() {
if (controller.hasClients) {
final moveTo =
((controller.offset - appBarHeight!) / itemHeight).toInt();
tabController.animateTo(moveTo < 0 ? 0 : moveTo);
setState(() {});
}
});
#override
Widget build(BuildContext context) {
return Scaffold(
body: LayoutBuilder(builder: (context, constraints) {
appBarHeight ??= constraints.maxHeight;
return CustomScrollView(
controller: controller,
slivers: [
SliverAppBar(
pinned: true,
expandedHeight: constraints.maxHeight * .7,
bottom: PreferredSize(
child: TabBar(
controller: tabController,
tabs: List.generate(
10,
(index) => Container(
width: 100,
height: 40,
alignment: Alignment.center,
color: index == tabController.index
? Colors.deepOrange
: Colors.cyanAccent,
child: Text("$index"),
)),
),
preferredSize: Size.fromHeight(kToolbarHeight),
),
),
SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) {
return Container(
height: itemHeight,
color: index.isEven ? Colors.green : Colors.pink,
width: constraints.maxWidth,
);
},
),
)
],
);
}),
);
}
}

fade growing animation flutter

I am trying to achieve the following result in one of my app in flutter.
But I cannot figure out how to animate the "SKYGOAL" text that comes fading and sliding.
I've animated the rest of the components using AnimatedContainer or AnimatedOpacity, but I've been stuck on this one. I am new to animations so I don't know much.
Any help would be useful.
Thank you!
My current related snippet is :
class SplashScreen1 extends StatefulWidget {
const SplashScreen1({Key? key}) : super(key: key);
#override
State<SplashScreen1> createState() => _SplashScreen1State();
}
class _SplashScreen1State extends State<SplashScreen1> with SingleTickerProviderStateMixin {
double _skygoalLogoOpacity = 0;
double _syjOpacity = 0;
double _skygoalTextWidth = 0;
#override
void initState() {
// TODO: implement initState
super.initState();
Future.delayed(const Duration(seconds: 0)).then((value) => setState(() {
_skygoalLogoOpacity = 1;
_syjOpacity = 1;
_skygoalTextWidth = 2000;
}));
Future.delayed(const Duration(milliseconds: 4800)).then((value) => Navigator.pushReplacement(context, AnimatedPageRoute(SplashScreen2())));
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
color: Color(0xFF0E3C6E),
width: MediaQuery.of(context).size.width,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
SizedBox(height: 250,),
Stack(
children: [
Container(
decoration: BoxDecoration(
shape: BoxShape.circle, color: Colors.white
),
height: 185,
width: 185,
),
AnimatedOpacity(
duration: const Duration(milliseconds: 1000),
opacity: _skygoalLogoOpacity,
child: Container(
padding: EdgeInsets.only(top: 20),
child: Image.asset("assets/images/skygoal-logo.png"),
// height: 135,
width: 164,
),
),
],
),
Stack(
children: [
AnimatedOpacity(
duration: const Duration(milliseconds: 2000),
opacity: _syjOpacity,
child: Container(
margin: EdgeInsets.only(left: 40, top: 37),
height: 29,
width: 153,
child: Image.asset("assets/images/start-your-journey.png"),
),
),
Container(
margin: EdgeInsets.only(top: 5,left: 20),
child: Text(
"SKYGOAL",
style: GoogleFonts.poppins(
fontSize: 30,
fontWeight: FontWeight.w800,
color: Colors.white
),
textAlign: TextAlign.center,
),
),
],
),
Spacer(),
Text(
"By Skygoal",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 13
),
),
Container(
margin: EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10)
),
height: 5,
width: 134,
)
],
),
),
);
}
}
You can try animated_text_kit fade transition.
Example from doc
return SizedBox(
width: 250.0,
child: DefaultTextStyle(
style: const TextStyle(
fontSize: 32.0,
fontWeight: FontWeight.bold,
),
child: AnimatedTextKit(
animatedTexts: [
FadeAnimatedText( "SKYGOAL"),
],
onTap: () {
print("Tap Event");
},
),
),
);
I dont know whether it is the correct solution or not, But you can try something like this . I created a stack and its first child is the text and the other child is a container with boxShadow . Have a look at this.
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key,}) : super(key: key);
#override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
#override
Widget build(BuildContext context) {
MediaQueryData mediaQueryData = MediaQuery.of(context);
return Scaffold(
appBar: AppBar(),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
height: mediaQueryData.size.width,
width: mediaQueryData.size.width,
child: ColoredBox(
color: Colors.yellowAccent,
child: Stack(
alignment: Alignment.centerRight,
children: [
Container(
width: mediaQueryData.size.width,
height: 80,
alignment: Alignment.center,
child: Text(
'Hello World',
style: TextStyle(
fontSize: mediaQueryData.textScaleFactor * 50,
),
),
),
TweenAnimationBuilder(
tween: Tween<double>(
end: 0,
begin: 1,
),
duration: const Duration(
seconds: 5,
),
builder: (context, double tween, _ ){
return Container(
//alignment: Alignment.centerRight,
height: 50, //mediaQueryData.size.width,
width: mediaQueryData.size.width * tween,
decoration: const BoxDecoration(
color: Colors.yellowAccent,
boxShadow: [
BoxShadow(
blurRadius: 80,
spreadRadius: 30,
color: Colors.yellowAccent,
),
]
),
);
},
)
],
),
),
)
],
),
),
);
}
}

Flutter - Align widget all the way to the end of a card view. (View image included)

how can I get the flat button to fill the area under the divider all the way to the end of the card, it appears to not be able to go any further down.
See the white space under the FlatButton? I want it to look like the FlatButton is the end.
Doesn't have to be a flat button, any widget with onTap/press/(or a something hack-ish with gesture detector) listener would be fine.
Dart code is ->
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(4.0),
child: Card(
elevation: 5,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(15))
),
child: Container(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 24, bottom: 16),
child: Text(_label, style: TextStyle(fontSize: 24, color: Color.fromARGB(190, 0, 0, 0), fontWeight: FontWeight.bold)),
),
Divider(color: Colors.black26, height: 2,),
Padding(
padding: const EdgeInsets.all(24.0),
child: Text(_information, style: TextStyle(fontSize: 20, color: Colors.black87)),
),
Divider(color: Colors.black26, height: 2,),
SizedBox(width: double.infinity, child: FlatButton(onPressed: () => _onTap(), color: Color.fromARGB(50, 100, 100, 100), child: Text('Done', style: TextStyle()), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5))))
],
),
),
),
);
}
Please see the code below, I'm using InkWell & Container :
import 'package:flutter/material.dart';
final Color darkBlue = const Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
//theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
String _label = "";
String _information = "";
return Padding(
padding: const EdgeInsets.all(4.0),
child: Card(
elevation: 5,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(15))),
child: Container(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 24, bottom: 16),
child: Text(_label,
style: TextStyle(
fontSize: 24,
color: Color.fromARGB(190, 0, 0, 0),
fontWeight: FontWeight.bold)),
),
Divider(
color: Colors.black26,
height: 2,
),
Padding(
padding: const EdgeInsets.all(24.0),
child: Text(_information,
style: TextStyle(fontSize: 20, color: Colors.black87)),
),
Divider(
color: Colors.black26,
height: 2,
),
Spacer(),
InkWell(
onTap: () {}, //_onTap(),
child: Container(
width: double.infinity,
height: 40,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: const Color.fromARGB(50, 100, 100, 100)),
child: const Center(child: Text('Done', style: TextStyle())),
),
)
],
),
),
),
);
}
}
I solved my code like this, setting a height factor it did what i wanted automatically.
SizedBox(width: double.infinity, height: 60, child:
FlatButton(onPressed: () => _onTap(), color: Colors.transparent, child:
Text('Done', style: TextStyle()), shape: RoundedRectangleBorder(borderRadius:
BorderRadius.only(bottomLeft: Radius.circular(15), bottomRight: Radius.circular(15)))))
Only downside is that you have to specify a height rather than letting the widget adjust that based on content. Although there is probably a workaround for that.

Overflow visible in Expanded widget

My layout is a row with three expanded widgets.
I need overflow visible in one of the expanded widgets
This is the code
Row(
children: [
Expanded(
flex: 1,
child: Container(color: Colors.red,)
),
Expanded(
flex: 2,
child: Container(color: Colors.green,)
),
Expanded(
flex: 3,
child: Container(color: Colors.orange,)
),
],
),
Now I need to add circles like this, in of the Expanded widgets, that overflow the Expanded widget. I can't wrap the Expanded in an overflow box, so I am lost
Any help is appreciated.
Edit: I tried this with the third expanded, just to see if it will overflow, but it only overflows the SizedOverflowBox, no overflow over the Expanded
Expanded(
flex: 3,
child: SizedOverflowBox(
size: const Size(100.0, 100.0),
alignment: AlignmentDirectional.bottomCenter,
child: Container(height: 50.0, width: 1500.0, color: Colors.blue,),
),
),
It looks like it is not going to be possible
Can easily be achieved with a Stack. Please see the code below :
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Stack(
children: [
Row(
children: [
Expanded(
flex: 1,
child: Container(
color: Colors.red,
)),
Expanded(
flex: 2,
child: Container(
color: Colors.green,
)),
Expanded(
flex: 3,
child: Container(
color: Colors.orange,
)),
],
),
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
height: 25,
width: 25,
decoration:
BoxDecoration(color: Colors.black, shape: BoxShape.circle),
child: Center(
child: Container(
height: 15,
width: 15,
decoration: BoxDecoration(
color: Colors.white, shape: BoxShape.circle),
),
),
),
Container(
height: 25,
width: 25,
decoration:
BoxDecoration(color: Colors.black, shape: BoxShape.circle),
child: Center(
child: Container(
height: 15,
width: 15,
decoration: BoxDecoration(
color: Colors.white, shape: BoxShape.circle),
),
),
),
Container(
height: 25,
width: 25,
decoration:
BoxDecoration(color: Colors.black, shape: BoxShape.circle),
child: Center(
child: Container(
height: 15,
width: 15,
decoration: BoxDecoration(
color: Colors.white, shape: BoxShape.circle),
),
),
),
],
),
),
],
);
}
}
Please see the code for Text Bullet points overflowing.
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(),
body: MyWidget(),
),
);
}
}
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
flex: 1,
child: Container(
color: Colors.red.withAlpha(60),
child: OverflowBox(
alignment: Alignment.topLeft,
maxWidth: 400,
child: SizedBox(
width: 300,
child: Text(
'HelloHello 🅐',
style: TextStyle(color: Colors.white),
),
),
),
),
),
Expanded(
flex: 2,
child: Container(
color: Colors.green.withAlpha(60),
child: OverflowBox(
alignment: Alignment.topLeft,
maxWidth: 400,
child: SizedBox(
width: 300,
child: Container(
child: Text(
'\n\nHelloHello HelloHello 🅐\n\nHelloHello HelloHello 🅐\n\nHelloHello HelloHello 🅐\n\nHelloHello HelloHello 🅐',
style: TextStyle(color: Colors.white),
),
),
),
),
),
),
Expanded(
flex: 3,
child: Container(
color: Colors.purple.withAlpha(60),
child: OverflowBox(
alignment: Alignment.topLeft,
maxWidth: 400,
child: SizedBox(
width: 300,
child: Text(
'\n\n\n\n\n\n\n\n\n\n\n\Hello Hello Hello Hello Hello Hello ',
style: TextStyle(color: Colors.white),
),
),
),
),
),
],
);
}
}