class CustomSquare extends StatelessWidget {
final Color color;
final double width;
final double height;
final Text child;
CustomSquare({
this.color,
this.width,
this.height,
@required this.child,
});
@override
Widget build(BuildContext context) {
return Container(
width: width,
height: height,
color: color,
child: Builder(builder: (context){
return InkWell(
onTap: (){
Scaffold.of(context).showSnackBar(SnackBar(content: child));
},
);
}),
);
}
}
2.解释源代码
import ‘package:flutter/material.dart’;
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState