How to have a circle shape like this in flutter? - user-interface

I am trying to have a circle shape like this in my flutter project. I tried using border-radius in a container. But it didn't work as I expected.
So, how can I have a shape like this given picture?
I tried using a container like this.
Container(
height: 72,
width: 211,
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.only(
topRight: Radius.circular(50),
topLeft: Radius.circular(30))
),
)

You can draw almost anything using CustomPaint, take a look:
https://api.flutter.dev/flutter/rendering/CustomPainter-class.html
In the code below, I draw something like that circle:
import "package:flutter/material.dart";
void main() {
runApp(MaterialApp(title: "", home: Home()));
}
class Home extends StatefulWidget {
#override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(),
body: Container(
width: double.infinity,
height: double.infinity,
child: CustomPaint(
painter: CirclePainter(),
)),
),
);
}
}
class CirclePainter extends CustomPainter {
final Paint lightBluePaint = Paint()..color = Color(0xFFbde5fa);
final Paint bluePaint = Paint()..color = Color(0xFF5abef2);
final TextPainter textPainter = TextPainter(
textDirection: TextDirection.ltr,
);
final TextStyle textStyle = TextStyle(
color: Colors.white.withAlpha(240),
fontSize: 18,
letterSpacing: 1.2,
fontWeight: FontWeight.w900);
#override
void paint(Canvas canvas, Size size) {
var rect = Rect.fromLTRB(
-100, size.height - 120, size.width * 0.7, size.height + 250);
final Path circle = Path()..addOval(rect);
final Path smallCircle = Path()..addOval(rect.inflate(50));
canvas.drawPath(smallCircle, lightBluePaint);
canvas.drawPath(circle, bluePaint);
drawText(canvas, size, 'Write now');
}
void drawText(Canvas canvas, Size size, String text) {
textPainter.text = TextSpan(style: textStyle, text: text);
textPainter.layout();
textPainter.paint(canvas, Offset(50, size.height - 60));
}
#override
bool shouldRepaint(CustomPainter oldDelegate) {
return true;
}
}

to implement your image preview you need to use Stack Class with Positioned elements. I made a widget as your picture shown. circles in corners can be made with container with border-radius.
Container(
width: MediaQuery.of(context).size.width,
height: 250,
margin: EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: <BoxShadow>[
BoxShadow(
color: Color(0x40000000),
blurRadius: 5.0,
spreadRadius: 0.0,
offset: Offset(0.0, 2.0),
),
],
),
child: Stack(
children: <Widget>[
Container(
padding: EdgeInsets.all(15.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Step 3',
style: TextStyle(
color: Colors.blue,
),
),
SizedBox(height: 5),
Text(
'It is a long established fact that a reader will be '
'distracted by the readable content of a page when '
'looking at its layout.',
style: TextStyle(
color: Colors.black54,
),
)
],
),
),
Positioned(
top: 150,
right: MediaQuery.of(context).size.width - 200,
child: Container(
width: 200,
height: 200,
decoration: BoxDecoration(
color: Color(0xFFB5E1F9),
borderRadius: BorderRadius.all(
Radius.circular(200),
),
),
child: Center(
child: Container(
width: 150,
height: 150,
decoration: BoxDecoration(
color: Color(0xFF4FB6F0),
borderRadius: BorderRadius.all(
Radius.circular(150),
),
),
),
),
),
),
Positioned(
bottom: 30,
left: 30,
child: Text(
'Write now',
style: TextStyle(
color: Colors.white,
),
),
),
],
),
);

Related

How to display active textfields hidden by the front panel?

I have been trying to display backdrop with searching fiture. but when I tap the textfield is hidden by front panel. how to front panel not hidden the search textfield ?
import 'package:flutter/material.dart';
import 'content_isi.dart';
class Panel extends StatefulWidget {
final AnimationController controller;
Panel({this.controller});
#override
_PanelState createState() => new _PanelState();
}
class _PanelState extends State<Panel> {
static const header_height = 200.0;
Animation<RelativeRect> getPanelAnimation(BoxConstraints constraints) {
final height = constraints.biggest.height;
final backPanelHeight = height - header_height;
final frontPanelHeight = -header_height;
return new RelativeRectTween(
begin: new RelativeRect.fromLTRB(
0.0, backPanelHeight, 0.0, frontPanelHeight),
end: new RelativeRect.fromLTRB(0.0, 0.0, 0.0, 0.0))
.animate(new CurvedAnimation(
parent: widget.controller, curve: Curves.linear));
}
Widget bothPanels(BuildContext context, BoxConstraints constraints) {
final ThemeData theme = Theme.of(context);
return new Container(
child: new Stack(
children: <Widget>[
new Container(
color: Colors.white,
child: Column(
children: <Widget>[
TextField(
decoration:
_buildInputDecoration(Icons.tune, 'Jenis Peraturan'),
),
Divider(
height: 0.0,
color: Colors.grey,
),
TextField(
decoration: _buildInputDecoration(Icons.pages, 'Nomor'),
),
Divider(
height: 0.0,
color: Colors.grey,
),
TextField(
decoration: _buildInputDecoration(Icons.pages, 'Tahun'),
),
Divider(
height: 0.0,
color: Colors.grey,
),
TextField(
decoration:
_buildInputDecoration(Icons.help_outline, 'Tentang'),
),
Container(
padding: EdgeInsets.only(left: 5.0, right: 5.0),
width: double.infinity,
child: FlatButton(
onPressed: () {},
child: Text(
'Cari',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 16),
),
color: Colors.blue,
),
),
],
),
),
new PositionedTransition(
rect: getPanelAnimation(constraints),
child: new Material(
elevation: 12.0,
child: ListView(
children: <Widget>[
ContentIsi(
no: '11',
th: '2020',
jnsperaturan: 'Peraturan BBB',
judul:
'Perubahan Keempat Atas Peraturan Nomor 1 Tahun 2017 tentang Pelimpahan Kewenangan Penandatanganan Perizinan dan Non Perizinan Kepada Kepala Dinas Penanaman Modal dan Pelayanan Terpadu Satu Pintu',
onPressed: null,
)
],
),
),
)
],
),
);
}
#override
Widget build(BuildContext context) {
return new LayoutBuilder(
builder: bothPanels,
);
}
InputDecoration _buildInputDecoration(IconData icon, String hintText) {
return InputDecoration(
prefixIcon: Padding(
padding: const EdgeInsets.only(right: 32.0, left: 16.0),
child: Icon(icon),
),
hintText: hintText,
contentPadding: const EdgeInsets.symmetric(vertical: 16.0),
border: InputBorder.none,
);
}
}
I'm the beginner of flutter. so i hope you can help me about it.
the gif image in the below :
in the image gif the textfield hidden by front pannel (listview) when I tap the textfield. how to fix it ????

Flutter :- Align a icon to the right bottom of a container

I tried a column with an aligned icon but it didn't display correctly
If anyone has any idea to help. It would be greatly appreciated. Thank you
This is my code that i tried
List<Widget> temp = [];
listAirline.map((airline) {
listAirlineName.map((item) {
if (airline.name == item) {
temp.add(
Column(
children: <Widget>[
Container(
height: 20,
decoration: BoxDecoration(
color: Colors.white,
borderRadius:
BorderRadius.all(Radius.elliptical(100.0, 60.0)),
),
child: Image.asset(
"images/Airlines/" + airline.id + ".jpg",
fit: BoxFit.fitWidth,
),
),
Align(
alignment: Alignment.bottomRight,
child: Icon(
Icons.remove_circle,
color: Colors.white,
),
)
],
),
);
}
}).toList();
}).toList();
return temp;
}```
You need to use the Stack widget for it, i have done similar task with the use of the Stack widget,please check thee below solution
class HomeScreen extends StatefulWidget {
#override
State<StatefulWidget> createState() {
// TODO: implement createState
return _HomeScreen();
}
}
class _HomeScreen extends State<HomeScreen> {
#override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: AppBar(
title: Text("Home"),
),
body: Container(
height: 100.0,
child: Align(
alignment: Alignment.topCenter,
child: Stack(
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 20.0),
height: MediaQuery.of(context).size.width*0.15,
width: MediaQuery.of(context).size.width*0.4,
child: Container(
margin: EdgeInsets.all(5.0),
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.all(Radius.elliptical(20.0, 20.0)),
),
),
)
,
Positioned(
right: 5.0,
bottom: 0.0,
child:
Icon(
Icons.remove_circle,
color: Colors.red,
),
)
],
),
)));
}
}
And output of the above code is as follow

how i can add validator: (value) { if (value.isEmpty) { return 'Please enter some text'; } return null; }, );

import 'package:awwapp/Auth/registration.dart';
import 'package:flutter/material.dart';
// import 'package:flutter/services.dart';
class LoginPage extends StatefulWidget {
#override
_LoginPageState createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
TextStyle style = TextStyle(fontFamily: 'Montserrat', fontSize: 20.0);
final _formKey = GlobalKey<FormState>();
#override
Widget build(BuildContext context) {
final emailField = TextField(
obscureText: false,
style: style,
decoration: InputDecoration(
contentPadding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
hintText: "Email",
border:
OutlineInputBorder(borderRadius: BorderRadius.circular(32.0))),
);
final passwordField = TextField(
obscureText: true,
style: style,
decoration: InputDecoration(
contentPadding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
hintText: "Password",
border:
OutlineInputBorder(borderRadius: BorderRadius.circular(32.0))),
);
final loginButon = Material(
elevation: 5.0,
borderRadius: BorderRadius.circular(30.0),
color: Color(0xff01A0C7),
child: MaterialButton(
minWidth: MediaQuery.of(context).size.width,
padding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
onPressed: () {},
child: Text("Login",
textAlign: TextAlign.center,
style: style.copyWith(
color: Colors.white, fontWeight: FontWeight.bold)),
),
);
final registrationButton = Material(
elevation: 5.0,
borderRadius: BorderRadius.circular(30.0),
color: Color(0xff01A0C7),
child: MaterialButton(
minWidth: MediaQuery.of(context).size.width,
padding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => RegistrationPage()),
);
},
child: Text("Register",
textAlign: TextAlign.center,
style: style.copyWith(
color: Colors.white, fontWeight: FontWeight.bold)),
),
);
return Scaffold(
body: Form(
key: _formKey,
child: Center(
child: Container(
color: Colors.white,
child: Padding(
padding: const EdgeInsets.all(36.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
height: 155.0,
child: Image.asset(
"assets/logo/logo.png",
fit: BoxFit.contain,
),
),
SizedBox(height: 45.0),
emailField,
SizedBox(height: 25.0),
passwordField,
SizedBox(
height: 35.0,
),
loginButon,
SizedBox(
height: 15.0,
),
registrationButton,
],
),
),
),
),
),
);
}
}
"TextFormField(
// The validator receives the text that the user has entered.
validator: (value) {
if (value.isEmpty) {
return 'Please enter some text';
}
return null;
},
); "
here is the my whole code
i am creating login for my project and i want to validate these fields that is mention at above and i want to add code that i mentioned in double qoutes how i can add these code in my above mention code
i Want to validate these fields but i am facing errors plz help me how can i add
how i can add code mention in double quotes in my above code
You already have a form. What you need to change the TextField to TextFormField.
TextFormField supports the validator method.
See the complete sample at bottom of this link
https://flutter.dev/docs/cookbook/forms/validation

How to convert RenderBox global position coordinates for Tween<Offset>?

I'm attempting to create my own Hero style transition using a SlideTransition with the position Offset starting at where the user taps the item on the previous screen.
This is what I'm currently using for receiving the coordinate value of where the user is tapping the screen (I only need the dy value):
GestureDetector(
child: //stuff
onTapDown: (TapDownDetails details) async {
RenderBox box = context.findRenderObject();
double position = box.localToGlobal(details.globalPosition).dy;
await Navigator.push(context, MaterialPageRoute(builder: (context) {
return SecondPage(startPosition: position);
}));
},
)
I then pass this onto the SecondPage and use it as the starting position of the Animation<Offset> in my initState:
#override
void initState() {
controller = new AnimationController(
duration: const Duration(milliseconds: 2000), vsync: this);
curve = CurvedAnimation(parent: controller, curve: Curves.easeInOut);
offset = new Tween<Offset>(begin: Offset(0.0, widget.startPosition), end: Offset.zero).animate(curve);
controller.forward();
super.initState();
}
The issue I'm having is finding a way to properly convert the dy value to one which matches what the Tween<Offset> uses as the dy value comes in with a value of say 250-300 for half way down the screen but the same for the Offset(0.0, widget.startPosition) would be around 2.0 for it to match the same position. I've tried various maths to match these (such as dividing the dy by the screens height) but I haven't found anything which matches it exactly.
If anyone knows the correct method/exact maths I have to perform on matching these values I'll love you forever.
Edit: Self contained example of what I'm trying to achieve which you can play around with. This is currently with me using double position = (box.globalToLocal(details.globalPosition).dy) / box.size.height * 3; as this is around the closest match I've found.
import 'package:flutter/material.dart';
class HomePage extends StatefulWidget {
#override
State createState() => HomePageState();
}
class HomePageState extends State<HomePage> {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.indigo.shade200,
floatingActionButton: Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).size.height / 35),
child: FloatingActionButton(
child: Icon(Icons.add),
backgroundColor: Colors.grey.shade200,
foregroundColor: Colors.black,
onPressed: () {},
)),
body: Stack(children: <Widget>[
SingleChildScrollView(
child: Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).size.height / 11),
child:
Column(children: <Widget>[Stack(children: getCards())]))),
Container(
height: MediaQuery.of(context).size.height / 5,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Colors.grey.shade200,
borderRadius:
BorderRadius.only(bottomLeft: Radius.circular(100.0))),
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
InkWell(
child: Padding(
padding: EdgeInsets.all(6.0),
child: Container(
height: 40.0,
width: 40.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
width: 2.0, color: Colors.pink.shade300)),
child: Icon(Icons.sentiment_satisfied),
),
)),
Text('Tab1',
style: TextStyle(
fontSize: 10.0,
fontWeight: FontWeight.bold,
color: Colors.black38))
],
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
InkWell(
child: Padding(
padding: EdgeInsets.all(6.0),
child: Container(
height: 40.0,
width: 40.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
width: 2.0, color: Colors.pink.shade300)),
child: Icon(Icons.trending_up),
),
)),
Text('Tab2',
style: TextStyle(
fontSize: 10.0,
fontWeight: FontWeight.bold,
color: Colors.black38))
],
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
InkWell(
child: Padding(
padding: EdgeInsets.all(6.0),
child: Container(
height: 40.0,
width: 40.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
width: 2.0, color: Colors.pink.shade300)),
child: Icon(Icons.favorite_border),
),
)),
Text('Tab3',
style: TextStyle(
fontSize: 10.0,
fontWeight: FontWeight.bold,
color: Colors.black38))
],
)
])))
]));
}
List<Widget> getCards() {
List<Widget> widgets = new List<Widget>();
for (int i = 0; i < 5; i++) {
widgets.add(GestureDetector(
child: Container(
margin: EdgeInsets.only(top: (i * 175).toDouble()),
padding: EdgeInsets.all(60.0),
height: 300.0,
decoration: BoxDecoration(
color: getColor(i),
borderRadius: BorderRadius.only(bottomLeft: Radius.circular(100.0)),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Center(
child: Text('Text ' + (i + 1).toString(),
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.white,
fontSize: 26.0,
fontWeight: FontWeight.bold)))
],
),
),
onTapDown: (TapDownDetails details) async {
RenderBox box = context.findRenderObject();
double position = (box.globalToLocal(details.globalPosition).dy) / box.size.height * 3;
await Navigator.push(context, CustomPageRoute(builder: (context) {
return SecondPage(index: i, startPosition: position);
}));
},
));
}
return widgets.reversed.toList();
}
}
class SecondPage extends StatefulWidget {
final int index;
final double startPosition;
SecondPage({this.index, this.startPosition});
#override
State createState() => SecondPageState();
}
class SecondPageState extends State<SecondPage> with TickerProviderStateMixin {
AnimationController controller;
Animation curve;
Animation<Offset> offset;
#override
void initState() {
controller = new AnimationController(
duration: const Duration(milliseconds: 2000), vsync: this);
curve = CurvedAnimation(parent: controller, curve: Curves.easeInOut);
offset = new Tween<Offset>(
begin: Offset(0.0, widget.startPosition), end: Offset.zero)
.animate(curve);
controller.forward();
super.initState();
}
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.indigo,
body: Material(
color: Colors.transparent,
child: Stack(children: <Widget>[
SlideTransition(
position: offset,
child: Container(
height: 200.0,
decoration: BoxDecoration(
color: getColor(widget.index),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(100.0))),
child: Padding(
padding: EdgeInsets.only(top: 28.0),
child: Stack(
children: <Widget>[
Align(
alignment: Alignment.topLeft,
child: IconButton(
icon: Icon(Icons.arrow_back,
color: Colors.white),
onPressed: () {
Navigator.of(context).pop(true);
},
)),
Align(
alignment: Alignment.topRight,
child: IconButton(
icon:
Icon(Icons.launch, color: Colors.white),
onPressed: () {
print("launch website");
},
)),
Align(
alignment: Alignment.center,
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: MediaQuery.of(context)
.size
.width /
5),
child: Material(
color: Colors.transparent,
child: Text('Text ' + (widget.index + 1).toString(),
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.white,
fontSize: 26.0,
fontWeight:
FontWeight.bold)))))
],
))))
])));
}
}
class CustomPageRoute<T> extends MaterialPageRoute<T> {
CustomPageRoute({WidgetBuilder builder, RouteSettings settings})
: super(builder: builder, settings: settings);
#override
Widget buildTransitions(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation, Widget child) {
return child;
}
}
Color getColor(int index) {
switch (index) {
case 0:
return Colors.pink.shade300;
case 1:
return Colors.purple.shade300;
case 2:
return Colors.deepPurple.shade400;
case 3:
return Colors.deepPurple.shade900;
case 4:
return Colors.indigo.shade900;
default:
return Colors.red;
}
}
Finding a renderBox is not useful in this case, because all of the cards are places in a stack the context.findRenderObject finds the top most stack. That stack covers the entire screen so when you transform from global to local position you get the same position.
You can calculate the correct offset for you second screen like this:
var scrollOffset = controller.position.pixels;
double position = ((i * 175).toDouble() + 100 - scrollOffset) / 200;
(i * 175) : Offset of every card from the top.
100 : Height difference between height of cards in the first screen
and second screen (300 in first and 200 in second). We add this to
compansate for the difference so the cards position will be the
same.
200 : Height of the card in the second screen. We divide by this
because
The translation is expressed as an Offset scaled to the child's size
Finally you will need to give a scrollController to your SingleChildScrollView to get the scroll offset. Without the scroll offset you can't calculate the correct position if the cards are scrolled (i.e Card 4 or Card 5)
Here is how your HomePageState should look like.
class HomePageState extends State<HomePage> {
ScrollController controller = new ScrollController();
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.indigo.shade200,
floatingActionButton: Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).size.height / 35),
child: FloatingActionButton(
child: Icon(Icons.add),
backgroundColor: Colors.grey.shade200,
foregroundColor: Colors.black,
onPressed: () {},
)),
body: Stack(children: <Widget>[
SingleChildScrollView(
controller: controller,
child: Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).size.height / 11),
child:
Column(children: <Widget>[Stack(children: getCards())]))),
Container(
height: MediaQuery.of(context).size.height / 5,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Colors.grey.shade200,
borderRadius:
BorderRadius.only(bottomLeft: Radius.circular(100.0))),
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
InkWell(
child: Padding(
padding: EdgeInsets.all(6.0),
child: Container(
height: 40.0,
width: 40.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
width: 2.0, color: Colors.pink.shade300)),
child: Icon(Icons.sentiment_satisfied),
),
)),
Text('Tab1',
style: TextStyle(
fontSize: 10.0,
fontWeight: FontWeight.bold,
color: Colors.black38))
],
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
InkWell(
child: Padding(
padding: EdgeInsets.all(6.0),
child: Container(
height: 40.0,
width: 40.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
width: 2.0, color: Colors.pink.shade300)),
child: Icon(Icons.trending_up),
),
)),
Text('Tab2',
style: TextStyle(
fontSize: 10.0,
fontWeight: FontWeight.bold,
color: Colors.black38))
],
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
InkWell(
child: Padding(
padding: EdgeInsets.all(6.0),
child: Container(
height: 40.0,
width: 40.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
width: 2.0, color: Colors.pink.shade300)),
child: Icon(Icons.favorite_border),
),
)),
Text('Tab3',
style: TextStyle(
fontSize: 10.0,
fontWeight: FontWeight.bold,
color: Colors.black38))
],
)
])))
]));
}
List<Widget> getCards() {
List<Widget> widgets = new List<Widget>();
for (int i = 0; i < 5; i++) {
widgets.add(GestureDetector(
child: Container(
margin: EdgeInsets.only(top: (i * 175).toDouble()),
padding: EdgeInsets.all(60.0),
height: 300.0,
decoration: BoxDecoration(
color: getColor(i),
borderRadius: BorderRadius.only(bottomLeft: Radius.circular(100.0)),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Center(
child: Text('Text ' + (i + 1).toString(),
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.white,
fontSize: 26.0,
fontWeight: FontWeight.bold)))
],
),
),
onTapDown: (TapDownDetails details) async {
var scrollOffset = controller.position.pixels;
double position = ((i * 175).toDouble() + 100 - scrollOffset) / 200;
await Navigator.push(context, CustomPageRoute(builder: (context) {
return SecondPage(index: i, startPosition: position);
}));
},
));
}
return widgets.reversed.toList();
}
}

How to create a transparent UI in flutter?

I want to create a tranparent UI in flutter.
Can you help me with the code?
Here is the link to the stuff I need.
https://dribbble.com/shots/3958928-Wikipedia-App/attachments/904403
https://dribbble.com/shots/1081917-WhereTO-App
https://dribbble.com/shots/1539644-App-Mockup
https://dribbble.com/shots/1254375-Events-More/attachments/171069
This example my help to resolve your problem
Code Snippet
Widget build(BuildContext context) {
List list = ['Introduction','Early life', 'Non-Film work', '2012-present', 'Controversy'];
return new Container(
child: new Stack(
fit: StackFit.expand,
children: <Widget>[
new Image.asset('assets/bg_img.jpg', fit: BoxFit.fitHeight,),
new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
elevation: 0.0,
backgroundColor: const Color(0xFFB4C56C).withOpacity(0.5),
),
backgroundColor: Colors.transparent,
body: new Center(
child: new Center(
child: new BackdropFilter(
filter: new ui.ImageFilter.blur(
sigmaX: 6.0,
sigmaY: 6.0,
),
child: new Container(
margin: EdgeInsets.all(20.0),
padding: EdgeInsets.all(20.0),
decoration: BoxDecoration(
color: const Color(0xFFB4C56C).withOpacity(0.01),
borderRadius: BorderRadius.all(Radius.circular(50.0)),
),
child: new Container(child: ListView.builder(itemBuilder: (contex, index){
return index == 0?new Container(
height: 50.0,
alignment: Alignment.centerLeft,
padding: EdgeInsets.only(left: 12.0),
decoration: BoxDecoration(
color: const Color(0xFFB4C56C).withOpacity(0.7),
borderRadius: BorderRadius.all(Radius.circular(25.0)),
boxShadow: [new BoxShadow(color: Colors.black12,offset: new Offset(2.0, 2.0), blurRadius: 2.0 )]
),child: new Row(children: <Widget>[
new Icon(Icons.info, color: Colors.white,),
new SizedBox(width: 8.0),
new Text(list[index], style: TextStyle(color: Colors.white70, fontSize: 18.0))
],),
):new ListTile(title: new Text(list[index], style: TextStyle(color: Colors.white),), leading: new Text('${index}',
style: TextStyle(color: const Color(0xFFB4C56C), fontSize: 18.0)),);
}, itemCount: list.length,),),
),
),
),
),
)
],),
);
}
Complete source code can be dowloaded from here blue_effect
You can override PageRoute like this
import 'package:flutter/cupertino.dart';
class TransparentRoute extends PageRoute<void> {
TransparentRoute({
#required this.builder,
RouteSettings settings,
}) : assert(builder != null),
super(settings: settings, fullscreenDialog: false);
final WidgetBuilder builder;
#override
bool get opaque => false;
#override
Color get barrierColor => null;
#override
String get barrierLabel => null;
#override
bool get maintainState => true;
#override
Duration get transitionDuration => Duration(milliseconds: 350);
#override
Widget buildPage(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation) {
final result = builder(context);
return FadeTransition(
opacity: Tween<double>(begin: 0, end: 1).animate(animation),
child: Semantics(
scopesRoute: true,
explicitChildNodes: true,
child: result,
),
);
}
}
/// And you can push like this
Navigator.of(context).push(
TransparentRoute(
builder: (BuildContext
context) =>
TransParentView()));
///New container to push
class TransParentView extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black.withOpacity(0.6),
body: Padding(
padding: const EdgeInsets.all(27.0),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(5))),
height: 700,
width: MediaQuery.of(context).size.width,
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
height: 60,
),
Container(
width: 160,
height: 100,
),
Container(
height: 290,
width: 250,
),
Container(
height: 150,
),
],
),
),
),
),
);
}
}
Hope this will help.
Just surround the widget or widget tree you want to make transparent with an Opacity widget and specify the opacity value from 0.0 to 1.0
For example:
0.0 means completely invisible,
0.5 means half way transparent,
1.0 means fully visible.

Resources