Skip to content

Instantly share code, notes, and snippets.

@doyle-flutter
Created February 15, 2021 08:42
Show Gist options
  • Save doyle-flutter/202ed5d9f30bf212bba1b96913569ff7 to your computer and use it in GitHub Desktop.
Save doyle-flutter/202ed5d9f30bf212bba1b96913569ff7 to your computer and use it in GitHub Desktop.
camera Example
import 'package:flutter/material.dart';
import 'package:andtest/Logic.dart';
import 'dart:typed_data';
class ProfilePage extends StatefulWidget {
@override
_ProfilePageState createState() => _ProfilePageState();
}
class _ProfilePageState extends State<ProfilePage> {
CameraLogic _cameraLogic;
Uint8List _imgData;
@override
void initState() {
_cameraLogic = new CameraLogic()
..channelOnData((Uint8List data){
setState(() {
this._imgData = data;
});
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("프로필 변경"),),
body: SingleChildScrollView(
child: Container(
child: Column(
children: [
GestureDetector(
onTap: () async{
if(this._imgData != null){
setState(() {
this._imgData = null;
});
return;
}
await _cameraLogic.camActionChannel();
return;
},
child: Container(
margin: this._widgetMargin,
width: MediaQuery.of(context).size.width/3,
height: MediaQuery.of(context).size.width/3,
decoration: this._imgWidget(),
),
),
Container(
padding: this._widgetPadding,
decoration: BoxDecoration(
border: Border.symmetric(horizontal: BorderSide(color: Colors.grey))
),
margin: this._widgetMargin,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("이름", style: this._titleTextStyle,),
Text("홍길동", style: this._desTextStyle,),
],
),
),
Container(
padding: this._widgetPadding,
decoration: BoxDecoration(
border: Border.symmetric(horizontal: BorderSide(color: Colors.grey))
),
margin: this._widgetMargin,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("이메일", style: this._titleTextStyle,),
Text("afzxc@naver.com", style: this._desTextStyle,),
],
),
),
Container(
alignment: Alignment.center,
margin: this._widgetMargin,
child: MaterialButton(
child: Text("전송",style: this._titleTextStyle,),
onPressed: () async{
return await showDialog<void>(
context: context,
builder: (BuildContext context) => AlertDialog(
title: (this._imgData == null)
? Text("변경 할 이미지가 없습니다")
: Text("이제 서버로 이미지 데이터를 보내시면 됩니다"),
actions: [
TextButton(
child: Text("닫기"),
onPressed: () => Navigator.of(context).pop<void>(),
)
],
)
);
},
color: Colors.red,
textColor: Colors.white,
),
)
],
),
),
),
);
}
EdgeInsets _widgetPadding = EdgeInsets.symmetric(horizontal: 20.0);
EdgeInsets _widgetMargin = EdgeInsets.only(top:20.0, left: 40.0, right: 40.0);
TextStyle _titleTextStyle = TextStyle(fontSize: 16.0,fontWeight: FontWeight.bold);
TextStyle _desTextStyle = TextStyle(fontSize: 16.0,);
BoxDecoration _imgWidget() => (this._imgData == null) ? BoxDecoration(color: Colors.grey) : BoxDecoration(
image: DecorationImage(
image: MemoryImage(this._imgData),
fit: BoxFit.cover
)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment