I want to write text with transparent color on image. like this.
I want to write text over the image but I am not able to do it properly.
This is my code.
I want to write text over the image but I am not able to do it properly.
And I also want transparent color for text.
Please help me.
import 'package:card_example/color_filters.dart';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
static final String title = 'Card Example';
#override
Widget build(BuildContext context) => MaterialApp(
debugShowCheckedModeBanner: false,
title: title,
theme: ThemeData(primarySwatch: Colors.deepOrange),
home: MainPage(title: title),
);
}
class MainPage extends StatefulWidget {
final String title;
const MainPage({
#required this.title,
});
#override
_MainPageState createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
#override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: ListView(
padding: EdgeInsets.all(16),
children: [
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24),
),
child: Stack(
alignment: Alignment.center,
children: [
Ink.image(
image: NetworkImage(
'https://resources.pulse.icc-cricket.com/ICC/photo/2018/04/22/c19486c2-4e5b-48c4-82af-c6d0eebb7bd2/Main.jpg',
),
colorFilter: ColorFilters.greyscale,
child: InkWell(
onTap: () {},
),
height: 240,
fit: BoxFit.cover,
),
Text(
'Sachin Tendulkar',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 24,
),
),
],
),
)
],
),
);
}}
I want to write text over the image but I am not able to do it properly.
And I also want transparent color for text.
Please help me.
If want to use for that container and I use decoration for image text widget for text then how to make exact that thing like is in image.
If you consider splashColor, there are multiple ways to handle this:
using Ink.image() inside Stack will not provide circular borderRadius. Check this GitHub issue. is still open.
ClipRRect(
borderRadius: BorderRadius.circular(12),
child: SizedBox(
width: 300,
height: 300,
child: Stack(
fit: StackFit.expand,
children: [
Align(
alignment: Alignment.bottomCenter,
child: Container(
width: double.infinity,
padding: EdgeInsets.all(8),
color: Colors.blue.withOpacity(.5),
child: Text(
'Sachin Tendulkar',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 24,
),
),
),
),
Ink.image(
image: NetworkImage(
'https://resources.pulse.icc-cricket.com/ICC/photo/2018/04/22/c19486c2-4e5b-48c4-82af-c6d0eebb7bd2/Main.jpg',
),
fit: BoxFit.cover,
child: InkWell(
borderRadius: BorderRadius.circular(12),
onTap: () {},
),
),
],
)),
);
1: Using GridTile
Container(
width: 300,
height: 300,
color: Colors.transparent,
child: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: InkWell(
onTap: () {},
child: GridTile(
child: Image.network(
'https://resources.pulse.icc-cricket.com/ICC/photo/2018/04/22/c19486c2-4e5b-48c4-82af-c6d0eebb7bd2/Main.jpg',
fit: BoxFit.cover,
),
footer: Container(
padding: EdgeInsets.all(8),
color: Colors.blue.withOpacity(.5),
child: Text(
'Sachin Tendulkar',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 24,
),
),
),
),
),
),
);
2: Using decoration of Container
InkWell(
onTap: () {},
splashColor: Colors.red,
child: Container(
width: 300,
height: 300,
alignment: Alignment.bottomCenter,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
image: DecorationImage(
image: NetworkImage(
'https://resources.pulse.icc-cricket.com/ICC/photo/2018/04/22/c19486c2-4e5b-48c4-82af-c6d0eebb7bd2/Main.jpg',
),
fit: BoxFit.cover,
),
),
child: Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.blue.withOpacity(.5),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(12),
bottomRight: Radius.circular(12),
),
),
padding: EdgeInsets.all(8),
child: Text(
'Sachin Tendulkar',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 24,
),
),
),
),
);
Try adding bottomCenter to alignment
Stack(
alignment: Alignment.bottomCenter, //Here
children: [
Ink.image(
image: NetworkImage(
'https://static.remove.bg/remove-bg-web/3661dd45c31a4ff23941855a7e4cedbbf6973643/assets/start_remove-79a4598a05a77ca999df1dcb434160994b6fde2c3e9101984fb1be0f16d0a74e.png',
),
child: InkWell(
onTap: () {},
),
height: 240,
fit: BoxFit.cover,
),
Text(
'Sachin Tendulkar',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 24,
),
),
],
);
Result:
Related
I Want show Image above the Container Using Stack Widget but I don't Know how to do
I'm Tried Position and Align Widget it's Work but image half Image Not visible
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:navami/Controller/FirebaseController.dart';
import 'package:navami/env.dart';
import '../DatabaseServices/dbServices.dart';
import 'wallet.dart';
class DetailScreen extends StatelessWidget {
final String imageId;
final Map data;
DetailScreen(this.imageId, this.data);
final FirebaseController controller = Get.find();
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
alignment: Alignment.center,
children: [
Hero(
tag: imageId,
child: Center(
child: Container(
alignment: Alignment.center,
height: 250,
width: 350,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25),
image: DecorationImage(
image: NetworkImage(
data['image'],
),
fit: BoxFit.cover),
),
),
),
),
Text(
data['title'],
style: Theme.of(context).textTheme.displaySmall,
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
height: MediaQuery.of(context).size.height / 1.5,
decoration: BoxDecoration(
color: Colors.blue[600],
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(25),
topRight: Radius.circular(25))),
),
),
],
),
}));
}
}
This is Emulator ScreenShot
Screen Top 30 Padding after image and above the container then center of the container text
So I want this type of Screen
class WelcomeScreen extends StatelessWidget {
#override
Widget build(BuildContext context) {
double h = MediaQuery.of(context).size.height;
double w = MediaQuery.of(context).size.width;
return Scaffold(
body: Container(
height: h,
width: w,
child: Stack(
children: [
Container(
child: Image.asset(
'assets/images/welcome.png',
),
),
Positioned(
bottom: 10.0,
child: Container(
// height: h * 0.4,
width: w,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20.0),
topRight: Radius.circular(20.0),
)),
child: Column(
children: [
Container(
height: 140,
width: 200,
child: SvgPicture.asset(
'assets/images/Logoforstaicimage.svg',
),
),
SizedBox(
height: 10.0,
),
Container(
padding: EdgeInsets.only(left: 24, right: 24.0),
child: Text(
"Fitness is POWERFUL!! My mission is to bring people together, from all walks of life, with varying goals and abilities.",
textScaleFactor: 0.85,
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'Raleway',
color: Color(0xff76767c),
fontSize: 17,
fontWeight: FontWeight.w500,
fontStyle: FontStyle.normal,
letterSpacing: 0,
),
),
),
],
),
),
),
],
),
),
);
}
}
I want to add an image in the background. I found this code snippet here in StackOverflow.
SizedBox.expand(
// -> 01
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
'https://wallpapercave.com/wp/wp5561184.jpg'),
fit: BoxFit.cover, // -> 02
),
),
),
),
this worked quite well for me in this code:
enter codeimport 'package:flutter/material.dart';
class Welcome extends StatelessWidget {
final int _picState;
final VoidCallback _picStateChange;
final Function _quizStarted;
Welcome(this._quizStarted, this._picState, this._picStateChange);
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
alignment: AlignmentDirectional.bottomCenter,
children: [
SizedBox.expand(
// -> 01
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
'https://wallpapercave.com/wp/wp5561184.jpg'),
fit: BoxFit.cover, // -> 02
),
),
),
),
SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Spacer(),
Text(
'Start Application',
style: Theme.of(context).textTheme.headline3?.copyWith(
color: Colors.white54,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
Spacer(),
Spacer(),
TextField(
onTap: () => _picStateChange(),
decoration: InputDecoration(
focusColor: Colors.amber,
filled: true,
fillColor: Colors.white.withOpacity(0.2),
hintText: 'ENTER YOUR NAME HERE',
hintStyle: TextStyle(
wordSpacing: 2,
fontWeight: FontWeight.bold,
color: Colors.white,
decoration: TextDecoration.underline),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(12))),
),
),
InkWell(
onTap: () => _quizStarted(),
child: Container(
width: double.infinity,
alignment: Alignment.center,
padding: EdgeInsets.all(15),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(20)),
gradient: (LinearGradient(
colors: [Colors.lime, Colors.blueGrey.shade700],
begin: Alignment.topRight,
end: Alignment.bottomLeft))),
child: Text('START THE APPLICATION',
style: Theme.of(context)
.textTheme
.button
?.copyWith(color: Colors.white38)),
),
),
Spacer(),
],
),
))
],
),
);
}
}
but when I used the same code in another section(the one below) the error "Failed assertion: line 1927 pos 12: 'hasSize'" appears
**import 'package:flutter/material.dart';
class Answer extends StatelessWidget {
final VoidCallback ansk;
final String gimme_Da_Answer;
Answer(this.ansk, this.gimme_Da_Answer);
#override
Widget build(BuildContext context) {
return Stack(
alignment: AlignmentDirectional.bottomCenter,
children: [
SizedBox.expand(
// -> 01
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
'https://wallpapercave.com/wp/wp5561184.jpg'),
fit: BoxFit.fitHeight, // -> 02
),
),
),
),
SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 18, horizontal: 17),
child: InkWell(
onTap: () => ansk(),
child: (Container(
child: Text(gimme_Da_Answer,textAlign: TextAlign.center,
style: TextStyle(
fontSize: 25,
color: Colors.cyan.shade800,
fontWeight: FontWeight.bold)),
width: double.infinity,
padding: EdgeInsets.all(15),
margin: EdgeInsets.all(10),
decoration: BoxDecoration(
border: Border.all(color: Colors.blue, width: 4),
color: Colors.blueAccent.shade100.withOpacity(0.4),
borderRadius: BorderRadius.all(Radius.circular(15))),
)),
),
),
),
]);
}
}**
^the code that shows error for me
THANKS A LOT!!!
The error occurs here because the Widget is looking for a size since fit has been set on the BoxDecoration. To solve this issue, set a width and height on the Container.
Container(
// set Container dimension
width: 100,
height: 100,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(),
fit: BoxFit.cover,
),
),
)
Hi I want to center a card which should be centered horizontally and vertically I am trying to acheive this via center widget Any idea how do i accomplish this task
This is what i am getting:
Here is my full updated code:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:provider/provider.dart';
import '../BackEnd/AuthenticationService.dart';
import 'Register.dart';
class PatientList extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: Container(
height: 174,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/patient_list.png'),
)),
child: Stack(
children: <Widget>[
Container(
alignment: Alignment.center,
height: 128,
child: Text(
'Patient List',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 30,
color: Colors.white),
),
),
Center(
child: Container(
height: 200,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
side: BorderSide(color: Color.fromRGBO(214, 0, 27, 1)),
),
child: Center(
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 10),
child: Row(
children: <Widget>[
Container(
child: Text("hello#xyz.com",
style: TextStyle(
fontWeight: FontWeight.normal,
color: Colors.black,
fontSize: 16)),
),
],
),
),
],
),
),
),
),
),
Container(
alignment: Alignment.bottomCenter,
child: ElevatedButton(
onPressed: () {
context.read<AuthenticationService>().signOut();
},
style: ElevatedButton.styleFrom(
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0),
side: BorderSide(color: Colors.red),
),
primary: Color.fromRGBO(214, 0, 27, 1)
),
child: Text(' Sign Out'.toUpperCase())
),
),
],
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
gotoRegister(BuildContext context) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Register()),
);
}
gotoRegister(context);
},
child: Icon(Icons.add),
backgroundColor: Color.fromRGBO(214, 0, 27, 1),
),
);
}
}
I want to center that card horizontally and vertically in the middle of the activity I hope i am now clear with my objectives as to what i want to achieve
Do you want to center the Text inside the card or the card itself? Generally just wrap it with a Center widget.
Your problem might be that you use row and column in the wrong place. Please share the complete code, to let me see what needs to be changed.
Center(
child: Container(
height: 200,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
side: BorderSide(color: Color.fromRGBO(214, 0, 27, 1)),
),
child: Center(
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 10),
child: Row(
children: <Widget>[
Container(
child: Text("hello#xyz.com",
style: TextStyle(
fontWeight: FontWeight.normal,
color: Colors.black,
fontSize: 16)),
),
],
),
),
],
),
),
),
),
);
This should be what you are looking for.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:provider/provider.dart';
import '../BackEnd/AuthenticationService.dart';
import 'Register.dart';
class PatientList extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
height: 174,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/patient_list.png'),
),
),
child: Stack(
children: <Widget>[
Container(
alignment: Alignment.center,
height: 128,
child: Text(
'Patient List',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 30, color: Colors.white),
),
),
Center(
child: Container(
height: 200,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
side: BorderSide(color: Color.fromRGBO(214, 0, 27, 1)),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 10),
child: Row(
children: <Widget>[
Container(
child: Text(
"hello#xyz.com",
style: TextStyle(fontWeight: FontWeight.normal, color: Colors.black, fontSize: 16),
),
),
],
),
),
Container(
alignment: Alignment.bottomCenter,
child: ElevatedButton(
onPressed: () {
context.read<AuthenticationService>().signOut();
},
style: ElevatedButton.styleFrom(
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0),
side: BorderSide(color: Colors.red),
),
primary: Color.fromRGBO(214, 0, 27, 1),
),
child: Text(
' Sign Out'.toUpperCase(),
),
),
),
],
),
),
),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Register()),
);
},
child: Icon(Icons.add),
backgroundColor: Color.fromRGBO(214, 0, 27, 1),
),
);
}
}
Please any expert who can suggest to me how to a background picture in this dashboard, I'll be very thankful.
When I add boxfit in the following scaffold widget the code got red lines.
Please any expert who can suggest to me how to a background picture in this dashboard, I'll be very thankful.
When I add boxfit in the following scaffold widget the code got red lines.
import 'package:google_fonts/google_fonts.dart';
import 'package:maps_app/screens/Dash_board.dart';
class Dashboard extends StatefulWidget {
static const routeName = '/home1';
#override
DashboardState createState() => new DashboardState();
}
class DashboardState extends State<Dashboard> {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xffffffff),
body: Column(
children: <Widget>[
SizedBox(
height: 110,
),
Padding(
padding: EdgeInsets.only(left: 16, right: 16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"ColorLine",
style: GoogleFonts.openSans(
textStyle: TextStyle(
color: Colors.black87,
fontSize: 24,
fontWeight: FontWeight.bold)),
),
SizedBox(
height: 4,
),
Text(
" Home",
style: GoogleFonts.openSans(
textStyle: TextStyle(
color: Color(0xff000000),
fontSize: 14,
fontWeight: FontWeight.w600)),
),
],
),
IconButton(
iconSize: 70,
alignment: Alignment.center,
icon: Image.asset(
"assets/colorline.png",
width: 100,
height: 100,
),
onPressed: () {},
)
],
),
),
SizedBox(
height: 40,
),
GridDashboard()
],
),
);
}
}
Scaffold(
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/background.jpeg"),
fit: BoxFit.cover,
),
),
child: ...
),
);
What you want to do is wrap your Scaffold with a Container Widget. Also, you need to make the Scaffold's color transparent. I will be using a bit of Vlad Konoshenko's answer to help you with this.
return Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/background.jpeg"),
fit: BoxFit.cover,
),
),
child: Scaffold(
backgroundColor: Colors.transparent,
// Rest of the code remains same.
...
),
);
I am trying to add a background to my home page, however, it does not seem to be working. Any thoughts? I know how to add it per se, but unsure of how to structure it. I had received some advice to use a Stack, but I am unfamiliar with this method and the resources online are not clear.
Any advice on how to structure this would be appreciated.
Here is the background image code:
Widget build(BuildContext context) {
return DecoratedBox(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/startbackground.jpg"),
fit: BoxFit.cover),
),
and here is the page code itself.
class MyHomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
color: Colors.orangeAccent,
height: double.infinity,
width: double.infinity,
alignment: Alignment.bottomLeft,
child: UnconstrainedBox(
child: Padding(
padding: const EdgeInsets.only(left: 50, bottom: 50),
child: Container(
height: 400,
width: 200,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
flex: 1,
child: Container(
child: Text(
"Text",
style: TextStyle(
fontSize: 30, fontWeight: FontWeight.w700),
textAlign: TextAlign.left,
),
color: Colors.purpleAccent,
),
),
Expanded(
flex: 3,
child: Container(
child: Text(
"Some Text",
style: TextStyle(
fontSize: 60, fontWeight: FontWeight.w700),
),
color: Colors.purpleAccent,
),
),
Expanded(
flex: 3,
child: Container(
child: Text(
"Some Text",
style: TextStyle(
fontSize: 60, fontWeight: FontWeight.w700),
),
color: Colors.teal,
),
),
Expanded(
flex: 2,
child: Padding(
padding: EdgeInsets.all(15),
child: FlatButton(
minWidth: 200,
onPressed: () {},
child: Text(
"Get Started",
style:
TextStyle(color: Color(0xff7638c9), fontSize: 15),
),
color: Colors.transparent,
shape: RoundedRectangleBorder(
side: BorderSide(color: Colors.purple),
borderRadius: BorderRadius.circular(18.0),
),
),
),
),
],
),
),
),
),
),
);
}
}
It's confusing, but we don't actually need a DecoratedBox, rather a BoxDecoration (inside your container, for the decoration: argument).
:P
Here's an example:
class BackgroundImagePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: BoxDecoration(
color: Colors.orangeAccent, // this has been moved up into BoxDeco
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
'https://i.pravatar.cc/300'
)
)
),
height: double.infinity,
width: double.infinity,
... <snip> ...
If the Scaffold is a child of the background image code, than I guess the Scaffold background color is hiding the image.
Set transparent background color for the Scaffold:
Scaffold(
backgroundColor: Color.transparent,
...
This ended up working. See below.
class MyHomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Stack(children: <Widget>[
Image.asset(
"assets/startbackground.jpg",
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
fit: BoxFit.cover,
),
Scaffold(
body: Container(
color: Colors.transparent,
height: double.infinity,
width: double.infinity,
alignment: Alignment.bottomLeft,
child: UnconstrainedBox(
child: Padding(
padding: const EdgeInsets.only(left: 50, bottom: 50),
child: Container(
height: 400,
width: 200,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
flex: 1,
child: Container(
child: Text(
"Text",
style: TextStyle(
fontSize: 30, fontWeight: FontWeight.w700),
textAlign: TextAlign.left,
),
color: Colors.transparent,
),
),
Expanded(
flex: 3,
child: Container(
child: Text(
"Some Text",
style: TextStyle(
fontSize: 60,fontWeight: FontWeight.w700),
),
color: Colors.transparent,
),
),
Expanded(
flex: 3,
child: Container(
child: Text(
"Some Text",
style: TextStyle(
fontSize: 60, fontWeight: FontWeight.w700),
),
color: Colors.transparent,
),
),
Expanded(
flex: 2,
child: Padding(
padding: EdgeInsets.all(15),
child: FlatButton(
minWidth: 200,
onPressed: () {},
child: Text(
"Get Started",
style: TextStyle(
color: Color(0xff7638c9), fontSize: 15),
),
color: Colors.transparent,
shape: RoundedRectangleBorder(
side: BorderSide(color: Colors.purple),
borderRadius: BorderRadius.circular(18.0),
),
),
),
),
],
),
),
),
),
),
)
]);
}
}