Created
May 10, 2024 23:24
-
-
Save oluyoung/8aabd775b6df1ce87c5d7133ee1bba78 to your computer and use it in GitHub Desktop.
Generated code from pixels2flutter.dev
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:go_router/go_router.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
MyApp({Key? key}) : super(key: key); | |
final GoRouter _router = GoRouter( | |
routes: [ | |
GoRoute( | |
path: '/', | |
builder: (BuildContext context, GoRouterState state) => CartScreen(), | |
), | |
GoRoute( | |
path: '/products', | |
builder: (BuildContext context, GoRouterState state) => ProductsScreen(), | |
), | |
], | |
); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp.router( | |
routeInformationParser: _router.routeInformationParser, | |
routerDelegate: _router.routerDelegate, | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
useMaterial3: true, | |
primarySwatch: Colors.green, | |
), | |
); | |
} | |
} | |
class CartScreen extends StatefulWidget { | |
@override | |
_CartScreenState createState() => _CartScreenState(); | |
} | |
class _CartScreenState extends State<CartScreen> { | |
int quantity = 1; | |
void _incrementQuantity() { | |
setState(() { | |
quantity++; | |
}); | |
} | |
void _decrementQuantity() { | |
if (quantity > 1) { | |
setState(() { | |
quantity--; | |
}); | |
} | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Cart'), | |
actions: [ | |
TextButton( | |
onPressed: () {}, | |
child: Text( | |
'Clear Cart', | |
style: TextStyle(color: Colors.white), | |
), | |
), | |
], | |
), | |
body: SingleChildScrollView( | |
child: Column( | |
children: [ | |
ListTile( | |
leading: Image.network( | |
'https://placehold.co/40x40?description=Brake%20Pad%20Image', | |
width: 40, | |
height: 40, | |
), | |
title: Text('Brake Pad'), | |
subtitle: Text('₦ 12,000.00'), | |
trailing: Row( | |
mainAxisSize: MainAxisSize.min, | |
children: [ | |
IconButton( | |
icon: Icon(Icons.remove), | |
onPressed: _decrementQuantity, | |
), | |
Text('$quantity'), | |
IconButton( | |
icon: Icon(Icons.add), | |
onPressed: _incrementQuantity, | |
), | |
], | |
), | |
), | |
Divider(), | |
ListTile( | |
title: Text('Add more items'), | |
trailing: Icon(Icons.add), | |
onTap: () => context.go('/products'), | |
), | |
ListTile( | |
leading: Icon(Icons.location_on), | |
title: Text('12 Obafemi Idowu street, Ikeja, Lagos'), | |
onTap: () { | |
// TODO: Implement modal for Google Places API search | |
}, | |
), | |
SizedBox(height: 16), | |
Text('Bill Details', style: Theme.of(context).textTheme.headline6), | |
ListTile( | |
title: Text('Sub Total'), | |
trailing: Text('₦12,000.00'), | |
), | |
ListTile( | |
title: Text('Coupon Discount'), | |
trailing: Text('₦0', style: TextStyle(color: Colors.green)), | |
), | |
ListTile( | |
title: Text('Delivery Fee'), | |
trailing: Text('₦1,000.00'), | |
), | |
Divider(), | |
ListTile( | |
title: Text('Total Amount'), | |
trailing: Text('₦13,000.00'), | |
), | |
SizedBox(height: 16), | |
ElevatedButton( | |
style: ElevatedButton.styleFrom( | |
minimumSize: Size(double.infinity, 50), // double.infinity is the width and 50 is the height | |
), | |
onPressed: () { | |
// TODO: Implement checkout functionality | |
}, | |
child: Text('Checkout'), | |
), | |
], | |
), | |
), | |
); | |
} | |
} | |
class ProductsScreen extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Products'), | |
), | |
body: Center( | |
child: Text('List of products will be displayed here.'), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment