🧩

Flutter OutlineButtonの下ごしらえ(UIのclass化)

に公開

codeの短縮化にはさほど寄与しないが

デザインを揃えるのが簡単なので採用。
今回は文字色しか指定していないけど、styleとかいろいろ触りたければ一括ですむ。

迷ったのはonPressedの型指定

import 'package:flutter/material.dart';

class ButtonFormat extends StatelessWidget {
  final String label;
  final VoidCallback onPressed;

  const ButtonFormat ({
    required this.label,
    required this.onPressed,

    Key? key,
  }) :super(key: key);

  
  Widget build(BuildContext context) {
    return OutlinedButton(
        onPressed: onPressed,
        child: Text(label,
        style: const TextStyle(
          color: Colors.white),
        ),
    );
  }
}

使うときはこれだけ

                        child: ButtonFormat(
                          onPressed: fetchPlaces,
                          label: 'Show and Select Current Place',
                        ),
Flutter大学

Discussion