flutter: image overlap card - flutter

i'm new to flutter and i wanted to create simple design for menu app as shown in image below ... i tried below code but it didn't give same design, is there any way to achieve it?
enter image description here
import 'package:flutter/material.dart';
main() => runApp(test());
class test extends StatefulWidget {
#override
_testState createState() => _testState();
}
class _testState extends State<test> {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("Card over stack"),
),
body: Stack(
children: <Widget>[
Align(
alignment: Alignment.topCenter,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(10.0)),
color: Colors.lightBlueAccent),
height: 100,
),
),
Positioned(
top: 60,
right: 10,
left: 10,
child: Card(
child: ListTile(
leading: SizedBox(
height: 150.0,
width: 150.0, // fixed width and height
child: Image.asset("assets/images/test.png"))),
),
),
],
),
),
);
}
}

Stack is the rignt choice, check screenshot below:
Full working code:
import 'package:flutter/material.dart';
main() => runApp(const DemoApp());
class DemoApp extends StatefulWidget {
const DemoApp({Key? key}) : super(key: key);
#override
State<StatefulWidget> createState() {
return _DemoState();
}
}
class _DemoState extends State<DemoApp> {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Stack(
alignment: Alignment.bottomCenter,
children: [
Container(
color: Colors.white,
),
Positioned(
bottom: 150,
// replace with your Card here
child: Card(
child: Container(
width: 250,
height: 300,
color: Colors.blue,
),
),
),
Positioned(
bottom: 320,
// replace with your image here
child: Container(
width: 200,
height: 280,
color: Colors.pink,
),
),
],
),
),
);
}
}

Here is a solution for this. You can also refer to the following link to learn more.
https://www.flutterbeads.com/flutter-position-widget-in-stack/
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
);
}
}
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) {
return Scaffold(
body: Container(
height: MediaQuery.of(context).size.height,
decoration: const BoxDecoration(
color: Colors.redAccent,
//add your gradiant here
),
child: SafeArea(
child: Stack(
alignment: AlignmentDirectional.topCenter,
children: [
Positioned(
top: 180,
child: Container(
width: MediaQuery.of(context).size.width * 0.9,
height: 500,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(7),
),
),
),
Positioned(
top: 20,
child: Container(
width: MediaQuery.of(context).size.width * 0.7,
height: 200,
decoration: BoxDecoration(
color: Colors.blueAccent,
borderRadius: BorderRadius.circular(7),
),
//add your image here
//child: Center(child: Image.asset(name)),
),
),
],
),
),
),
);
}
}

Related

Flutter : How to make button like this [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 months ago.
Improve this question
i want to make button like this
The background is of different colors and shapes
Text and icon
Here is a complete code for making one of the buttons. you can play with bordet radius to build other buttons as well.
enter code here import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
final Overlay overlay = const Overlay();
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: '3D Button',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const Home(),
);
}
}
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
#override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: colors[50],
appBar: AppBar(
title: const Center(
child: Text("3D Button"),
),
),
// body: const ClickyButtonPage(),
body: Center(child: const Custom3DButton()),
);
}
}
const MaterialColor colors = Colors.blue;
const MaterialColor colors2 = Colors.grey;
class Custom3DButton extends StatelessWidget {
const Custom3DButton({
Key? key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
double _width = 220;
double _height = 65;
double _sideWidth = 180;
var _borderRadius = const Radius.circular(50);
return Container(
width: _width,
height: 70.0,
child: GestureDetector(
child: Stack(children: <Widget>[
Positioned(
bottom: 0,
child: Container(
width: _width,
height: _height,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(_borderRadius),
color: colors[800],
),
),
),
Positioned(
left: 0,
bottom: 0,
child: Container(
width: _sideWidth * 5 / 6,
height: _height,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: _borderRadius, topLeft: _borderRadius),
color: colors2[400],
),
),
),
Container(
width: _width,
height: _height,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(_borderRadius),
color: Colors.blue,
),
),
Positioned(
left: 0,
child: Container(
width: _sideWidth,
height: _height,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(_borderRadius),
color: Colors.white,
),
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.menu_rounded,
size: 34,
color: Colors.blue,
),
const SizedBox(
width: 10,
),
Text(
'SETTING',
style: TextStyle(color: colors[600], fontSize: 24),
),
],
),
),
),
),
]),
),
);
}
}
Here is the screen shot for this example;

Flutter: rounded corner container

i am new to flutter. How can I indent the corners like in the picture? Thanks for answers.
exapmle
You should be checking if the problem you faced asked before. There are tons of sources related to this.
1- There are containers with one rounded border in the example video you provided. To achieve that, check the following code:
BoxDecoration(
color: color,
borderRadius: const BorderRadius.only(
bottomLeft: Radius.circular(100.0),
),
);
2- To have multiple containers on top of each other, you need to use the Stack widget like the following:
Stack(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height * 0.90,
decoration: decoration(Colors.black),
),
Container(
height: MediaQuery.of(context).size.height * 0.70,
decoration: decoration(Colors.purple),
),
Container(
height: MediaQuery.of(context).size.height * 0.45,
decoration: decoration(Colors.pink),
),
Container(
height: MediaQuery.of(context).size.height * 0.20,
decoration: decoration(Colors.white),
),
],
),
Complete code main.dart:
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) => MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
);
}
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) => Scaffold(
backgroundColor: Colors.grey,
body: Stack(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height * 0.90,
decoration: decoration(Colors.black),
),
Container(
height: MediaQuery.of(context).size.height * 0.70,
decoration: decoration(Colors.purple),
),
Container(
height: MediaQuery.of(context).size.height * 0.45,
decoration: decoration(Colors.pink),
),
Container(
height: MediaQuery.of(context).size.height * 0.20,
decoration: decoration(Colors.white),
),
],
),
floatingActionButton: FloatingActionButton(
onPressed: () {},
tooltip: 'Add',
backgroundColor: Colors.white,
child: const Icon(
Icons.add,
color: Colors.black,
),
),
);
BoxDecoration decoration(Color color) => BoxDecoration(
color: color,
borderRadius: const BorderRadius.only(
bottomLeft: Radius.circular(100.0),
),
);
}
You can also access the complete source code through GitHub.
If you have further questions, please don't hesitate to write in the comments.

How to add highlight overlay around the widget upon click?

I'm working on simple design system using Flutter. I want to highlight a widget upon selection (click), as you can see in the below images button get highlighted upon click. It gets handle and border.
Challenging part: I don't want layout getting changed as additional space taken by handle and border upon click. I want widget, handle and border are overlaid, so that it wouldn't shift the position of other neighbouring widgets.
And after selection
You could also use a Stack with the overlay bleeding out of the Stack thanks to a clipBehavior of Clip.none.
Full code
Just copy paste it in a DartPad to see it in action.
import 'package:flutter/material.dart';
const kcPrimary = Color(0xFF001989);
const kcSecondary = Color(0xFF239689);
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.light(),
debugShowCheckedModeBanner: false,
home: const HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: const [
Text('Blablablablabla'),
Text('Blablablablabla'),
Text('Blablablablabla'),
PlayButton(),
Text('Blablablablabla'),
Text('Blablablablabla'),
Text('Blablablablabla'),
],
),
),
),
);
}
}
class PlayButton extends StatefulWidget {
const PlayButton({Key? key}) : super(key: key);
#override
State<PlayButton> createState() => _PlayButtonState();
}
class _PlayButtonState extends State<PlayButton> {
bool clicked = false;
#override
Widget build(BuildContext context) {
return Stack(
clipBehavior: Clip.none,
children: [
InkWell(
onTap: () => setState(() => clicked = !clicked),
child: _mainButton,
),
if (clicked) ...[
Positioned.fill(
child: IgnorePointer(
child: _overlayBorder,
),
),
Positioned(
top: -20.0,
left: 0,
child: _overlayTitle,
),
Positioned(top: 0, right: 0, child: _corner),
Positioned(bottom: 0, right: 0, child: _corner),
Positioned(bottom: 0, left: 0, child: _corner),
Positioned(top: 0, left: 0, child: _corner),
],
],
);
}
Widget get _mainButton => Container(
width: 80.0,
height: 40.0,
decoration: BoxDecoration(
border: Border.all(
color: kcPrimary,
width: 3.0,
),
borderRadius: const BorderRadius.all(Radius.circular(12))),
child: Center(
child: Row(
mainAxisSize: MainAxisSize.min,
children: const [
Icon(Icons.play_arrow),
Text('Play'),
],
),
),
);
Widget get _overlayBorder => Container(
decoration: BoxDecoration(
border: Border.all(
color: kcSecondary,
width: 3.0,
),
),
);
Widget get _corner => Container(width: 10, height: 10, color: kcSecondary);
Widget get _overlayTitle => Container(
height: 20.0,
width: 48.0,
color: kcSecondary,
alignment: Alignment.center,
child: const Text(
'Button',
style: TextStyle(
color: Colors.white,
fontSize: 10,
fontWeight: FontWeight.bold,
),
),
);
}

Flutter integration_test: How to simulate mouse wheel scroll operation over `SingleChildScrollView` Widget?

Implementing some integration_test for flutter-web application wherein I'm trying to simulate mouse wheel scroll operation , I have SingleChildScrollView widget with series of Container in it...trying to scroll to end of the list?
I've tried the following without any success.
main.dart
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
#override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: SingleChildScrollView(
controller: ScrollController(),
scrollDirection: Axis.vertical,
child: Column(
children: [
Container(
height: 100,
width: double.infinity,
color: Colors.red,
),
Container(
height: 100,
width: double.infinity,
color: Colors.green,
),
Container(
height: 100,
width: double.infinity,
color: Colors.blue,
),
Container(
height: 100,
width: double.infinity,
color: Colors.purple,
),
Container(
height: 100,
width: double.infinity,
color: Colors.yellow,
),
Container(
height: 100,
width: double.infinity,
color: Colors.black12,
),
Container(
height: 100,
width: double.infinity,
color: Colors.orangeAccent,
),
Container(
height: 100,
width: double.infinity,
color: Colors.pink,
),
Container(
height: 100,
width: double.infinity,
color: Colors.amber,
),
],
)),
floatingActionButton: FloatingActionButton(
onPressed: () {},
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
app_test.dart
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:hello_world/main.dart' as app;
void main() async {
group('Complete E2E Test', () {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
setUp(() {
app.main();
});
testWidgets('Hello World test', (WidgetTester tester) async {
final Offset scrollEventLocation = tester.getCenter(find.byType(SingleChildScrollView));
final TestPointer testPointer = TestPointer(1, PointerDeviceKind.mouse);
testPointer.hover(scrollEventLocation);
final HitTestResult result = tester.hitTestOnBinding(scrollEventLocation);
await tester.sendEventToBinding(testPointer.scroll(const Offset(0.0, 200)));
await tester.sendEventToBinding(testPointer.scroll(const Offset(600, 200)));
await tester.pumpAndSettle(const Duration(seconds: 5));
});
});
}

Flutter: How to create a beautiful Curve oval shape Container / Divider between other widgets in Flutter

How to create this beautiful curve shape divider in a flutter App.
Simply use this customDivider as your divider
customDivider(String title) {
return Row(
children: [
Expanded(
child: Container(
color: Colors.white,
height: 10,
),
),
Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(13),
color: Colors.white,
),
child: Center(child: Text(title)),
),
Expanded(
child: Container(
color: Colors.white,
height: 10,
),
),
],
);
}
Here is an example
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> {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey,
appBar: AppBar(
title: Text(widget.title),
),
body: ListView.builder(
itemCount: 5,
shrinkWrap: true,
itemBuilder: (context, index) => listItem(index),
),
);
}
customDivider(String title) {
return Row(
children: [
Expanded(
child: Container(
color: Colors.white,
height: 10,
),
),
Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(13),
color: Colors.white,
),
child: Center(child: Text(title)),
),
Expanded(
child: Container(
color: Colors.white,
height: 10,
),
),
],
);
}
listItem(int index) {
return Column(
children: [
Container(
height: 200,
width: 200,
margin: EdgeInsets.all(10),
color: index.isEven ? Colors.orange : Colors.deepPurpleAccent,
),
customDivider("your title"),
],
);
}
}
OUTPUT:
There can be many ways to do this in flutter. This is one of the simplest approach.
main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: SafeArea(
child: SO(),
),
);
}
}
class SO extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.pink.shade100,
appBar: AppBar(),
body: Center(
child: CapsuleWidget(
label: 'organizing data'.toUpperCase(),
ribbonHeight: 8,
),
),
);
}
}
class CapsuleWidget extends StatelessWidget {
final Color fillColor;
final Color textColor;
final String label;
final double ribbonHeight;
final double ribbonRadius;
const CapsuleWidget({
Key key,
this.fillColor = Colors.white,
this.textColor = Colors.black,
#required this.label,
#required this.ribbonHeight,
this.ribbonRadius = 1000,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Row(
children: <Widget>[
Expanded(
child: Container(
height: ribbonHeight,
color: fillColor,
),
),
Container(
decoration: BoxDecoration(color: fillColor, borderRadius: BorderRadius.circular(ribbonRadius)),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Text(
label,
style: TextStyle(color: textColor, fontWeight: FontWeight.w500),
),
),
),
Expanded(
child: Container(
height: ribbonHeight,
color: fillColor,
),
),
],
);
}
}
it use Stack class
link url : https://api.flutter.dev/flutter/widgets/Stack-class.html
pseudo code
Stack {
Container(), // background
Contanier(), // white Line
Text() , // center Text
}