Exemplo de solicitação ao Chatgpt, Genini e Copilot
Tempo de leitura: 5 minutes
Perguntado em Inglês o texto abaixo, olha as respostas.
write flutter code all font - Google font plugin (poppins) padding - 15 title "Beverages" - poppins, semibold, size 18 hight gap 4 gridview (col 2, gap 15,Ratio - 9/14) - ProductCard ProductCard (container) - border (radius 15, color grey), bg color white. inside card padding 5, image, hight gap 15, name - (font semibold), unit - (grey, size 12), price - (size 14, font medium). all element should be center. data (with model class) [ { "name": "Diet Coke", "price": "$1.99", "unit": "355ml", "image": "https://lnkd.in/gT5VX8_s" }, { "name": "Sprite Can", "price": "$1.50", "unit": "355ml", "image": "https://lnkd.in/gr26cyZc" }, { "name": "Apple Juice", "price": "$15.99", "unit": "2L", "image": "https://lnkd.in/geTkPRmP" }, { "name": "Orange Juice", "price": "$15.99", "unit": "2L", "image": "https://lnkd.in/gDxxMSvn" }, { "name": "Coca Cola Can", "price": "$4.99", "unit": "325ml", "image": "https://lnkd.in/gcyrWsxw" }, { "name": "Pepsi Can", "price": "$4.99", "unit": "330ml", "image": "https://lnkd.in/gZFu23eK" } ] need full code
Resposta do Copilot do Bing
Sure, here’s a Flutter code snippet that should meet your requirements. This code uses the Google Fonts plugin for Flutter to apply the Poppins font. It also includes a GridView to display a list of products in a card format. ----- (Tradução) Claro, aqui está um trecho de código do Flutter que deve atender às suas necessidades. Esse código usa o plug-in do Google Fonts para o Flutter para aplicar a fonte Poppins. Ele também inclui um GridView para exibir uma lista de produtos em um formato de cartão. ----- Programa abaixo. ----- Please note that you need to add the google_fonts package to your pubspec.yaml file. Also, the images are loaded from the network, so you need to add the necessary permissions to your app if you’re testing on a real device. Finally, this is a basic implementation and might need adjustments based on your exact requirements. ---- (Tradução) ------ Observe que você precisa adicionar o pacote google_fonts ao seu arquivo pubspec.yaml. Além disso, as imagens são carregadas da rede, portanto, você precisa adicionar as permissões necessárias ao seu aplicativo se estiver testando em um dispositivo real. Por fim, esta é uma implementação básica e pode precisar de ajustes com base em seus requisitos exatos.
Código Fonte
Dart import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; class Product { final String name; final String price; final String unit; final String image; Product({required this.name, required this.price, required this.unit, required this.image}); } final List<Product> products = [ Product(name: "Diet Coke", price: "\$1.99", unit: "355ml", image: "https://lnkd.in/gT5VX8_s"), Product(name: "Sprite Can", price: "\$1.50", unit: "355ml", image: "https://lnkd.in/gr26cyZc"), Product(name: "Apple Juice", price: "\$15.99", unit: "2L", image: "https://lnkd.in/geTkPRmP"), Product(name: "Orange Juice", price: "\$15.99", unit: "2L", image: "https://lnkd.in/gDxxMSvn"), Product(name: "Coca Cola Can", price: "\$4.99", unit: "325ml", image: "https://lnkd.in/gcyrWsxw"), Product(name: "Pepsi Can", price: "\$4.99", unit: "330ml", image: "https://lnkd.in/gZFu23eK"), ]; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Padding( padding: const EdgeInsets.all(15.0), child: Column( children: [ Text( 'Beverages', style: GoogleFonts.poppins( fontSize: 18, fontWeight: FontWeight.w600, ), ), SizedBox(height: 4), Expanded( child: GridView.builder( gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 2, childAspectRatio: 9 / 14, crossAxisSpacing: 15, mainAxisSpacing: 15, ), itemCount: products.length, itemBuilder: (context, index) { return ProductCard(product: products[index]); }, ), ), ], ), ), ), ); } } class ProductCard extends StatelessWidget { final Product product; ProductCard({required this.product}); @override Widget build(BuildContext context) { return Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(15), border: Border.all(color: Colors.grey), ), child: Padding( padding: const EdgeInsets.all(5.0), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Image.network(product.image), SizedBox(height: 15), Text( product.name, style: GoogleFonts.poppins(fontWeight: FontWeight.w600), ), Text( product.unit, style: GoogleFonts.poppins(color: Colors.grey, fontSize: 12), ), Text( product.price, style: GoogleFonts.poppins(fontSize: 14, fontWeight: FontWeight.w500), ), ], ), ), ); } }
Resposta do ChatGPT 3.5
Apenas Código Fonte.
import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class Product { final String name; final String price; final String unit; final String image; Product({ required this.name, required this.price, required this.unit, required this.image, }); } class MyApp extends StatelessWidget { final List<Product> products = [ Product( name: "Diet Coke", price: "\$1.99", unit: "355ml", image: "https://lnkd.in/gT5VX8_s", ), Product( name: "Sprite Can", price: "\$1.50", unit: "355ml", image: "https://lnkd.in/gr26cyZc", ), Product( name: "Apple Juice", price: "\$15.99", unit: "2L", image: "https://lnkd.in/geTkPRmP", ), Product( name: "Orange Juice", price: "\$15.99", unit: "2L", image: "https://lnkd.in/gDxxMSvn", ), Product( name: "Coca Cola Can", price: "\$4.99", unit: "325ml", image: "https://lnkd.in/gcyrWsxw", ), Product( name: "Pepsi Can", price: "\$4.99", unit: "330ml", image: "https://lnkd.in/gZFu23eK", ), ]; @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, home: Scaffold( appBar: AppBar( title: Text( "Beverages", style: TextStyle( fontFamily: 'Poppins', fontWeight: FontWeight.w600, fontSize: 18, ), ), ), body: Padding( padding: EdgeInsets.all(15), child: GridView.builder( gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 2, crossAxisSpacing: 15, mainAxisSpacing: 15, childAspectRatio: 9 / 14, ), itemCount: products.length, itemBuilder: (context, index) { return ProductCard(product: products[index]); }, ), ), ), ); } } class ProductCard extends StatelessWidget { final Product product; const ProductCard({Key? key, required this.product}) : super(key: key); @override Widget build(BuildContext context) { return Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(15), color: Colors.white, border: Border.all(color: Colors.grey), ), padding: EdgeInsets.all(5), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Image.network(product.image), SizedBox(height: 15), Text( product.name, style: TextStyle( fontFamily: 'Poppins', fontWeight: FontWeight.w600, ), ), Text( product.unit, style: TextStyle( color: Colors.grey, fontSize: 12, ), ), Text( product.price, style: TextStyle( fontSize: 14, fontWeight: FontWeight.w500, ), ), ], ), ); } }
Resposta do Gemini AI
Código Fonte
Dart // Import required libraries import 'package:flutter/material. // [[1](https://fonts.google.com/specimen/Poppins)] import 'package:http/http.dart' as http; // for fetching images (not shown in provided code) // Define your Product class to hold product information class Product { final String name; final double price; final String unit; final String image; Product({ required this.name, required this.price, required this.unit, required this.image, }); } // Create a custom ProductCard widget class ProductCard extends StatelessWidget { final Product product; const ProductCard({Key? key, required this.product}) : super(key: key); @override Widget build(BuildContext context) { return Container( padding: const EdgeInsets.all(5.0), decoration: BoxDecoration( borderRadius: BorderRadius.circular(15.0), color: Colors.white, border: Border.all( color: Colors.grey, width: 1.0, ), ), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ // Load product image (assuming you have a way to fetch the image) Image.network(product.image), const SizedBox(height: 15.0), Text( product.name, style: const TextStyle( fontSize: 14.0, fontWeight: FontWeight.semibold, // [[2](https://developer.mozilla.org/pt-BR/docs/Web/CSS/font-weight)] ), ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( product.unit, style: const TextStyle( fontSize: 12.0, color: Colors.grey, ), ), Text( product.price.toStringAsFixed(2), // format price to 2 decimal places style: const TextStyle( fontSize: 14.0, fontWeight: FontWeight.medium, // [[2](https://developer.mozilla.org/pt-BR/docs/Web/CSS/font-weight)] ), ), ], ), ], ), ); } } // Main app widget void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { // Sample product data final List<Product> products = [ // ... (your product data here) ]; @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: Text( 'Beverages', style: TextStyle( // Use Poppins font (需自行集成 Google Fonts 套件) [[1](https://fonts.google.com/specimen/Poppins)] fontSize: 18.0, fontWeight: FontWeight.semibold, // [[2](https://developer.mozilla.org/pt-BR/docs/Web/CSS/font-weight)] ), ), ), body: GridView.count( crossAxisCount: 2, // 2 columns crossAxisSpacing: 15.0, // spacing between columns [[6](https://developer.mozilla.org/en-US/docs/Web/CSS/column-gap)] childAspectRatio: 9 / 14, // aspect ratio of each card padding: const EdgeInsets.all(15.0), // grid view padding [[3](https://stackoverflow.com/questions/49943272/flutter-gridview-in-column-whats-solution)] children: products.map((product) => ProductCard(product: product)).toList(), ), ), ); } }
Explicação fornecida do Código
This code incorporates the following functionalities based on the provided requirements:
- Grid View with Product Cards: Creates a GridView with two columns (crossAxisCount: 2) and spacing between them (crossAxisSpacing).
- Product Card Design: Defines a ProductCard widget with a container, border, background color, padding, image, and text elements for product name, unit, and price.
- Data with Model Class: Uses a Product class to hold product information and a sample product list.
- **Custom Fonts (Integration Required):