Skip to content

Instantly share code, notes, and snippets.

@asadamatic
Created March 22, 2024 04:53
Show Gist options
  • Save asadamatic/776448b129c82177be517aa40cdbde95 to your computer and use it in GitHub Desktop.
Save asadamatic/776448b129c82177be517aa40cdbde95 to your computer and use it in GitHub Desktop.
UI to Flutter Code Using ChatGpt Plus.
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: HomeScreen(),
);
}
}
class HomeScreen extends StatelessWidget {
const HomeScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: TextButton(
child: Text('Hello, World!'),
onPressed: () => showDialog(
context: context,
builder: (dialogContext) => AlertSelectionWidget())),
),
);
}
}
class AlertSelectionWidget extends StatefulWidget {
@override
_AlertSelectionWidgetState createState() => _AlertSelectionWidgetState();
}
class _AlertSelectionWidgetState extends State<AlertSelectionWidget> {
String? _selectedAlert;
void _sendAlert() {
if (_selectedAlert != null) {
// Implement your send alert functionality here
print('Sending alert: $_selectedAlert');
}
}
@override
Widget build(BuildContext context) {
return Dialog(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Select an Alert',
style: Theme.of(context).textTheme.headline6,
),
SizedBox(height: 16.0),
Text(
'Select an alert from below to send to your students’ parents'),
ListTile(
title: Text('Bus is running late. Expect delayed arrival.'),
leading: Radio<String>(
value: 'Bus is running late',
groupValue: _selectedAlert,
onChanged: (value) {
setState(() {
_selectedAlert = value;
});
},
),
),
ListTile(
title: Text(
'Weather alert: Possible delays or changes. Stay tuned.'),
leading: Radio<String>(
value: 'Weather alert',
groupValue: _selectedAlert,
onChanged: (value) {
setState(() {
_selectedAlert = value;
});
},
),
),
ListTile(
title: Text('Bus maintenance alert. Expect possible delays.'),
leading: Radio<String>(
value: 'Bus maintenance alert',
groupValue: _selectedAlert,
onChanged: (value) {
setState(() {
_selectedAlert = value;
});
},
),
),
ListTile(
title: Text('Heavy Traffic Ahead. Expect possible delays'),
leading: Radio<String>(
value: 'Heavy Traffic Ahead',
groupValue: _selectedAlert,
onChanged: (value) {
setState(() {
_selectedAlert = value;
});
},
),
),
SizedBox(height: 24.0),
SizedBox(
width: double.infinity, // match_parent
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.yellow[700], // Button color
foregroundColor: Colors.black, // Text color
),
child: Text('Send Alert'),
onPressed: _sendAlert,
),
),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment