Circular image biasa kita lihat pada avatar atau profile pada Aplikasi tertentu, nah pada kesempatan ini kita akan belajar bagaimana cara membuat circle image dengan Flutter, berikut langkahnya:
- Tambahkan Code seperti berikut pada Widget
CircleAvatar(
backgroundColor: Colors.white,
radius: 100,
backgroundImage: AssetImage('img/profile.jpg')
Secara keseluruhan code nya dapat dilihat seperti berikut:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 16),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
decoration: BoxDecoration(
border: Border.all(width: 2, color: Colors.grey),
borderRadius: BorderRadius.circular(100)),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
CircleAvatar(
backgroundColor: Colors.white,
radius: 100,
backgroundImage: AssetImage('img/profile.jpg'),
),
]),
),
),
],
),
),
),
);
}
}
Sehingga hasilnya seperti berikut:
Ok teman – teman sekian tutorial kali ini, Semangat belajar! ^.^