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

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

前回

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

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

Painting and effects

ClipRectウィジェット

ClipRectウィジェットはchildで指定したウィジェットを四角く切り取ります。

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: ClipRect(
          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));
  }
}

前回とほぼ同じ実装です。ふわーーっと表示されます。(この部分は割愛)

最後に

切り抜きって結構使う機会多いんですかね。
自分で切り抜かなくてよいのは便利ですね。

今日はここまで!