Skip to content

Instantly share code, notes, and snippets.

@ChangJoo-Park
Created August 23, 2023 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChangJoo-Park/f88b6950c44596d8adba8d9fccb581e0 to your computer and use it in GitHub Desktop.
Save ChangJoo-Park/f88b6950c44596d8adba8d9fccb581e0 to your computer and use it in GitHub Desktop.
Custom icon with button
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
final String title;
const MyHomePage({
Key? key,
required this.title,
}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
renderOutlineButtonWithIcon(true),
const SizedBox(height: 8),
renderOutlineButtonWithIcon(false),
],
),
),
);
}
final _selectedStyle = (
iconColor: Colors.black,
borderColor: const Color(0xFF323F66),
textColor: const Color(0xFF242F53),
);
final _unselectedStyle = (
iconColor: Colors.grey,
borderColor: const Color(0xFFD7DBDF),
textColor: const Color(0xFF969FAC)
);
Widget renderOutlineButtonWithIcon(bool isSelected) {
final style = isSelected ? _selectedStyle : _unselectedStyle;
return OutlinedButton(
onPressed: () {},
style: OutlinedButton.styleFrom(
padding: EdgeInsets.zero,
shape: RoundedRectangleBorder(
side: BorderSide(width: 0.75, color: style.borderColor),
borderRadius: BorderRadius.circular(6),
),
splashFactory: NoSplash.splashFactory,
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.check, size: 16, color: style.iconColor),
const SizedBox(width: 4),
Text(
'동의',
style: TextStyle(
color: style.textColor,
fontSize: 14.22,
fontFamily: 'Pretendard',
fontWeight: FontWeight.w700,
height: 1.13,
),
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment