Design I want:
My current design:
How to make the letter back to normal color?
My code:
Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Stack(
children: [
Image.asset(
'assets/images/front_Page_Image.png',
height: 746,
width: constraints.maxWidth * 0.64,
fit: BoxFit.cover,
),
Image.asset(
'assets/images/half_circle.png',
color: Color.fromARGB(255, 255, 255, 255),
//colorBlendMode: BlendMode.srcOver,
)
],
),
],
),
You can use Opacity with color as below for transparent white background
color : Colors.white.withOpacity(0.5)
For image Opacity :
Container(
child: new Text(
'Hello world',
style: Theme.of(context).textTheme.display4
),
decoration: new BoxDecoration(
color: const Color(0xff7c94b6),
image: new DecorationImage(
fit: BoxFit.cover,
colorFilter: new ColorFilter.mode(Colors.black.withOpacity(0.2), BlendMode.dstATop),
image: new NetworkImage(
'http://www.allwhitebackground.com/images/2/2582-190x190.jpg',
),
),
),
),
It is required that the image you want to "remove the background" for, is transparent except for the text. Meaning what you'd like to remove the white for, is actually the Containers background. Meaning that you can use something like Colors.white.withOpacity(0.3) to achieve the transparency.
A complete example that will produce this image:
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(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const HomeScreen(),
);
}
}
class HomeScreen extends StatelessWidget {
const HomeScreen({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Stack(
children: [
Card(
child: Image.asset('assets/this_is_fine.jpg'),
),
Container(
width: MediaQuery.of(context).size.width * 0.5,
color: Colors.white.withOpacity(0.3),
child: Image.asset('assets/fine_text.png'),
)
],
)
],
),
);
}
}
I think you shouldn't wrap them in a Card. The first Container also serves no purpose. So like
Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Stack(
children: [
Image.asset(
'assets/images/front_Page_Image.png',
height: 746,
width: constraints.maxWidth * 0.64,
fit: BoxFit.cover,
),
Container(
alignment: Alignment.topLeft,
child: Image.asset(
'assets/images/half_circle.png'),
)
],
),
],
)
Related
I'm trying to let my users increase the size of an image inside a fixed size Stack.
The chosen size can be way above the Stack's size.
This is the result I get for now, even though the image :
Here is the relevant code :
Expanded(
child: AspectRatio(
aspectRatio: myCustomScreen.width / myCustomScreen.height,
child: ClipRRect(
borderRadius: BorderRadius.circular(14),
child: LayoutBuilder(
builder: (context, boxConstraint) {
return Stack(
alignment: Alignment.center,
fit: StackFit.passthrough,
children: [
Container(
color: Colors.blue,
),
//This object doesn't overflow when its width is above the
UnconstrainedBox(
child: Image(
width: (object.width.toDouble() * boxConstraint.biggest.width) / myCustomScreen.width,
image: NetworkImage("www.images.com/image.png", scale: 1)),
),
],
);
},
),
),
),
),
How can I let my users view the real size of the image inside this view without being constrained by the stack ?
Thank you !
Stack has a property called clipBehavior you can use it like this to enable overflow:
Stack(
clipBehavior: Clip.none,
// Your code continues here
Edit: Testing your code I made ti work on dart pad. The steps were, remove the UnconstrainedBox and used the image scale to resize it alongside with the fit property defined as none:
here's the code that I used on darted: https://dartpad.dartlang.org/
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
final String title;
const MyHomePage({
Key? key,
required this.title,
}) : super(key: key);
#override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
Expanded(
child: AspectRatio(
aspectRatio: 200 / 400,
child: ClipRRect(
borderRadius: BorderRadius.circular(14),
child: LayoutBuilder(
builder: (context, boxConstraint) {
return Stack(
clipBehavior: Clip.none,
alignment: Alignment.center,
fit: StackFit.passthrough,
children: [
Container(
color: Colors.blue,
),
Image(
fit: BoxFit.none,
image: NetworkImage(
"https://images.pexels.com/photos/13406218/pexels-photo-13406218.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2",
scale: 1 / (_counter + 1),
),
),
],
);
},
),
),
),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
How to put the widgets inside the mobile so that the picture is like a border, I want to put the widget inside the mobile frame, how can I do that?
Code:
Container(
decoration: BoxDecoration(
border: MobileImage(),
),
child: Widgets(),
),
You can try this code & I have added a screenshot also for your favor.
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SizedBox(
width: double.infinity,
height: double.infinity,
child: FractionallySizedBox(
widthFactor: 0.9,
heightFactor: 0.9,
child: Stack(
alignment: Alignment.bottomCenter,
children: [
Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/iphone13.png"),
fit: BoxFit.fill,
),
),
child: Container(),
),
Positioned(
child: FractionallySizedBox(
widthFactor: 0.8,
heightFactor: 0.9,
child: Container(
alignment: Alignment.centerLeft,
child: ListView.separated(
itemCount: 100,
itemBuilder: (context, index) {
return ListTile(
title: Text('Text ${index+1}'),
);
},
separatorBuilder: (context, index) {
return const SizedBox(height:10);
},
),
),
),
),
],
),
),
),
));
}
}
N.B: Here, "assets/images/iphone13.png" are the iPhone background image.
you can do like this,
Container(
decoration: BoxDecoration(
border: //your border,
image: DecorationImage(image: AssetImage(MobileImage()))
),
child: Widgets(),
),
and also u can use the stack widget to Put The Widgets Inside the border Image
I want a achieve a design like the one in the second screenshot with a faded background. So the upper half of the blurred background image is already fine, just the bottom half is missing a gradient into a fixed color (like black or white).
For clarification: I want only the background to fade into black without affecting the top layer (in this case the untouched image). I tried quite long now to get a suitable solution but unfortunately I did not find any.
Current state:
Goal:
Current code (first screenshot):
Container(
color: Colors.white,
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: CachedNetworkImageProvider(widget.storyData.coverURL),
fit: BoxFit.cover,
),
),
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 30, sigmaY: 30),
child: Container(
child: Padding(
padding: const EdgeInsets.all(80.0),
child: Hero(
tag: widget.heroTagID,
child: CachedNetworkImage(
imageUrl: widget.storyData.coverURL,
placeholder: (context, url) => Padding(
padding: EdgeInsets.all(25),
child: Icon(Ionicons.image_outline),
),
),
),
),
),
)),
);
You can achieve that using Stack and LinearGradient.
I've replaced CachedNetworkImageProvider with simple NetworkImage so that the code can work on https://dartpad.dev/. The principle remains the same:
import 'dart:ui';
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: <Widget>[
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
'https://picsum.photos/id/255/1440/3200',
),
fit: BoxFit.cover,
),
),
),
Container(
constraints: BoxConstraints.expand(),
decoration: BoxDecoration(
color: Colors.white,
gradient: LinearGradient(
begin: FractionalOffset.topCenter,
end: FractionalOffset.bottomCenter,
colors: [Colors.black.withOpacity(0.0), Colors.black],
stops: [0.0, 1.0]
)
),
),
BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
child: Center(
child: Padding(
padding: const EdgeInsets.all(80.0),
child: Hero(
tag: 'heroTag',
child: Image.network(
'https://picsum.photos/id/255/1440/3200',
)
),
),
)
),
],
);
}
}
You can tweak the colors and stops to get it exactly how you want it.
End result:
So I am trying to put my image logo on the background, but my background suddenly became cropped with half of a black screen appearing. As per picture:
My main.dart code:
import 'package:flutter/material.dart';
import 'login_page.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return new MaterialApp(
home: new LoginPage(),
theme: new ThemeData(
primarySwatch: Colors.green
)
);
}
}
my login_page.dart code:
import 'package:flutter/material.dart';
class LoginPage extends StatefulWidget{
#override
State createState() => new LoginPageState();
}
class LoginPageState extends State<LoginPage>{
#override
Widget build(BuildContext context){
return new Scaffold(
backgroundColor: Colors.transparent,
body: new Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset('assets/arrowPNG.png'),
]
),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/background.png"),
fit: BoxFit.cover,
)
)
)
);
}
}
It happened after putting the image logo which is 'Image.asset('assets/arrowPNG.png'),'. How do I resolve this?
Try this below code
class LoginPageState extends State<LoginPage>{
#override
Widget build(BuildContext context){
return new Scaffold(
backgroundColor: Colors.transparent,
body: new Container(
width: MediaQuery.of(context).size.width,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset('images/a_dot_ham.png'),
]
),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("images/background.jpg"),
fit: BoxFit.cover,
)
)
)
);
}
When you add the below line to your Container, the issue will get resolved
width: MediaQuery.of(context).size.width
Here is my result
Try to add, width: MediaQuery.of(context).size.width height: MediaQuery.of(context).size.height to Container like this,
Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset('assets/images/logo.png'),
]
),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/splash_bg.png"),
fit: BoxFit.cover,
)
)
)
Output
I would like to shrink and expand my Wrap widget when the size of the parent Container is increased or decreased. The fonts of the individual children should increase or decrease along with the size of the boxes. What is the best way to achieve this?
I have tried FittedBox (scaledDown) which reduces the sizes but then widget doesn't wrap at all (!) and all the children remain on one line.
This is the default behavious (if the Wrap widget is defined in a Container with a specific size).
Here is the code...
Widget _build(BuildContext context) {
var words = ["a", "abc", "de", "ef", "g", "i", "is", "s", "th"];
return new Scaffold(
body: Column(children: <Widget>[
Text('height 100'),
Container(
color: Colors.red,
height: 100.0,
child: Wrap(
alignment: WrapAlignment.spaceEvenly,
children: _buildWordButtons(words),
),
),
Text('height 50'),
Container(
color: Colors.green,
height: 50.0,
child: Wrap(
alignment: WrapAlignment.spaceEvenly,
children: _buildWordButtons(words),
),
),
Text('FittedBox, scaleDown, height 200'),
Container(
color: Colors.blue,
height: 200.0,
child: FittedBox(
fit: BoxFit.scaleDown,
child: Wrap(
alignment: WrapAlignment.spaceEvenly,
children: _buildWordButtons(words),
),
),
),
]),
);
}
List<Widget> _buildWordButtons(List<String> words) {
var buttons = List<Widget>();
for (var word in words) {
buttons.add(Container(
decoration: new BoxDecoration(border: new Border.all(color: Colors.black)),
child: Text(
word,
style: TextStyle(fontSize: 50.0),
),
margin: EdgeInsets.all(5.0),
));
}
return buttons;
}
If you'd like to create a Text widget that will adapt to the size of its parent widget, you may want to look into LayoutBuilder widget. Using this widget should help its child widget determine its parent widget's constraints. Since you've mentioned that having a spacious Container should print long texts in a newline, you can have it set inside the LayoutBuilder.
Here's a sample. I've modified the code snippet provided.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final words = ["a", "abc", "de", "ef", "g", "i", "is", "s", "th"];
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Column(children: <Widget>[
Text('height 100'),
Container(
color: Colors.red,
height: 100.0,
child: adaptiveText(),
),
Text('height 50'),
Container(
color: Colors.green,
height: 50.0,
child: adaptiveText(),
),
Text('height 200'),
Container(
alignment: Alignment.center,
color: Colors.blue,
height: 200.0,
child: adaptiveText(),
),
]),
);
}
adaptiveText() {
return LayoutBuilder(
builder: (context, constraints) {
debugPrint('constraint maxHeight: ${constraints.maxHeight}');
// adapt Text widget if parent widget size is <= 100
if (constraints.maxHeight <= 100)
return FittedBox(
fit: BoxFit.scaleDown,
child: Wrap(
alignment: WrapAlignment.spaceEvenly,
children: _buildWordButtons(words),
),
);
else
return Wrap(
alignment: WrapAlignment.spaceEvenly,
children: _buildWordButtons(words),
);
},
);
}
List<Widget> _buildWordButtons(List<String> words) {
var buttons = List<Widget>();
for (var word in words) {
buttons.add(Container(
decoration:
new BoxDecoration(border: new Border.all(color: Colors.black)),
child: Text(
word,
style: TextStyle(fontSize: 50.0),
maxLines: 3,
),
margin: EdgeInsets.all(5.0),
));
}
return buttons;
}
}
Demo