커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
MAP 사용법
[왕초보] 플러터(Flutter)로 시작하는 앱개발 종합반 v0
기타
북마크
백*희
댓글
3
추천
0
조회수
7
조회수
7
답변 완료

* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.


안녕하세요! 5주간의 수업 정말 잘 들었습니다.

추가적인 공부를 위해 서비스를 만들어보려고 하고 있습니다.

이런것을 질문드려도 되는지 모르겠지만,


최종적으로 이력서를 PDF로 만들어주는 어플을 생각하고 있는데요!

앱개발 종합반 수업에서 만들었던 mymemo 구조를 가지고 만들어보고 있습니다.


우선은 생일 년 / 월 / 일 정보만 어떻게 해보고 싶은데


infoMap이라는 형태로 만들었는데,

TextField(

                    controller: _birthController,

                    onChanged: (value) {},

                    decoration: InputDecoration(

                      labelText: 'YYYY',

                      labelStyle: TextStyle(

                        color: Colors.grey,

                      ),


이부분에서 labelText: infoMap[birthyyyy]가 null이면 'YYYY' 값이 있으면 infoMap[birthyyyy] 이 값을 보여주고 싶습니다.

어떤 식으로 해야할까요?

제가 map으로 만든것도 과연 잘한 일일까요...



작성한 코드 및 에러 메세지

main.dart


import 'package:flutter/material.dart';

import 'info.dart';

import 'info_service.dart';

import 'package:provider/provider.dart';

import 'package:shared_preferences/shared_preferences.dart';


late SharedPreferences prefs;


void main() async {

  WidgetsFlutterBinding.ensureInitialized();

  prefs = await SharedPreferences.getInstance();

  runApp(

    MultiProvider(

      providers: [

        ChangeNotifierProvider(

          create: (context) => InfoService(),

        )

      ],

      child: MyApp(),

    ),

  );

}


class MyApp extends StatelessWidget {

  @override

  Widget build(BuildContext context) {

    return MaterialApp(

      title: 'ProFit PortFolio',

      theme: ThemeData(

        primarySwatch: Colors.blue,

      ),

      home: ResumeForm(),

    );

  }

}


//

class ResumeForm extends StatefulWidget {

  @override

  _ResumeFormState createState() => _ResumeFormState();

}


class _ResumeFormState extends State<ResumeForm> {

  final TextEditingController _birthController = TextEditingController();


  @override

  Widget build(BuildContext context) {

    return Consumer<InfoService>(builder: (context, infoservice, child) {

      return Scaffold(

        appBar: AppBar(

          title: Text(

            '내 이력서 만들기',

            style: TextStyle(

              color: Colors.white,

              fontWeight: FontWeight.bold,

              fontSize: 20,

            ),

          ),

        ),

        body: Column(

          children: [

            Container(

              width: double.infinity,

              child: Row(

                children: [

                  TextField(

                    controller: _birthController,

                    onChanged: (value) {},

                    decoration: InputDecoration(

                      labelText: 'YYYY',

                      labelStyle: TextStyle(

                        color: Colors.grey,

                      ),

                    ),

                  ),

                  Text("년"),

                  TextField(

                    decoration: InputDecoration(

                      labelText: "MM",

                      labelStyle: TextStyle(

                        color: Colors.grey,

                      ),

                    ),

                  ),

                  Text("월"),

                  TextField(

                    decoration: InputDecoration(

                      labelText: "DD",

                      labelStyle: TextStyle(

                        color: Colors.grey,

                      ),

                    ),

                  ),

                  Text("일"),

                  TextButton(onPressed: () {}, child: Text('저장'))

                ],

              ),

            )

          ],

        ),

      );

    });

  }

}


class InfoService extends ChangeNotifier {

  Map<String, Info> infoMap = {};


  createInfo({

    required String? birthyyyy,

    required String? birthmm,

    required String? birthdd,

  }) {

    String key = "$birthyyyy$birthmm$birthdd";

    Info info = Info(

      birthyyyy: birthyyyy,

      birthmm: birthmm,

      birthdd: birthdd,

    );

    infoMap[key] = info;

    notifyListeners();

  }

}


class Info {

  Info({

    required this.birthyyyy,

    required this.birthmm,

    required this.birthdd,

  });


  String? birthyyyy;

  String? birthmm;

  String? birthdd;

}

//





취소
 공유
취소
댓글 0
댓글 알림
나의얼굴