如何在 Flutter 中为计算器制作这个按钮效果?

问题描述 投票:0回答:1

我想制作这个按钮设计,但现在我无法正确完成,我正在使用backgroundBlendMode,但这对我来说是不可能的。

Widget buildButton(String value) {
  return Container(
    margin: const EdgeInsets.all(5.0),
    decoration: BoxDecoration(
      borderRadius: BorderRadius.circular(20.0),
      gradient: const LinearGradient(
        colors: [
          Color(0xFF546486),
          Color(0xFF394A68),
        ],
        begin: Alignment.topLeft,
        end: Alignment.bottomRight,
      ),
    ),
    child: Container(
      margin: const EdgeInsets.all(5.0),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(20.0),        
        gradient: const LinearGradient(
          colors: [
            Color(0xFF394A68),
            Color(0xFF546486),
          ],
          begin: Alignment.topLeft,
          end: Alignment.bottomRight,
        ),
        boxShadow: const [
          BoxShadow(color: Color(0xFF394A68), blurRadius: 5.0),
        ],
      ),
      child: Center(
        child: Text(
          value,
          style: const TextStyle(
            color: Color(0XFFBCC6DF),
            fontSize: 30.0,
          ),
        ),
      ),
    ),
  );
}

这就是我到目前为止所得到的,请随意更改您想要或需要的所有内容。

目前结果

预期结果

css flutter button containers
1个回答
0
投票

您好,请提供更多您正在寻找的代码,根据我的理解,我在这里设计的是代码

    import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter App!!',
      theme: ThemeData(
        colorSchemeSeed: Colors.indigo,
        useMaterial3: true,
        brightness: Brightness.light,
      ),
      darkTheme: ThemeData(
        colorSchemeSeed: Colors.blue,
        useMaterial3: true,
        brightness: Brightness.dark,
      ),
      home: const MyHomePage(title: 'Flutter Example App'),
      debugShowCheckedModeBanner: false,
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      // This call to setState tells the Flutter framework that something has
      // changed in this State, which causes it to rerun the build method below
      // so that the display can reflect the updated values. If we changed
      // _counter without calling setState(), then the build method would not be
      // called again, and so nothing would appear to happen.
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Column(children: [
            SizedBox(height: 150, width: 150,
            child: buildButton("c"),
            )
            
          ],)
    );
  }
}

Widget buildButton(String value) {
  return Container(
    margin: const EdgeInsets.all(5.0),
    decoration: BoxDecoration(
      borderRadius: BorderRadius.circular(40.0),
      gradient: const LinearGradient(
        colors: [
          Color(0xFF546486),
          Color(0xFF394A68),
        ],
        begin: Alignment.topLeft,
        end: Alignment.bottomRight,
      ),
    ),
    child: Container(
      margin: const EdgeInsets.all(5.0),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(40.0),        
        gradient: const LinearGradient(
          colors: [
            Color(0xFF394A68),
            Color(0xFF546486),
          ],
          begin: Alignment.topLeft,
          end: Alignment.bottomRight,
        ),
        boxShadow: const [
          BoxShadow(color: Color(0xFF394A68), blurRadius: 5.0),
        ],
      ),
      child: Center(
        child: Text(
          value,
          style: const TextStyle(
            color: Color(0XFFBCC6DF),
            fontSize: 65.0,
          ),
        ),
      ),
    ),
  );
}

here is the output

希望它有效!!!!!!

© www.soinside.com 2019 - 2024. All rights reserved.