Search
 
SCRIPT & CODE EXAMPLE
 

DART

flutter container with custom shape

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: CustomPaint(
          painter: Chevron(),
          child: Container(
            width: 100.0,
            height: 120.0,
            child: Padding(
              padding: EdgeInsets.only(top: 30.0),
              child: Align(
                alignment: Alignment.topCenter,
                child: Text("1", style: TextStyle(fontSize: 24.0)),
              ),
            ),
          ),
        ),
      ),
    );
  }
}

class Chevron extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    final Gradient gradient = new LinearGradient(
      begin: Alignment.topCenter,
      end: Alignment.bottomCenter,
      colors: [Colors.orangeAccent, Colors.yellow],
      tileMode: TileMode.clamp,
    );

    final Rect colorBounds = Rect.fromLTRB(0, 0, size.width, size.height);
    final Paint paint = new Paint()
      ..shader = gradient.createShader(colorBounds);

    Path path = Path();
    path.moveTo(0, 0);
    path.lineTo(0, size.height);
    path.lineTo(size.width / 2, size.height - size.height / 3);
    path.lineTo(size.width, size.height);
    path.lineTo(size.width, 0);
    path.close();

    canvas.drawPath(path, paint);
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) => false;
}

Comment

PREVIOUS NEXT
Code Example
Dart :: concatenate in flutter 
Dart :: delay fetching data flutter 
Dart :: increase widh of TableCell in flutter 
Dart :: how to use api key in flutter 
Dart :: add all items to a list in dart 
Dart :: string null dart 
Dart :: Modal overlay in flutter 
Dart :: dart void 
Dart :: dart string equals 
Dart :: how to create space between list on flutter 
Dart :: dart typedef 
Dart :: collection for in dart 
Dart :: arrary where dart 
Dart :: app bar color flutter 
Dart :: nullable conditional assignment dart 
Dart :: flutter longpress vibration 
Dart :: constructor with different name flutter 
Dart :: flutter instance of 
Dart :: how to parse json with missing key in lfutter 
Dart :: customscrollview add container widget 
Swift :: swift + data to string 
Swift :: find object in array by property swift 
Swift :: declaration of empty dictionary in swift language 
Swift :: textfield style swiftui own 
Swift :: swift substring 
Swift :: Decimal to Double conversion in Swift 
Swift :: swift alamofire x-www-form-urlencoded 
Swift :: and in swif 
Swift :: struct vs enum swift 
Swift :: switch case in swift language 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =