name27 / flutter

0 stars 0 forks source link

Nature #89

Open name27 opened 1 year ago

name27 commented 1 year ago

image

main.dart

import 'package:flutter/material.dart';
import 'package:nature_wep_clone_app/model/News.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    List<Map<String, dynamic>> newData = [
      {
        "title":
            "Webb telescope blasts off successfully — launching a new era in astronomy",
        "author": "Alexandra Witze",
        "time": "25 Dec 2021",
        "imageUrl":
            "https://media.nature.com/w1248/magazine-assets/d41586-021-03655-4/d41586-021-03655-4_19975878.jpg?as=webp"
      },
      {
        "title":
            "Researchers fear growing COVID vaccine hesitancy in developing nations",
        "author": "Smriti Mallapaty",
        "time": "23 Dec 2021",
        "imageUrl":
            "https://media.nature.com/lw767/magazine-assets/d41586-021-03830-7/d41586-021-03830-7_19972466.jpg?as=webp"
      },
      {
        "title": "Fatal lab explosion in China highlights wider safety fears",
        "author": "Andrew Silver",
        "time": "22 Dec 2021",
        "imageUrl":
            "https://media.nature.com/lw767/magazine-assets/d41586-021-03589-x/d41586-021-03589-x_19914056.jpg?as=webp"
      },
      {
        "title": "Journals adopt AI to spot duplicated images in manuscripts",
        "author": "Richard Van Noorden",
        "time": "21 Dec 2021",
        "imageUrl":
            "https://media.nature.com/lw767/magazine-assets/d41586-021-03807-6/d41586-021-03807-6_19969478.jpg?as=webp"
      },
      {
        "title":
            "Omicron overpowers key COVID antibody treatments in early tests",
        "author": "Max Kozlov",
        "time": "21 Dec 2021",
        "imageUrl":
            "https://media.nature.com/lw767/magazine-assets/d41586-021-03829-0/d41586-021-03829-0_19971408.jpg?as=webp"
      },
      {
        "title":
            "Afghanistan’s academics despair months after Taliban takeover",
        "author": "Smriti Mallapaty",
        "time": "17 Dec 2021",
        "imageUrl":
            "https://media.nature.com/lw767/magazine-assets/d41586-021-03774-y/d41586-021-03774-y_19964192.jpg?as=webp"
      },
      {
        "title": "The science events to watch for in 2022",
        "author": "Davide Castelvecchi",
        "time": "17 Dec 2021",
        "imageUrl":
            "https://media.nature.com/w1248/magazine-assets/d41586-021-03772-0/d41586-021-03772-0_19962224.jpg?as=webp"
      },
    ];
    var news = [];
    for (int i = 0; i < newData.length; i++) {
      news.add([]);
      news[i] = News(
          title: newData[i]["title"],
          author: newData[i]["author"],
          time: newData[i]["time"],
          imageUrl: newData[i]["imageUrl"]);
    }
    return MaterialApp(
      home: Scaffold(
        extendBodyBehindAppBar: true,
        appBar: AppBar(
          backgroundColor: Colors.transparent,
          elevation: 0,
        ),
        body: ListView.separated(
          itemCount: news.length,
          itemBuilder: (context, index) => Padding(
            padding: const EdgeInsets.all(12.0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  children: [
                    Container(
                      width: 240,
                      child: RichText(
                        overflow: TextOverflow.clip,
                        maxLines: 3,
                        strutStyle: StrutStyle(fontSize: 16.0),
                        text: TextSpan(
                            text: news[index].title,
                            style: TextStyle(
                                fontSize: 18,
                                color: Colors.black,
                                fontWeight: FontWeight.bold,
                                decoration: TextDecoration.underline)),
                      ),
                    ),
                    SizedBox(
                      width: 20,
                    ),
                    SizedBox(
                        width: 125,
                        height: 70,
                        child: Image.network(
                          news[index].imageUrl,
                          fit: BoxFit.cover,
                        )),
                  ],
                ),
                SizedBox(
                  height: 8,
                ),
                Text(
                  news[index].author,
                  style: TextStyle(fontSize: 13),
                ),
                Row(
                  children: [
                    Text(
                      "News",
                      style:
                          TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
                    ),
                    Text(
                      " | ",
                      style: TextStyle(fontWeight: FontWeight.w200),
                    ),
                    Text(
                      news[index].time,
                      style: TextStyle(fontSize: 15),
                    )
                  ],
                )
              ],
            ),
          ),
          separatorBuilder: (context, index) => Divider(
            thickness: 2,
          ),
        ),
      ),
    );
  }
}

News.dart

class News {
  String title;
  String author;
  String time;
  String imageUrl;

  News(
      {required this.title,
      required this.author,
      required this.time,
      required this.imageUrl});
}