【 Flutter 】Flutter を 基礎 から 学習 ( ウィジェット編 ) part73 Painting and effects

基礎 から 学ぶ Flutter 」という書籍で  学習 したことを ブログでアウトプットしていこうと思います。今回は ウィジェット編 ( part73 )です。

前回

【 Flutter 】Flutter を 基礎 から 学習 ( ウィジェット編 ) part72 Painting and effects

引き続き、Painting and effectsについて学びます。

Painting and effects

ClipRRectウィジェット

ClipRRectウィジェットはClipRectウィジェットの角丸版です。
角が丸くなると温かみみたいなものを感じますよね😀

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:transparent_image/transparent_image.dart';

void main() {
  runApp(new MaterialApp(home: new MyApp()));
}

class MyApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _State();
  }
}

class _State extends State<MyApp> {
  int _index = 0;
  @override
  // pubspec.yamlのdependenciesに「transparent_image:  ^2.0.0」を追加しておきます。
  // pub getを忘れずに!
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
      appBar: AppBar(
        title: Text('テスト中です。'),
      ),
      body: ClipRRect(
          borderRadius: BorderRadius.circular(15.0), // 丸みの指定
          clipBehavior: Clip.hardEdge, // 角の形を決定
          child: FadeInImage.memoryNetwork(
            placeholder: kTransparentImage,
            image: 'https://picsum.photos/250?image=9',
            fadeInDuration: const Duration(milliseconds: 200),
            width: 100,
            height: 100,
            fit: BoxFit.cover,
          )),
    ));
  }

  Widget box(
      {double height = 50,
      double width = 50,
      Color color = Colors.green,
      String txt = "0"}) {
    return Container(
        margin: const EdgeInsets.all(2),
        height: height,
        width: width,
        color: color,
        child: Text(txt));
  }
}

最後に

やっぱり丸角が見栄えも優しくなるからよいですね。

今日はここまで!