कैसे बनाने के लिए एक ElevatedButton एक ढाल के साथ पृष्ठभूमि में स्पंदन?

0

सवाल

मैंने पाया है कई उदाहरण पर ढेर अतिप्रवाह का उपयोग करने के लिए कैसे एक RaiseButton एक ढाल के साथ पृष्ठभूमि के बाद से, लेकिन पोस्टिंग उन लोगों के जवाब है, RaiseButton पदावनत किया गया है.

सबसे समाधान के लिए मिल गया है एक ElevatedButton एक ढाल के साथ पृष्ठभूमि गया है अधूरा कुछ डिग्री करने के लिए; या तो ढाल कवर नहीं करता है, पूरे रंग की पृष्ठभूमि या ग्रहण है ।

यह किया गया है सबसे पूरा जवाब मुझे मिल गया है, लेकिन onPress ऊंचाई प्रस्तुत करता है एक विवाद छाया.

नीचे मैं पोस्ट किया है एक जवाब के साथ अपने सर्वश्रेष्ठ करने की कोशिश की एक ElevatedButton एक ढाल के साथ पृष्ठभूमि (क्यू एंड ए शैली). कृपया टिप्पणी में तरीके से आप देखते हैं अपने जवाब में सुधार!

button dart flutter
2021-11-23 15:45:52
1

सबसे अच्छा जवाब

0

बाद बहुत परीक्षण और त्रुटि, मैं विश्राम करने में कामयाब रहे ElevatedButton.

अंत परिणाम:

Gradient Button

नीचे है मेरे कोड के लिए एक पुन: प्रयोज्य ढाल बटन.

import 'package:flutter/material.dart';

class GradientElevatedButton extends StatelessWidget {
  const GradientElevatedButton({
    Key? key,
    required this.child,
    required this.onPressed,
    required this.linearGradient,
  }) : super(key: key);

  final Widget child;
  final VoidCallback onPressed;
  final LinearGradient linearGradient;

  @override
  Widget build(BuildContext context) {
    return Padding(
      // ElevatedButton has default 5 padding on top and bottom
      padding: const EdgeInsets.symmetric(
        vertical: 5,
      ),
      // DecoratedBox contains our linear gradient
      child: DecoratedBox(
        decoration: BoxDecoration(
          gradient: linearGradient,
          // Round the DecoratedBox to match ElevatedButton
          borderRadius: BorderRadius.circular(5),
        ),
        child: ElevatedButton(
          onPressed: onPressed,
          // Duplicate the default styling of an ElevatedButton
          style: ElevatedButton.styleFrom(
            // Enables us to see the BoxDecoration behind the ElevatedButton
            primary: Colors.transparent,
            // Fits the Ink in the BoxDecoration
            tapTargetSize: MaterialTapTargetSize.shrinkWrap,
          ).merge(
            ButtonStyle(
              // Elevation declared here so we can cover onPress elevation
              // Declaring in styleFrom does not allow for MaterialStateProperty
              elevation: MaterialStateProperty.all(0),
            ),
          ),
          child: child,
        ),
      ),
    );
  }
}

2021-11-23 15:45:52

अन्य भाषाओं में

यह पृष्ठ अन्य भाषाओं में है

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................