ผมฝีกเขียนตามคลิปนี้ครับแต่ของผมขึ้นerror Image picker camera gallery Flutter, flutter video tutorial in English, part 38 - YouTube
import 'dart:html';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
void main() {
runApp(MyApp());
//runApp(imageTeam());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// is not restarted.
primarySwatch: Colors.blue,
),
//home: MainPage(),
home: MainPage(),
);
}
}
class MainPage extends StatefulWidget {
@override
_MainPageState createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
final title = "basketball";
File _image;
final background = "images/basketball_background.jpg";
final Team_A_Name = "Team Name";
final Team_B_Name = "Team Name";
TextEditingController TeamA = TextEditingController(text: "");
TextEditingController TeamB = TextEditingController(text: "");
Future getImage() async{
final image= ImagePicker.pickImage(source: ImageSource.gallery);
setState(() {
_image = image as File;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Builder(
builder: (context) => Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(background),
fit: BoxFit.cover
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
AppBar(
toolbarHeight: 70,
backgroundColor: Colors.black45,
title: Text(title,style: TextStyle(fontSize: 48,)),
centerTitle: true,
titleTextStyle: TextStyle(
fontSize: 50,
fontWeight: FontWeight.bold,
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,//ProFile
children: [
Padding(
padding: const EdgeInsets.all(10.0),
child:
CircleAvatar(
radius: 70,
backgroundColor:
Colors.grey[600].withOpacity(0.7),
child: ClipOval(
child: SizedBox(
width: 180.0,
height: 180.0,
child:_image == null ? Image.file(_image,fit:BoxFit.fill)
:Image.network('https://firebasestorage.googleapis.com/v0/b/thaidevgroup-89222.appspot.com/o/131897219_434594304234247_5658792147038434898_n.png?alt=media&token=a08a48b2-dcdc-4716-a85a-ca634c2b0c3d',
fit: BoxFit.fill,
),
),
),
),
),
Padding(
padding: EdgeInsets.only(top:70.0),
child: IconButton(
icon: Icon(
Icons.camera_alt,
size: 20.0,
color: Colors.white,
),
onPressed:(){
getImage();
},
),
),
Padding(
padding: const EdgeInsets.all(10.0),
child: CircleAvatar(
radius: 70,
backgroundColor:
Colors.grey[600].withOpacity(0.7)
),
),
],
),
]
),
SizedBox(
height: 30,
),
Column( //Team Name
children: [
Padding(
padding: const EdgeInsets.only(left:20.0),
child: TextField(
decoration: InputDecoration(
labelText: ("Team A Name"),
labelStyle: TextStyle(fontSize: 24,
color: Colors.red,
fontStyle: FontStyle.normal
),
hintText: "$Team_A_Name",
hintStyle: TextStyle(
fontFamily: '',
fontSize: 24,
color: Colors.white,
),
border: InputBorder.none,
),
maxLines: 1,
controller: TeamA,
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.white
),
textInputAction: TextInputAction.done,
),
),
Padding(
padding: const EdgeInsets.only(left:20.0),
child: TextField(
decoration: InputDecoration(
labelText: ("Team B Name"),
labelStyle: TextStyle(fontSize: 24,
color: Colors.indigo,
fontStyle: FontStyle.normal
),
hintText: "$Team_B_Name",
hintStyle: TextStyle(
fontSize: 24,
color: Colors.white,
),
border: InputBorder.none,
),
maxLines: 1,
controller: TeamB,
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.white,
),
textInputAction: TextInputAction.done,
),
),
],
),
],
),
),
),
);
}
}