Advertisement
Guest User

Untitled

a guest
Nov 29th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 4.20 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'monumento.dart';
  3. import 'package:http/http.dart' as http;
  4. import 'dart:convert';
  5.  
  6. void main() {
  7.   runApp(MyApp());
  8. }
  9.  
  10. class MyApp extends StatelessWidget {
  11.   // This widget is the root of your application.
  12.   @override
  13.   Widget build(BuildContext context) {
  14.     return MaterialApp(
  15.       debugShowCheckedModeBanner: false,
  16.       title: 'Flutter Demo',
  17.       theme: ThemeData(
  18.         primarySwatch: Colors.blue,
  19.         visualDensity: VisualDensity.adaptivePlatformDensity,
  20.       ),
  21.       home: HomeScreen(),
  22.     );
  23.   }
  24. }
  25.  
  26. class HomeScreen extends StatefulWidget {
  27.   @override
  28.   _HomeScreenState createState() => _HomeScreenState();
  29. }
  30.  
  31. class _HomeScreenState extends State<HomeScreen> {
  32.   String risultato = '';
  33.   List<Monumento> monumenti = List<Monumento>();
  34.  
  35.   @override
  36.   void initState() {
  37.     monumentiGet();
  38.     super.initState();
  39.   }
  40.  
  41.   @override
  42.   Widget build(BuildContext context) {
  43.     return Scaffold(
  44.       body: Column(
  45.         children: <Widget>[
  46.           ClipPath(
  47.             clipper: MyClipper(),
  48.             child: Container(
  49.               height: 350,
  50.               width: double.infinity,
  51.               decoration: BoxDecoration(
  52.                 gradient: LinearGradient(
  53.                     begin: Alignment.topRight,
  54.                     end: Alignment.bottomLeft,
  55.                     colors: [Color(0xFF890000), Color(0xFF520000)]),
  56.                 image: DecorationImage(
  57.                   image: NetworkImage(
  58.                       'xxx'),
  59.                 ),
  60.               ),
  61.             ),
  62.           ),
  63.           Container(
  64.             margin: EdgeInsets.symmetric(horizontal: 20),
  65.             height: 80,
  66.             width: double.infinity,
  67.             decoration: BoxDecoration(
  68.                 color: Colors.white,
  69.                 borderRadius: BorderRadius.circular(25),
  70.                 border: Border.all(
  71.                   color: Color(0xFF676767),
  72.                 )),
  73.             child: Padding(
  74.               padding: const EdgeInsets.all(12.0),
  75.               child: Row(
  76.                 mainAxisAlignment: MainAxisAlignment.spaceAround,
  77.                 children: <Widget>[
  78.                   Text(
  79.                     'Oggi a Ferentino ci sono 18 gradi',
  80.                     style: TextStyle(fontWeight: FontWeight.bold),
  81.                   ),
  82.                   Icon(Icons.wb_sunny)
  83.                 ],
  84.               ),
  85.             ),
  86.           ),
  87.           Container(
  88.             height: 100,
  89.             child: Padding(
  90.               padding: const EdgeInsets.all(8.0),
  91.               child: ListView.builder(
  92.                   scrollDirection: Axis.horizontal,
  93.                   itemCount: monumenti.length,
  94.                   itemBuilder: (BuildContext context, int index) {
  95.                     return Card(
  96.                       elevation: 2,
  97.                       child: ListTile(
  98.                           onTap: (){},
  99.                           leading: Image.network(monumenti[index].immagine),
  100.                           title: Text(monumenti[index].nomeMonumento),
  101.                           subtitle: Text(monumenti[index].nomeMonumento),
  102.                     )
  103.                     );
  104.                   },
  105.                 ),
  106.             ),
  107.           )
  108.         ],
  109.       ),
  110.     );
  111.   }
  112.  
  113.   Future monumentiGet() async {
  114.     final String url = 'xxx';
  115.     try {
  116.       http.get(url).then((res) {
  117.         final resJson = json.decode(res.body);
  118.         monumenti = resJson
  119.             .map<Monumento>((mappa) => Monumento.fromMap(mappa))
  120.             .toList();
  121.         setState(() {
  122.           risultato = res.body;
  123.           monumenti = monumenti;
  124.         });
  125.       });
  126.     } catch (errore) {
  127.       setState(() {
  128.         risultato = '';
  129.       });
  130.     }
  131.   }
  132. }
  133.  
  134. class MyClipper extends CustomClipper<Path> {
  135.   @override
  136.   Path getClip(Size size) {
  137.     var path = Path();
  138.     path.lineTo(0, size.height - 80);
  139.     path.quadraticBezierTo(
  140.         size.width / 2, size.height, size.width, size.height - 80);
  141.     path.lineTo(size.width, 0);
  142.     path.close();
  143.     return path;
  144.   }
  145.  
  146.   @override
  147.   bool shouldReclip(covariant CustomClipper<Path> oldClipper) {
  148.     return false;
  149.   }
  150. }
  151.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement