Розмір відео: 1280 X 720853 X 480640 X 360
Показувати елементи керування програвачем
Автоматичне відтворення
Автоповтор
데이터가 계속 null로 체크가 됩니다.해결 방법이 있을까요?감사합니다.
현재 강좌의 정상 작동 소스입니다.import 'package:flutter/cupertino.dart';import 'package:flutter/material.dart';import '../database/memo.dart';import '../database/db.dart';class ViewPage extends StatelessWidget { const ViewPage({Key? key, required this.id}) : super(key: key); final String id; //findMemo(id)[0]; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( actions: [ IconButton( onPressed: (){}, icon: Icon(Icons.delete), ), IconButton( onPressed: (){}, icon: Icon(Icons.edit), ), ], ), body: Padding( padding: EdgeInsets.all(20.0), child: LoadBuilder(), ), ); } Future loadMemo(String id) async { DBHelper sd = DBHelper(); return await sd.findMemo(id); } LoadBuilder() { return FutureBuilder( future: loadMemo(id), builder: (BuildContext context, AsyncSnapshot snapshot){ if ((snapshot.data as List).isEmpty || (snapshot.data as List).length == 0){ //if (snapshot.data.isEmpty) { return Container( child: Text('데이터를 불러올 수 없습니다.') ); } else { Memo memo = snapshot.data![0]; return Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Text(memo.title, style: TextStyle(fontSize: 30, fontWeight: FontWeight.w500),), Text('메모 만든 시간: ' + memo.createTime.split('.')[0], style: TextStyle(fontSize: 11), textAlign: TextAlign.end,), Text('메모 수정 시간: ' + memo.editTime.split('.')[0], style: TextStyle(fontSize: 11), textAlign: TextAlign.end,), SizedBox(height: 20,), Expanded(child: Text(memo.text)), ], ); } }, ); }}
데이터가 계속 null로 체크가 됩니다.
해결 방법이 있을까요?
감사합니다.
현재 강좌의 정상 작동 소스입니다.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../database/memo.dart';
import '../database/db.dart';
class ViewPage extends StatelessWidget {
const ViewPage({Key? key, required this.id}) : super(key: key);
final String id;
//findMemo(id)[0];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
actions: [
IconButton(
onPressed: (){},
icon: Icon(Icons.delete),
),
IconButton(
onPressed: (){},
icon: Icon(Icons.edit),
),
],
),
body: Padding(
padding: EdgeInsets.all(20.0),
child: LoadBuilder(),
),
);
}
Future loadMemo(String id) async {
DBHelper sd = DBHelper();
return await sd.findMemo(id);
}
LoadBuilder() {
return FutureBuilder(
future: loadMemo(id),
builder: (BuildContext context, AsyncSnapshot snapshot){
if ((snapshot.data as List).isEmpty || (snapshot.data as List).length == 0){
//if (snapshot.data.isEmpty) {
return Container(
child: Text('데이터를 불러올 수 없습니다.')
);
} else {
Memo memo = snapshot.data![0];
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(memo.title, style: TextStyle(fontSize: 30, fontWeight: FontWeight.w500),),
Text('메모 만든 시간: ' + memo.createTime.split('.')[0], style: TextStyle(fontSize: 11), textAlign: TextAlign.end,),
Text('메모 수정 시간: ' + memo.editTime.split('.')[0], style: TextStyle(fontSize: 11), textAlign: TextAlign.end,),
SizedBox(height: 20,),
Expanded(child: Text(memo.text)),
],
);
}
},
);
}
}