Why my fitted genextreme distribution have no mean/variance? - scipy

I have the following code for estimating a generalized extreme value distribution from scipy.
from scipy.stats import genextreme
ys = [22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.3, 22.3, 22.3, 22.3, 22.3, 22.3, 22.3, 22.3, 22.3, 22.3, 22.3, 22.3, 22.3, 22.3, 22.3, 22.3, 23.3, 23.3, 23.3, 23.3, 23.3, 23.3, 23.3, 23.3, 23.3, 23.3, 23.3, 23.3, 23.3, 23.3, 23.3, 23.3, 23.3, 23.3, 23.3, 23.3, 23.3, 23.3, 23.3, 23.3, 23.3, 23.3, 23.2, 23.2, 23.2, 23.2, 23.2, 23.2, 23.2, 23.2, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 29.9, 27.7, 27.7, 27.7, 27.7, 27.7, 27.7, 27.7, 27.7, 27.7, 27.7, 27.7, 27.7, 27.7, 27.7, 27.7, 27.7, 27.7, 27.7, 27.7, 27.7, 27.7, 27.7, 27.7, 27.7, 27.7, 27.7, 24.5, 24.5, 24.5, 24.5, 24.5, 24.5, 24.5, 24.5, 24.5, 26.6, 26.6, 26.6, 26.6, 26.6, 26.6, 26.6, 26.6, 26.6, 26.6, 26.6, 26.6, 26.6, 26.6, 26.6, 26.6, 26.6, 26.6, 26.6, 26.6, 26.6, 26.6, 26.6, 26.6, 26.6, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 23.7, 23.7, 23.7, 23.7, 23.7, 23.7, 23.7, 23.7, 23.7, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.9, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764, 22.058823529411764]
shape, loc, scale = genextreme.fit(ys)
mean, var = genextreme.stats(shape, loc, scale, moments='mv')
I got the following fitted parameters (shape, location and scale respecitvely):
-2.787020488783334
22.058823529411782
5.0707584099150134e-14
Thus, the shape is negative but the documentation on https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.genextreme.html allows the shape to go negative.
However, my mean and variance are both nan.
It looks like I can fit a model, and the fitted parameters look reasonable, but why am I unable to get a mean from the fitted distribution?

When the shape parameter is less than -1, the distribution is sufficiently "fat-tailed" that the mean and variance don't exist. This is noted in the table on the right side of the wikipedia article on the generalized extreme value distribution--but note that the sign of the shape parameter c used by genextreme is the opposite of the parameter ΞΎ in the wikipedia article.

Related

error when creating glm for gtsummary table

I am trying to build a logistic regression using the code below, but I encounter the error that I am unable to identify the cause of! I have compared the contents of my df to the example used in a recent gtsummary seminar (https://cran.r-project.org/web/packages/gtsummary/vignettes/tbl_regression.html) and I can't find the cause.
Error in glm(disease_present ~ disease_cat, sex, age, data = df, :
'weights' must be a numeric vector
Code
mod <- glm(disease_present ~ disease_cat, sex, age,
data = df, family = binomial)
Data
df <-
structure(
list(
disease_cat = structure(
c(
7L,
2L,
2L,
2L,
2L,
5L,
2L,
2L,
2L,
2L,
2L,
3L,
2L,
2L,
5L,
2L,
2L,
2L,
2L,
2L,
2L,
2L,
5L,
5L,
5L,
2L,
8L,
2L,
8L,
2L,
7L,
2L,
7L,
2L,
7L,
8L,
8L,
2L,
2L,
7L,
2L,
7L,
7L,
2L,
2L,
2L,
2L,
2L,
5L,
5L
),
.Label = c(
"breast",
"prostate",
"colorectal",
"lung",
"melanoma",
"bladder",
"pancreatic",
"endometrial"
),
class = "factor"
),
disease_present = c(
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
0,
1,
0,
0,
1,
0,
0,
0,
0,
0,
0,
0,
1,
1,
1,
0,
1,
0,
1,
0,
1,
0,
1,
0,
1,
1,
1,
0,
0,
1,
0,
1,
1,
0,
0,
0,
0,
0,
1,
1
),
sex = structure(
c(
2L,
2L,
1L,
2L,
1L,
2L,
1L,
2L,
1L,
1L,
2L,
1L,
1L,
1L,
2L,
2L,
1L,
2L,
2L,
1L,
2L,
2L,
1L,
1L,
2L,
2L,
2L,
1L,
1L,
1L,
1L,
1L,
1L,
1L,
2L,
2L,
1L,
1L,
2L,
1L,
2L,
1L,
1L,
2L,
1L,
1L,
2L,
2L,
1L,
1L
),
.Label = c("female", "male"),
class = "factor"
),
age = c(
18,
41,
40,
45,
48,
25,
50,
56,
45,
46,
45,
28,
40,
50,
25,
50,
40,
40,
40,
40,
50,
50,
29,
26,
8,
55,
60,
40,
35,
40,
22,
45,
10,
45,
14,
21,
45,
53,
55,
18,
45,
18,
35,
53,
45,
45,
54,
48,
30,
44
)
),
row.names = c(NA,-50L),
class = c("tbl_df",
"tbl", "data.frame")
)

File does not get converted to base64 string properly

So I have written some code to capture an image from the user using the better_camera package and then store it in a file. Then I convert it to base64 string for further use. It seems like the image is getting saved properly since Image.file shows the image. But when I convert the image to base64string, it gives the image of a small white screen. I do not know where the problem is coming. Can someone check?
CODE
import 'dart:convert';
import 'dart:io';
import 'dart:math';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter_better_camera/camera.dart';
import 'package:frappe/flutter_flow/flutter_flow_theme.dart';
import 'package:path_provider/path_provider.dart';
class AddNewCameraItem extends StatefulWidget {
const AddNewCameraItem({Key key}) : super(key: key);
#override
_AddNewCameraItemState createState() => _AddNewCameraItemState();
}
class _AddNewCameraItemState extends State<AddNewCameraItem> {
CameraController controller;
#override
void initState() {
super.initState();
initCam();
}
void initCam() async {
List<CameraDescription> cameras = await availableCameras();
controller = CameraController(cameras[0], ResolutionPreset.max);
controller.initialize().then((_) {
controller.setFlashMode(FlashMode.off);
if (!mounted) {
return;
}
setState(() {});
});
}
#override
void dispose() {
controller?.dispose();
super.dispose();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: FlutterFlowTheme.secondaryColor,
automaticallyImplyLeading: true,
centerTitle: true,
title: Text(
'ADD NEW ITEMS',
style: FlutterFlowTheme.bodyText1.override(
fontFamily: 'Noto Serif',
color: Color(0xFFFAFAFA),
fontSize: 20,
fontWeight: FontWeight.w600,
),
),
elevation: 4,
),
body: !controller.value.isInitialized
? Container()
// : Image.file(File(
// '/data/user/0/com.flutterflow.frappe/cache/lkpbpyigaqpjsh6iygy8dA4dsFDG9CAcVD7DueDLtd3C3JqzmmRuZcKaFFmAt88Ryyp208CzlE1oYfkJKnvwErBFv3DkO0dSYLZApETWDnsGOur728R7WgoUQ1EEOv9ilz1jAeNLotSsYFaI13Jk9wp5mmGdqhmRx6LYSCfHQHAdalrMCtniqrU3Sqhaw1iJZfeuUsJy.jpg')),
: MaterialApp(
home: CameraPreview(controller),
),
floatingActionButton: FloatingActionButton(
onPressed: () async {
try {
Directory tempDir = await getTemporaryDirectory();
String randomName =
tempDir.path + '/' + getRandomString(200) + '.jpg';
// await controller.takePicture(randomName);
File file = File(
'/data/user/0/com.flutterflow.frappe/cache/IfXsEjNsSifPiQJ0d628j2d1HRh2Ww2Flin3urZc4d59WYeZ9DQ8mjpLdrt2jwzBjn2vxqvnkzRd4AGowI6fKCGRNWOfei7B2KufbpOG0RsNH7mobwGa7KS7q1C6ALoNIVJ13XLqpa7BX7pIQSgLobe5lW6z7P01QBms3CVrM9omeEvIZxRwxL5s555HLOGN4Te9Bta2.jpg');
Uint8List list = await file.readAsBytes();
print(list);
print(base64Encode(list.toList()));
print("Random n: " + randomName);
// print(base64Encode((await xfile.readAsBytes()).toList()));
} catch (e) {
print("Error: " + e.toString());
}
},
child: Center(
child: Icon(Icons.camera_alt, color: FlutterFlowTheme.tertiaryColor),
),
),
);
}
String getRandomString(int length) {
String _chars =
'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890';
Random _rnd = Random();
return String.fromCharCodes(Iterable.generate(
length, (_) => _chars.codeUnitAt(_rnd.nextInt(_chars.length))));
}
}
BASE64OUTPUT
/9j/4QurRXhpZgAATU0AKgAAAAgACwEPAAIAAAAHAAAAkgEQAAIAAAARAAAAmgESAAMAAAABAAYAAAEaAAUAAAABAAAArAEbAAUAAAABAAAAtAEoAAMAAAABAAIAAAExAAIAAAA9AAAAvAEyAAIAAAAUAAAA+gITAAMAAAABAAEAAIdpAAQAAAABAAABDoglAAQAAAABAAAC8gAAAvhYaWFvbWkAAFJlZG1pIE5vdGUgNSBQcm8AAAAAAEgAAAABAAAASAAAAAF3aHlyZWQtdXNlciA5IFBLUTEuMTgwOTA0LjAwMSBWMTEuMC41LjAuUEVJTUlYTSByZWxlYXNlLWtleXMAADIwMjE6MDg6MTggMTk6MTY6MTkAAByCmgAFAAAAAQAAAmSCnQAFAAAAAQAAAmyIIgADAAAAAQAAAACIJwADAAAAAQJDAACQAAAHAAAABDAyMjCQAwACAAAAFAAAAnSQBAACAAAAFAAAAoiRAQAHAAAABAECAwCSAQAKAAAAAQAAApySAgAFAAAAAQAAAqSSAwAKAAAAAQAAAqySBwADAAAAAQABAACSCQADAAAAAQAQAACSCgAFAAAAAQAAArSSkAACAAAABwAAArySkQACAAAABwAAAsSSkgACAAAABwAAAsygAAAHAAAABDAxMDCgAQADAAAAAQABAACgAgAEAAAAAQAABpCgAwAEAAAAAQAABOigBQAEAAAAAQAAAtOiFwADAAAAAQACAACjAQAHAAAAAQEAAACkAgADAAAAAQAAAACkAwADAAAAAQAAAACkBQADAAAAAQAEAACkBgADAAAAAQAAAAAAAAAAAAAAAQAAAB4AAADcAAAAZDIwMjE6MDg6MTggMTk6MTY6MTkAMjAyMTowODoxOCAxOToxNjoxOQAAABMqAAAD6AAAAOMAAABkAAAAAAAAAGQAAA7iAAAD6Dk1NTM0OQBzOTU1MzQ5AAA5NTUzNDkAAAIAAQACAAAABFI5OAAAAgAHAAAABDAxMDAAAAAAAAA
UINT8LIST
[255, 216, 255, 225, 11, 171, 69, 120, 105, 102, 0, 0, 77, 77, 0, 42, 0, 0, 0, 8, 0, 11, 1, 15, 0, 2, 0, 0, 0, 7, 0, 0, 0, 146, 1, 16, 0, 2, 0, 0, 0, 17, 0, 0, 0, 154, 1, 18, 0, 3, 0, 0, 0, 1, 0, 6, 0, 0, 1, 26, 0, 5, 0, 0, 0, 1, 0, 0, 0, 172, 1, 27, 0, 5, 0, 0, 0, 1, 0, 0, 0, 180, 1, 40, 0, 3, 0, 0, 0, 1, 0, 2, 0, 0, 1, 49, 0, 2, 0, 0, 0, 61, 0, 0, 0, 188, 1, 50, 0, 2, 0, 0, 0, 20, 0, 0, 0, 250, 2, 19, 0, 3, 0, 0, 0, 1, 0, 1, 0, 0, 135, 105, 0, 4, 0, 0, 0, 1, 0, 0, 1, 14, 136, 37, 0, 4, 0, 0, 0, 1, 0, 0, 2, 242, 0, 0, 2, 248, 88, 105, 97, 111, 109, 105, 0, 0, 82, 101, 100, 109, 105, 32, 78, 111, 116, 101, 32, 53, 32, 80, 114, 111, 0, 0, 0, 0, 0, 72, 0, 0, 0, 1, 0, 0, 0, 72, 0, 0, 0, 1, 119, 104, 121, 114, 101, 100, 45, 117, 115, 101, 114, 32, 57, 32, 80, 75, 81, 49, 46, 49, 56, 48, 57, 48, 52, 46, 48, 48, 49, 32, 86, 49, 49, 46, 48, 46, 53, 46, 48, 46, 80, 69, 73, 77, 73, 88, 77, 32, 114, 101, 108, 101, 97, 115, 101, 45, 107, 101, 121, 115, 0, 0, 50, 48, 50, 49, 58, 48, 56, 58, 49, 56, 32, 49, 57, 58, 49, 5
You have to decode before using the Base64 string
String encoded = stringToBase64.encode(credentials);
String decoded = stringToBase64.decode(encoded);

Adobe XD to flutter code results in "RenderCustomMultiChildLayoutBox object was given an infinite size during layout." error

I have started to use Adobe XD to design a UI for my flutter application. When I export my UI to flutter code and try to add it with my existing code I get the error
"RenderCustomMultiChildLayoutBox object was given an infinite size during layout."
I am calling the XDOutlet() function in an already working layout, but when the code runes that error is present.
I have not changed anything from the exported code, and I can't seem to pinpoint the issue. Any help will be appreciated!
XDOutlet.dart
class XDOutlet extends StatelessWidget {
XDOutlet({
Key key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xffffffff),
body: Stack(
children: <Widget>[
Transform.translate(
offset: Offset(114.0, 315.2),
child:
// Adobe XD layer: 'Bottom_Outlet' (component)
SizedBox(
width: 200.0,
height: 200.0,
child: XDBottom_Outlet(),
),
),
Transform.translate(
offset: Offset(114.0, 52.0),
child:
// Adobe XD layer: 'Top_Outlet' (component)
SizedBox(
width: 200.0,
height: 200.0,
child: XDTop_Outlet(),
),
),
Transform.translate(
offset: Offset(220.0, 809.0),
child:
// Adobe XD layer: 'Restart' (component)
SizedBox(
width: 188.0,
height: 60.0,
child: XDRestart(),
),
),
Transform.translate(
offset: Offset(20.0, 809.0),
child:
// Adobe XD layer: 'Update' (component)
SizedBox(
width: 188.0,
height: 60.0,
child: XDUpdate(),
),
),
Transform.translate(
offset: Offset(20.0, 727.0),
child:
// Adobe XD layer: 'Statistics' (component)
PageLink(
links: [
PageLinkInfo(
transition: LinkTransition.SlideUp,
ease: Curves.easeOut,
duration: 0.3,
pageBuilder: () => XDOurlet_Statistics(),
),
],
child: SizedBox(
width: 388.0,
height: 60.0,
child: XDStatistics(),
),
),
),
Transform.translate(
offset: Offset(162.7, 578.4),
child:
// Adobe XD layer: 'All_Power' (component)
SizedBox(
width: 103.0,
height: 103.0,
child: XDAll_Power(),
),
),
],
),
);
}
}
XDBottom_Outlet.dart
class XDBottom_Outlet extends StatelessWidget {
final VoidCallback BottomOutlet;
XDBottom_Outlet({
Key key,
this.BottomOutlet,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => BottomOutlet?.call(),
child: Stack(
children: <Widget>[
Pinned.fromSize(
bounds: Rect.fromLTWH(0.0, 0.0, 200.0, 200.0),
size: Size(200.0, 200.0),
pinLeft: true,
pinRight: true,
pinTop: true,
pinBottom: true,
child:
// Adobe XD layer: 'Bottom_Outlet' (shape)
SvgPicture.string(
_svg_p3l2i1,
allowDrawingOutsideViewBox: true,
fit: BoxFit.fill,
),
),
],
),
);
}
}
const String _svg_p3l2i1 =
'<svg viewBox="0.0 0.0 200.0 200.0" ><defs><filter id="shadow"><feDropShadow dx="0" dy="3" stdDeviation="6"/></filter></defs><path transform="translate(-2.25, -2.25)" d="M 152.8860168457031 2.25 L 51.52471542358398 2.25 C 24.34328460693359 2.25 2.25 24.83424758911133 2.25 52.50664138793945 L 2.25 151.94873046875 C 2.25 179.6211242675781 24.34328460693359 202.2053680419922 51.52471542358398 202.2053680419922 L 152.9306488037109 202.2053680419922 C 180.1120910644531 202.2053680419922 202.25 179.6211242675781 202.25 151.94873046875 L 202.25 52.50664138793945 C 202.2053680419922 24.83424758911133 180.1120910644531 2.25 152.8860168457031 2.25 Z M 66.07504272460938 99.99604797363281 L 66.07504272460938 100.308479309082 C 66.07504272460938 105.173469543457 62.01344680786133 109.4135971069336 57.19309616088867 109.4135971069336 L 46.79363250732422 109.4135971069336 C 41.97328186035156 109.4135971069336 37.91168975830078 105.173469543457 37.91168975830078 100.308479309082 L 37.91168975830078 99.99604797363281 L 37.91168975830078 54.69365310668945 L 37.91168975830078 54.06879043579102 C 38.35801696777344 49.24844360351563 42.01791763305664 45.05294418334961 46.79363250732422 45.05294418334961 L 57.19309616088867 45.05294418334961 C 62.05807876586914 45.05294418334961 66.07504272460938 49.42696762084961 66.07504272460938 54.33658218383789 L 66.07504272460938 99.99604797363281 Z M 120.5271835327148 165.7849273681641 C 120.5271835327148 170.8730926513672 116.5548477172852 173.6403198242188 111.5559692382813 173.6403198242188 L 92.89942169189453 173.6403198242188 C 87.90053558349609 173.6403198242188 83.92820739746094 170.0250549316406 83.92820739746094 164.8922729492188 L 83.92820739746094 151.8148345947266 C 83.92820739746094 141.4153747558594 92.00676727294922 132.9351196289063 102.2276916503906 132.9351196289063 C 112.4486312866211 132.9351196289063 120.5271835327148 141.4153747558594 120.5271835327148 151.8148345947266 L 120.5271835327148 165.7849273681641 Z M 166.4990539550781 99.99604797363281 L 166.4990539550781 100.308479309082 C 166.4990539550781 105.173469543457 162.4374694824219 109.4135971069336 157.6171112060547 109.4135971069336 L 146.7713165283203 109.4135971069336 C 141.9509582519531 109.4135971069336 137.8893585205078 105.173469543457 137.8893585205078 100.308479309082 L 137.8893585205078 99.99604797363281 L 137.8893585205078 54.69365310668945 L 137.8893585205078 54.06879043579102 C 138.335693359375 49.24844360351563 141.9955902099609 45.05294418334961 146.7713165283203 45.05294418334961 L 157.6171112060547 45.05294418334961 C 162.4374542236328 45.05294418334961 166.4990539550781 49.42696762084961 166.4990539550781 54.33658218383789 L 166.4990539550781 99.99604797363281 Z" fill="#d90b0b" stroke="none" stroke-width="1" stroke-miterlimit="4" stroke-linecap="butt" filter="url(#shadow)"/></svg>';
XDTop_Outlet.dart
class XDTop_Outlet extends StatelessWidget {
final VoidCallback TopOutlet;
XDTop_Outlet({
Key key,
this.TopOutlet,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => TopOutlet?.call(),
child: Stack(
children: <Widget>[
Pinned.fromSize(
bounds: Rect.fromLTWH(0.0, 0.0, 200.0, 200.0),
size: Size(200.0, 200.0),
pinLeft: true,
pinRight: true,
pinTop: true,
pinBottom: true,
child:
// Adobe XD layer: 'Top_Outlet' (shape)
SvgPicture.string(
_svg_p3l2i1,
allowDrawingOutsideViewBox: true,
fit: BoxFit.fill,
),
),
],
),
);
}
}
const String _svg_p3l2i1 =
'<svg viewBox="0.0 0.0 200.0 200.0" ><defs><filter id="shadow"><feDropShadow dx="0" dy="3" stdDeviation="6"/></filter></defs><path transform="translate(-2.25, -2.25)" d="M 152.8860168457031 2.25 L 51.52471542358398 2.25 C 24.34328460693359 2.25 2.25 24.83424758911133 2.25 52.50664138793945 L 2.25 151.94873046875 C 2.25 179.6211242675781 24.34328460693359 202.2053680419922 51.52471542358398 202.2053680419922 L 152.9306488037109 202.2053680419922 C 180.1120910644531 202.2053680419922 202.25 179.6211242675781 202.25 151.94873046875 L 202.25 52.50664138793945 C 202.2053680419922 24.83424758911133 180.1120910644531 2.25 152.8860168457031 2.25 Z M 66.07504272460938 99.99604797363281 L 66.07504272460938 100.308479309082 C 66.07504272460938 105.173469543457 62.01344680786133 109.4135971069336 57.19309616088867 109.4135971069336 L 46.79363250732422 109.4135971069336 C 41.97328186035156 109.4135971069336 37.91168975830078 105.173469543457 37.91168975830078 100.308479309082 L 37.91168975830078 99.99604797363281 L 37.91168975830078 54.69365310668945 L 37.91168975830078 54.06879043579102 C 38.35801696777344 49.24844360351563 42.01791763305664 45.05294418334961 46.79363250732422 45.05294418334961 L 57.19309616088867 45.05294418334961 C 62.05807876586914 45.05294418334961 66.07504272460938 49.42696762084961 66.07504272460938 54.33658218383789 L 66.07504272460938 99.99604797363281 Z M 120.5271835327148 165.7849273681641 C 120.5271835327148 170.8730926513672 116.5548477172852 173.6403198242188 111.5559692382813 173.6403198242188 L 92.89942169189453 173.6403198242188 C 87.90053558349609 173.6403198242188 83.92820739746094 170.0250549316406 83.92820739746094 164.8922729492188 L 83.92820739746094 151.8148345947266 C 83.92820739746094 141.4153747558594 92.00676727294922 132.9351196289063 102.2276916503906 132.9351196289063 C 112.4486312866211 132.9351196289063 120.5271835327148 141.4153747558594 120.5271835327148 151.8148345947266 L 120.5271835327148 165.7849273681641 Z M 166.4990539550781 99.99604797363281 L 166.4990539550781 100.308479309082 C 166.4990539550781 105.173469543457 162.4374694824219 109.4135971069336 157.6171112060547 109.4135971069336 L 146.7713165283203 109.4135971069336 C 141.9509582519531 109.4135971069336 137.8893585205078 105.173469543457 137.8893585205078 100.308479309082 L 137.8893585205078 99.99604797363281 L 137.8893585205078 54.69365310668945 L 137.8893585205078 54.06879043579102 C 138.335693359375 49.24844360351563 141.9955902099609 45.05294418334961 146.7713165283203 45.05294418334961 L 157.6171112060547 45.05294418334961 C 162.4374542236328 45.05294418334961 166.4990539550781 49.42696762084961 166.4990539550781 54.33658218383789 L 166.4990539550781 99.99604797363281 Z" fill="#d90b0b" stroke="none" stroke-width="1" stroke-miterlimit="4" stroke-linecap="butt" filter="url(#shadow)"/></svg>';
XDRestart.dart
class XDRestart extends StatelessWidget {
final VoidCallback Restart;
XDRestart({
Key key,
this.Restart,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => Restart?.call(),
child: Stack(
children: <Widget>[
Pinned.fromSize(
bounds: Rect.fromLTWH(0.0, 0.0, 188.0, 60.0),
size: Size(188.0, 60.0),
pinLeft: true,
pinRight: true,
pinTop: true,
pinBottom: true,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
color: const Color(0xfffa0000),
boxShadow: [
BoxShadow(
color: const Color(0x29000000),
offset: Offset(0, 3),
blurRadius: 6,
),
],
),
),
),
Pinned.fromSize(
bounds: Rect.fromLTWH(27.0, 7.0, 134.0, 47.0),
size: Size(188.0, 60.0),
pinLeft: true,
pinRight: true,
pinTop: true,
pinBottom: true,
child:
// Adobe XD layer: 'Restart' (text)
Text(
'Restart',
style: TextStyle(
fontFamily: 'Raleway',
fontSize: 40,
color: const Color(0xffffffff),
fontWeight: FontWeight.w500,
),
textAlign: TextAlign.left,
),
),
],
),
);
}
}
XDUpdate.dart
class XDUpdate extends StatelessWidget {
final VoidCallback Update;
XDUpdate({
Key key,
this.Update,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => Update?.call(),
child: Stack(
children: <Widget>[
Pinned.fromSize(
bounds: Rect.fromLTWH(0.0, 0.0, 188.0, 60.0),
size: Size(188.0, 60.0),
pinLeft: true,
pinRight: true,
pinTop: true,
pinBottom: true,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
color: const Color(0xff3790f7),
boxShadow: [
BoxShadow(
color: const Color(0x29000000),
offset: Offset(0, 3),
blurRadius: 6,
),
],
),
),
),
Pinned.fromSize(
bounds: Rect.fromLTWH(24.0, 7.0, 139.0, 47.0),
size: Size(188.0, 60.0),
pinLeft: true,
pinRight: true,
pinTop: true,
pinBottom: true,
child: Text(
'Update',
style: TextStyle(
fontFamily: 'Raleway',
fontSize: 40,
color: const Color(0xffffffff),
fontWeight: FontWeight.w500,
),
textAlign: TextAlign.left,
),
),
],
),
);
}
}
XDStatistics.dart
class XDStatistics extends StatelessWidget {
final VoidCallback StatisticsPage;
XDStatistics({
Key key,
this.StatisticsPage,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => StatisticsPage?.call(),
child: Stack(
children: <Widget>[
Pinned.fromSize(
bounds: Rect.fromLTWH(0.0, 0.0, 388.0, 60.0),
size: Size(388.0, 60.0),
pinLeft: true,
pinRight: true,
pinTop: true,
pinBottom: true,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
color: const Color(0xff2cd625),
boxShadow: [
BoxShadow(
color: const Color(0x29000000),
offset: Offset(0, 3),
blurRadius: 6,
),
],
),
),
),
Pinned.fromSize(
bounds: Rect.fromLTWH(111.0, 7.0, 168.0, 47.0),
size: Size(388.0, 60.0),
pinTop: true,
pinBottom: true,
fixedWidth: true,
child:
// Adobe XD layer: 'Statistics' (text)
Text(
'Statistics',
style: TextStyle(
fontFamily: 'Raleway',
fontSize: 40,
color: const Color(0xffffffff),
fontWeight: FontWeight.w500,
),
textAlign: TextAlign.left,
),
),
],
),
);
}
}
XDAll_Power.dart
class XDAll_Power extends StatelessWidget {
final VoidCallback AllPower;
XDAll_Power({
Key key,
this.AllPower,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => AllPower?.call(),
child: Stack(
children: <Widget>[
Pinned.fromSize(
bounds: Rect.fromLTWH(0.0, 0.0, 102.6, 102.6),
size: Size(102.6, 102.6),
pinLeft: true,
pinRight: true,
pinTop: true,
pinBottom: true,
child:
// Adobe XD layer: 'Icon ionic-md-power' (shape)
SvgPicture.string(
_svg_md9vfg,
allowDrawingOutsideViewBox: true,
fit: BoxFit.fill,
),
),
],
),
);
}
}
const String _svg_md9vfg =
'<svg viewBox="0.0 0.0 102.6 102.6" ><defs><filter id="shadow"><feDropShadow dx="0" dy="3" stdDeviation="6"/></filter></defs><path transform="translate(-3.37, -3.37)" d="M 60.35555648803711 3.375000238418579 L 48.96437835693359 3.375000238418579 L 48.96437835693359 60.35555648803711 L 60.35555648803711 60.35555648803711 L 60.35555648803711 3.375000238418579 Z M 87.87191772460938 15.75243091583252 L 79.78467559814453 23.83967781066895 C 88.78420257568359 31.0886116027832 94.55375671386719 42.18391799926758 94.55375671386719 54.65997314453125 C 94.55375671386719 76.70264434814453 76.72730255126953 94.55374908447266 54.65998077392578 94.55374908447266 C 32.59264755249023 94.55374908447266 14.76618099212646 76.70264434814453 14.76618099212646 54.65997314453125 C 14.76618099212646 42.18391799926758 20.51108551025391 31.0639533996582 29.4612979888916 23.76571083068848 L 21.42336273193359 15.72777462005615 C 10.37737083435059 25.14645385742188 3.375000238418579 39.05257797241211 3.375000238418579 54.65997314453125 C 3.375000238418579 82.98998260498047 26.32995796203613 105.9449310302734 54.65997314453125 105.9449310302734 C 82.98998260498047 105.9449310302734 105.9449310302734 82.98998260498047 105.9449310302734 54.65997314453125 C 105.9449310302734 39.05257797241211 98.94255828857422 25.14645385742188 87.87191772460938 15.75243091583252 Z" fill="#d90b0b" stroke="none" stroke-width="1" stroke-miterlimit="4" stroke-linecap="butt" filter="url(#shadow)"/></svg>';
Unfortunately XD to flutter is not 100% works and not recommended, here's why :
There is not just create and convert from xd to flutter
You need to chain the widget your self
Use XD to flutter for UI purpose only, because XD cannot contain logical behavior of your program
I would highly recommend you to code it your self, flutter covering almost 100% possibilities of a custom widget, and it's easy enough to understand rather than create UI and convert it to a fully functional program which almost impossible to work flawlessly

Wrong Flutter error Convert image ImagePicker type File to base64, Wrong Encoded

I need to convert an image that I get from the device with ImagePicker, convert it from File type to base64 to store it through a post in a db, but the procedure I do to convert it does not do it well, it converts only a thin line and the rest blank, apparently readAsbyte does not convert well when implemented as "var bytes = imageFile.readAsBytesSync ();" makes it incomplete
this is how i am implementing it
File imageFile;
void _openGallery(BuildContext context) async{
var picture = await ImagePicker().getImage(source: ImageSource.gallery);
this.setState(() {
imageFile = File(picture.path);
var bytes = imageFile.readAsBytesSync();
String imagenConvertida = base64.encode(bytes);
print(bytes);
print(imagenConvertida);
});
Navigator.of(context).pop();
}
From your implementation,
File imageFile;
void _openGallery(BuildContext context) async{
var picture = await ImagePicker().getImage(source: ImageSource.gallery);
this.setState(() {
imageFile = File(picture.path);
var bytes = imageFile.readAsBytesSync();
String imagenConvertida = base64.encode(bytes);
print(bytes);
print(imagenConvertida);
});
Navigator.of(context).pop();
The output of bytes is
[255, 216, 255, 225, 1, 181, 69, 120, 105, 102, 0, 0, 77, 77, 0, 42,
0, 0, 0, 8, 0, 7, 1, 16, 0, 2, 0, 0, 0, 26, 0, 0, 0, 98, 1, 0, 0, 4,
0, 0, 0, 1, 0, 0, 3, 192, 1, 1, 0, 4, 0, 0, 0, 1, 0, 0, 5, 0, 1, 50,
0, 2, 0, 0, 0, 20, 0, 0, 0, 124, 1, 18, 0, 3, 0, 0, 0, 1, 0, 1, 0, 0,
135, 105, 0, 4, 0, 0, 0, 1, 0, 0, 0, 151, 1, 15, 0, 2, 0, 0, 0, 7, 0,
0, 0, 144, 0, 0, 0, 0, 65, 110, 100, 114, 111, 105, 100, 32, 83, 68,
75, 32, 98, 117, 105, 108, 116, 32, 102, 111, 114, 32, 120, 56, 54, 0,
50, 48, 50, 48, 58, 48, 57, 58, 48, 50, 32, 48, 52, 58, 49, 53, 58,
51, 54, 0, 71, 111, 111, 103, 108, 101, 0, 0, 16, 130, 157, 0, 5, 0,
0, 0, 1, 0, 0, 1, 93, 130, 154, 0, 5, 0, 0, 0, 1, 0, 0, 1, 101, 146,
146, 0, 2, 0, 0, 0, 4, 56, 56, 57, 0, 146, 145, 0, 2, 0, 0, 0, 4, 56,
56, 57, 0, 146, 144, 0, 2, 0, 0, 0, 4, 56, 56, 57, 0, 146, 10, 0, 5,
0, 0, 0, 1, 0, 0, 1, 109, 146, 9, 0, 3, 0, 0, 0, 1, 0, 0, 0, 0, 136,
39, 0, 3, 0, 0, 0, 1, 0, 100, 0, 0, 144, 4, 0, 2, 0, 0, 0, 20, 0, 0,
1, 117, 144, 3, 0, 2, 0, 0, 0, 20, 0,
The output of imagenConvertida is
/9j/4QG1RXhpZgAATU0AKgAAAAgABwEQAAIAAAAaAAAAYgEAAAQAAAABAAADwAEBAAQAAAABAAAFAAEyAAIAAAAUAAAAfAESAAMAAAABAAEAAIdpAAQAAAABAAAAlwEPAAIAAAAHAAAAkAAAAABBbmRyb2lkIFNESyBidWlsdCBmb3IgeDg2ADIwMjA6MDk6MDIgMDQ6MTU6MzYAR29vZ2xlAAAQgp0ABQAAAAEAAAFdgpoABQAAAAEAAAFlkpIAAgAAAAQ4ODkAkpEAAgAAAAQ4ODkAkpAAAgAAAAQ4ODkAkgoABQAAAAEAAAFtkgkAAwAAAAEAAAAAiCcAAwAAAAEAZAAAkAQAAgAAABQAAAF1kAMAAgAAABQAAAGJoAMABAAAAAEAAAUApAMAAwAAAAEAAAAAoAIABAAAAAEAAAPAkgIABQAAAAEAAAGdkgEACgAAAAEAAAGlkAAABwAAAAQwMjIwAAAAAAAAARgAAABkAJiWgDuaygAAABOIAAAD6DIwMjA6MDk6MDIgMDQ6MTU6MzYAMjAyMDowOTowMiAwNDoxNTozNgAAAAEpAAAAZAAAGfMAAAPo/+AAEEpGSUYAAQEAAAEAAQAA/9sAQwACAQEBAQECAQEBAgICAgIEAwICAgIFBAQDBAYFBgYGBQYGBgcJCAYHCQcGBggLCAkKCgoKCgYICwwLCgwJCgoK/9sAQwECAgICAgIFAwMFCgcGBwoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoK/8AAEQgFAAPAAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVm
Reversing it, I come up with the following code:
File imageFile;
Image decodedImage;
void _openGallery(BuildContext context) async {
var picture = await ImagePicker().getImage(source: ImageSource.gallery);
this.setState(
() {
imageFile = File(picture.path);
// Convert image to base64
var bytes = imageFile.readAsBytesSync();
String imagenConvertida = base64.encode(bytes);
print('Value of bytes: $bytes');
print('Value of imagenConvertida: $imagenConvertida');
// Convert base64 to image
Uint8List decodedBytes = base64.decode(imagenConvertida);
decodedImage = Image.memory(decodedBytes);
print('Value of decodedBytes: $decodedBytes');
print('Value of decodedImage: $decodedImage');
},
);
// Commented out for testing purposes
// Navigator.of(context).pop();
}
When you compare the output the value of decodedBytes
[255, 216, 255, 225, 1, 181, 69, 120, 105, 102, 0, 0, 77, 77, 0, 42,
0, 0, 0, 8, 0, 7, 1, 16, 0, 2, 0, 0, 0, 26, 0, 0, 0, 98, 1, 0, 0, 4,
0, 0, 0, 1, 0, 0, 3, 192, 1, 1, 0, 4, 0, 0, 0, 1, 0, 0, 5, 0, 1, 50,
0, 2, 0, 0, 0, 20, 0, 0, 0, 124, 1, 18, 0, 3, 0, 0, 0, 1, 0, 1, 0, 0,
135, 105, 0, 4, 0, 0, 0, 1, 0, 0, 0, 151, 1, 15, 0, 2, 0, 0, 0, 7, 0,
0, 0, 144, 0, 0, 0, 0, 65, 110, 100, 114, 111, 105, 100, 32, 83, 68,
75, 32, 98, 117, 105, 108, 116, 32, 102, 111, 114, 32, 120, 56, 54, 0,
50, 48, 50, 48, 58, 48, 57, 58, 48, 50, 32, 48, 52, 58, 49, 53, 58,
51, 54, 0, 71, 111, 111, 103, 108, 101, 0, 0, 16, 130, 157, 0, 5, 0,
0, 0, 1, 0, 0, 1, 93, 130, 154, 0, 5, 0, 0, 0, 1, 0, 0, 1, 101, 146,
146, 0, 2, 0, 0, 0, 4, 56, 56, 57, 0, 146, 145, 0, 2, 0, 0, 0, 4, 56,
56, 57, 0, 146, 144, 0, 2, 0, 0, 0, 4, 56, 56, 57, 0, 146, 10, 0, 5,
0, 0, 0, 1, 0, 0, 1, 109, 146, 9, 0, 3, 0, 0, 0, 1, 0, 0, 0, 0, 136,
39, 0, 3, 0, 0, 0, 1, 0, 100, 0, 0, 144, 4, 0, 2, 0, 0, 0, 20, 0, 0,
1, 117, 144, 3, 0, 2, 0, 0, 0,
And when you convert it, it will give you the exact original image, see the sample app code below:
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:image_picker/image_picker.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> {
// From SO
File imageFile;
Image decodedImage;
void _openGallery(BuildContext context) async {
var picture = await ImagePicker().getImage(source: ImageSource.gallery);
this.setState(
() {
imageFile = File(picture.path);
// Convert image to base64
var bytes = imageFile.readAsBytesSync();
String imagenConvertida = base64.encode(bytes);
print('Value of bytes: $bytes');
print('Value of imagenConvertida: $imagenConvertida');
// Convert base64 to image
Uint8List decodedBytes = base64.decode(imagenConvertida);
decodedImage = Image.memory(decodedBytes);
print('Value of decodedBytes: $decodedBytes');
print('Value of decodedImage: $decodedImage');
},
);
// Commented out for testing purposes
// Navigator.of(context).pop();
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(
height: 20.0,
),
Text('Original image from gallery'),
SizedBox(height: 10.0),
Container(
color: Colors.blueGrey,
height: 200.0,
width: 150.0,
child: imageFile == null
? Text('Image is not loaded')
: Image.file(imageFile),
),
SizedBox(height: 20.0),
Text('Image decoded from base64'),
SizedBox(height: 10.0),
Container(
color: Colors.grey,
height: 200.0,
width: 150.0,
child: decodedImage == null
? Text('Image is not loaded')
: decodedImage,
),
],
),
),
floatingActionButton: Row(
mainAxisAlignment: MainAxisAlignment.end,
// crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
FloatingActionButton(
onPressed: () {
// _getImage();
_openGallery(context);
print('Open Gallery');
},
tooltip: 'Pick an image',
child: Icon(Icons.image),
),
SizedBox(
width: 20,
),
],
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
Since the decoded image is the same as the original image, I think var bytes = imageFile.readAsBytesSync(); is working fine.

Flutter - How to make the custom rounded shape of card in flutter?

I want to make a card with a rounded shape like the image below
I tried a lot for it but I can't make it a shape like a design.
I have made a sample with ShapeBorder that you can copy(paste to dartPad and play with.
Replace the Icon with an Image.
PS. I added a LayoutBuilder to make it more robust to responsive layouts.
This is the result, hope it can help you:
import "package:flutter/material.dart";
import "dart:math";
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false, home: Scaffold(body: HomeScreen())));
}
class HomeScreen extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Container(
width: 300,
height: 800,
child: Column(children: <Widget>[
MyCustomCard(),
MyCustomCard(),
]));
}
}
class MyCustomCard extends StatelessWidget {
#override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (_, BoxConstraints bc) {
return Container(
padding: EdgeInsets.all(10),
color: Colors.black,
child: Stack(children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(
height: 80,
),
Container(
width: double.infinity,
//height: 400,
decoration: ShapeDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Color(0xff3344ff), Color(0x883344ff)],
stops: [0, 1],
),
shape: CustomCardShape(
//kW:MediaQuery.of(context).size.width-40,
),
),
child: Padding(
padding: EdgeInsets.all(20),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(height: 20),
Text(
"Steve Jobs",
style: TextStyle(
color: Colors.white,
fontSize: 14,
fontWeight: FontWeight.bold,
),
),
Text(
"Seattle",
style:
TextStyle(color: Colors.white, fontSize: 18),
),
SizedBox(height: 20),
Text(
"hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello ",
style:
TextStyle(color: Colors.white, fontSize: 14),
),
]),
)),
]),
Positioned(
top: 20,
//left: (MediaQuery.of(context).size.width/2)-60, //100,
left: bc.constrainWidth() / 2 - 50,
child: Container(
alignment: Alignment.center,
width: 80,
decoration: BoxDecoration(
color: Colors.black,
shape: BoxShape.circle,
),
child: Icon(Icons.home, color: Colors.white, size: 80),
),
),
]), // stack
);
});
}
}
class CustomCardShape extends ShapeBorder {
//final double kH = 350; // card height
//final double kW; // = 260; // card width
final double circleW = 100;
CustomCardShape(); //{this.kW});
#override
EdgeInsetsGeometry get dimensions => EdgeInsets.all(0);
#override
Path getInnerPath(Rect rect, {TextDirection textDirection}) => null;
#override
Path getOuterPath(Rect rect, {TextDirection textDirection}) {
rect = Rect.fromPoints(rect.topLeft, rect.bottomRight);
double kW = rect.width - 20;
double kH = rect.height;
double www = (kW - circleW - 20) / 2;
double wwwR = www;
return Path()
..moveTo(rect.topLeft.dx, rect.topLeft.dy + 20)
..lineTo(rect.topLeft.dx, rect.topLeft.dy + kH)
// rect bottom left
..arcTo(Rect.fromLTWH(rect.topLeft.dx, rect.topLeft.dy + kH, 20, 20), -pi,
-pi / 2, false)
..lineTo(rect.topLeft.dx + kW, rect.topLeft.dy + kH + 20)
// rect bottom right
..arcTo(Rect.fromLTWH(rect.topLeft.dx + kW, rect.topLeft.dy + kH, 20, 20),
-3 * pi / 2, -pi / 2, false)
..lineTo(rect.topLeft.dx + kW + 20, rect.topLeft.dy + 20)
// rect top right
..arcTo(Rect.fromLTWH(rect.topLeft.dx + kW, rect.topLeft.dy, 20, 20), 0,
-pi / 2, false)
..lineTo(rect.topLeft.dx + kW - www, rect.topLeft.dy)
// circle bottom right
..arcTo(
Rect.fromLTWH(
rect.topLeft.dx + kW - wwwR, rect.topLeft.dy - 20, 20, 20),
pi / 2,
pi / 2,
false)
..lineTo(rect.topLeft.dx + kW - wwwR, rect.topLeft.dy - 20)
// circle
..arcTo(
Rect.fromLTWH(rect.topLeft.dx + kW - wwwR - circleW,
rect.topLeft.dy - 20 - 50, circleW, circleW),
0,
-pi,
false)
..lineTo(rect.topLeft.dx + kW - wwwR - circleW, rect.topLeft.dy - 20)
// circle bottom left
..arcTo(
Rect.fromLTWH(
rect.topLeft.dx + 20 + www - 20, rect.topLeft.dy - 20, 20, 20),
0,
pi / 2,
false)
..lineTo(rect.topLeft.dx, rect.topLeft.dy)
// rect top left
..arcTo(Rect.fromLTWH(rect.topLeft.dx, rect.topLeft.dy, 20, 20), -pi / 2,
-pi / 2, false)
..close();
}
#override
void paint(Canvas canvas, Rect rect, {TextDirection textDirection}) {}
#override
ShapeBorder scale(double t) => this;
}