Open name27 opened 1 year ago
강의 보고 난 후 수정사항
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/container.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:secret_app/Page/author_page.dart';
import 'package:secret_app/Page/secret_page.dart';
import 'package:secret_app/Page/upload_page.dart';
class MainPage extends StatelessWidget {
const MainPage({super.key});
@override
Widget build(BuildContext context) {
var _titleName = '내 비밀 네 비밀';
return Scaffold(
backgroundColor: Colors.indigo[900],
extendBodyBehindAppBar: true,
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
),
body: Center(
child: SingleChildScrollView(
physics: NeverScrollableScrollPhysics(),
child: Column(
children: [
CircleAvatar(
backgroundImage: AssetImage('assets/marketing.png'),
radius: 40,
),
SizedBox(
height: 8,
),
FutureBuilder(
future: Future.delayed(Duration(milliseconds: 2000)),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
_titleName = '내 비 네 비';
return Animate(
effects: [
FadeEffect(duration: Duration(milliseconds: 800)),
ScaleEffect(
begin: Offset(0.8, 0.8),
duration: Duration(milliseconds: 800))
],
child: Text(
_titleName,
style: TextStyle(color: Colors.white, fontSize: 22),
),
);
} else {
_titleName = '내 비밀 네 비밀';
return Animate(
effects: [
TintEffect(
delay: Duration(milliseconds: 500),
duration: Duration(milliseconds: 1500),
color: Colors.indigo[900])
],
child: Text(
_titleName,
style: TextStyle(color: Colors.white, fontSize: 22),
),
);
}
},
),
SizedBox(
height: 60,
),
Container(
width: 330,
height: 70,
color: Colors.white,
child: ListTile(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SecretPage()));
},
tileColor: Colors.white,
title: Text('비밀 보기'),
subtitle: Text('눌러가기'),
trailing: CircleAvatar(
backgroundImage: AssetImage('assets/marketing.png'),
),
),
),
SizedBox(
height: 15,
),
Container(
width: 330,
height: 70,
color: Colors.white,
child: ListTile(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AuthorPage()));
},
tileColor: Colors.white,
title: Text('작성자들 보러가기'),
subtitle: Text('눌러가기'),
trailing: CircleAvatar(
backgroundImage: AssetImage('assets/marketing.png'),
),
),
),
SizedBox(
height: 15,
),
Container(
width: 330,
height: 70,
color: Colors.white,
child: ListTile(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => UploadPage()));
},
tileColor: Colors.white,
title: Text('비밀 공유'),
subtitle: Text('눌러가기'),
trailing: CircleAvatar(
backgroundImage: AssetImage('assets/marketing.png'),
),
),
),
],
),
),
),
);
}
}
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/container.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:secret_cat_sdk/api/api.dart';
class SecretPage extends StatelessWidget {
const SecretPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
extendBodyBehindAppBar: true,
appBar: AppBar(
title: Text('뒤로가기'),
backgroundColor: Colors.transparent,
elevation: 0,
),
body: Container(
alignment: Alignment.center,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/backgroundImage.jpg'),
fit: BoxFit.cover,
colorFilter: ColorFilter.mode(Colors.black45, BlendMode.darken))),
child: Center(
child: FutureBuilder(
future: SecretCatApi.fetchSecrets(),
builder: (context, snapshot) {
if (snapshot.hasData) {
var reversedList = snapshot.data!.reversed.toList();
return PageView.builder(
itemCount: snapshot.data?.length,
itemBuilder: (context, index) => Animate(
effects: [
FadeEffect(
duration: Duration(milliseconds: 1200),
delay: Duration(milliseconds: 300)),
SlideEffect(begin: Offset(0.2, 0)),
ScaleEffect(begin: Offset(0.8, 0.8))
],
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
reversedList[index].author == null
? CircleAvatar(
backgroundImage:
AssetImage('assets/aquarius.png'),
radius: 35,
)
: CircleAvatar(
backgroundColor: Colors.transparent,
backgroundImage: NetworkImage(reversedList[index].author!.avatar
.toString()),
radius: 35,
),
SizedBox(
height: 8,
),
Animate(
effects: [
FadeEffect(
delay: Duration(milliseconds: 500),
duration: Duration(milliseconds: 1200)),
SlideEffect(
delay: Duration(milliseconds: 800),
begin: Offset(0.2, 0))
],
child: Text(
reversedList[index].secret.toString(),
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 18),
textAlign: TextAlign.center,
),
),
SizedBox(
height: 8,
),
Text(
reversedList[index].author?.username ?? '익명',
style: TextStyle(color: Colors.white))
],
),
),
);
}
return SizedBox();
},
)),
),
);
}
}
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/src/widgets/container.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:secret_cat_sdk/api/api.dart';
class UploadPage extends StatefulWidget {
const UploadPage({super.key});
@override
State<UploadPage> createState() => _UploadPageState();
}
class _UploadPageState extends State<UploadPage> {
var _inputController = TextEditingController();
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: Colors.black,
image: DecorationImage(
image: AssetImage('assets/backgroundImage.jpg'),
fit: BoxFit.cover,
opacity: 0.7),
),
child: Scaffold(
backgroundColor: Colors.transparent,
extendBodyBehindAppBar: true,
appBar: AppBar(
title: Text('뒤로가기'),
backgroundColor: Colors.transparent,
elevation: 0,
),
body: Center(
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
child: TextField(
style: TextStyle(color: Colors.white),
controller: _inputController,
minLines: 7,
maxLines: 8,
decoration: InputDecoration(
filled: true,
fillColor: Colors.white24,
hintText: '비밀을 입력하세요',
hintStyle: TextStyle(color: Colors.white),
enabledBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.white, width: 0.5))),
)),
ElevatedButton(
onPressed: () async {
if (_inputController.text != '') {
var secret =
await SecretCatApi.addSecret(_inputController.text);
if (secret != null) {
Navigator.pop(context);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('비밀 공유 성공 ${secret.secret}')));
}
}
},
child: Text('비밀 공유')),
],
),
),
)),
),
);
}
}
main.dart
main_page.dart
secret_page.dart
author_page.dart
upload_page.dart