WoofnWalk / lib / screens / maps / walkers_detail_screen.dart
walkers_detail_screen.dart
Raw
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

import '../../model/walker.dart';
import '../../widgets/location_input.dart';

class WalkerDetailScreen extends StatefulWidget {
  final Walker walker;
  WalkerDetailScreen({Key? key, required this.walker}) : super(key: key);

  @override
  _WalkerDetailsScreen createState() => _WalkerDetailsScreen();
}

class _WalkerDetailsScreen extends State<WalkerDetailScreen> {
  dynamic previewImg;
  String description = '';

  @override
  void initState() {
    super.initState();
    dynamic preview;
    String txtDesc = '';

    widget.walker.imgUrl == null ? preview = const Text('No photo available') : preview = Image.network(widget.walker.imgUrl!);
    widget.walker.description == null ? txtDesc = 'Hmm... this section seems empty.' : txtDesc = widget.walker.description!;

    setState(() {
      previewImg = preview;
      description = txtDesc;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        title: Text(widget.walker.name),
      ),
      body: SingleChildScrollView (
        child: Center (
            child: Column (
              children: <Widget>[
                LocationInput(latitude: widget.walker.location.latitude, longitude: widget.walker.location.longitude),
                Padding(
                  padding: const EdgeInsets.symmetric(vertical: 16.0),
                  child: Container (
                      width: 150.0,
                      height: 150.00,
                      child: previewImg
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.only(bottom: 4.0),
                  child: Text(
                      // <Name of Walker>
                      widget.walker.name,
                      style: const TextStyle(
                        fontSize: 25.0,
                        fontWeight: FontWeight.bold,
                      )
                  )
                ),
                const Padding(
                  padding: EdgeInsets.symmetric(horizontal: 12.0, vertical: 8.0),
                  child: Align(
                    alignment: Alignment.centerLeft,
                    child: Text(
                      'About Me',
                      textAlign: TextAlign.start,
                      style: TextStyle(
                        fontWeight: FontWeight.bold,
                        fontSize: 16.0,
                      ),
                    ),
                  ),
                ),
                Padding(
                    padding: const EdgeInsets.symmetric(horizontal: 12.0),
                    child: Text(
                        // <Description of Walker>
                        description,
                        textAlign: TextAlign.left,
                    )
                ),
                const Padding(
                  padding: EdgeInsets.all(8.0),
                  child: Divider(),
                ),
                Padding(
                    padding: const EdgeInsets.all(4.0),
                    child: Row(
                      children: [
                        const Padding(
                          padding: EdgeInsets.only(left: 8.0, right: 15.0),
                          child: Text(
                            'Years Experience',
                            style: TextStyle(
                              fontSize: 16.0,
                              fontWeight: FontWeight.bold,
                            ),
                          ),
                        ),
                        Text(
                          widget.walker.yrsExp.toString(),
                          textAlign: TextAlign.center,
                        )
                      ],)
                ),
                Padding(
                  padding: const EdgeInsets.all(4.0),
                  child: Row(
                    children: [
                      const Padding(
                          padding: EdgeInsets.only(left: 8.0, right: 15.0),
                          child: Text(
                            'Trainer Certified',
                            style: TextStyle(
                              fontSize: 16.0,
                              fontWeight: FontWeight.bold,
                            ),
                          ),
                        ),
                      widget.walker.trainingCert == true
                      ? const Padding(
                          padding: EdgeInsets.symmetric(horizontal: 8.0),
                          child: Text(
                              'Yes',
                              textAlign: TextAlign.center,
                          )
                        )
                      : const Padding(
                          padding: EdgeInsets.symmetric(horizontal: 8.0),
                          child: Text(
                              'No',
                              textAlign: TextAlign.center,
                          )
                        )
                  ],)
                ),
                Padding(
                  padding: const EdgeInsets.all(4.0),
                  child: Row(
                    children: [
                      const Padding(
                          padding: EdgeInsets.only(left: 8.0, right: 8.0),
                          child: Text(
                            'First Aid Certified',
                            style: TextStyle(
                              fontSize: 16.0,
                              fontWeight: FontWeight.bold,
                            ),
                          ),
                        ),
                      widget.walker.firstaid == true
                      ? const Padding(
                          padding: EdgeInsets.symmetric(horizontal: 8.0),
                          child: Text(
                              'Yes',
                              textAlign: TextAlign.center,
                          )
                        )
                      : const Padding(
                          padding: EdgeInsets.symmetric(horizontal: 8.0),
                          child: Text(
                              'No',
                              textAlign: TextAlign.center,
                          )
                        )
                  ],)
                ),
                Padding(
                    padding: const EdgeInsets.only(bottom: 4.0),
                    child: ElevatedButton.icon(
                      icon: const Icon(Icons.send),
                      onPressed: _sendingEmails,
                      label: const Text('Contact'),
                    )
                ),
              ],
            )
        ),
      ),
    );
  }

  _sendingEmails() async {
    String url = 'mailto:' + widget.walker.email;
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not open email: $url';
    }
  }
}