Skip to content

Instantly share code, notes, and snippets.

@Meshugah
Last active June 4, 2020 05:39
Show Gist options
  • Save Meshugah/f3c4cb24d2bf7b46136d3585dfdd3326 to your computer and use it in GitHub Desktop.
Save Meshugah/f3c4cb24d2bf7b46136d3585dfdd3326 to your computer and use it in GitHub Desktop.
Flutterhelp code review
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_calendar/calendar.dart';
import 'package:syncfusion_flutter_core/core.dart';
void main() {
return runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
// This makes the visual density adapt to the platform that you run
// the app on. For desktop platforms, the controls will be smaller and
// closer together (more dense) than on mobile platforms.
visualDensity: VisualDensity.adaptivePlatformDensity,
),
initialRoute: '/CalendarList',
routes: {
'/CalendarList': (context) => CalendarList(),
'/CreateOrder': (context) => CreateOrder(),
'/Reports': (context) => Reports(),
},
);
}
}
Widget _heroAppBar({BuildContext context}){
print(context);
return PreferredSize(
preferredSize: Size.fromHeight(kToolbarHeight),
child: Hero(
tag: 'app_bar',
child: Builder(builder: (BuildContext context) {
return AppBar(
title: const Text('AppBar Demo'),
actions: <Widget>[
IconButton(
icon: const Icon(Icons.add_box),
tooltip: 'Show Snackbar',
onPressed: () {
Navigator.pushReplacementNamed(
context,'/CreateOrder'
);
},
),
IconButton(
icon: const Icon(Icons.calendar_today),
tooltip: 'Next page',
onPressed: () {
Navigator.pushReplacementNamed(
context, '/CalendarList'
);
}
),
IconButton(
icon: const Icon(Icons.assessment),
tooltip: 'Next page',
onPressed: () {
Navigator.pushReplacementNamed(
context, '/CalendarList'
);
}
),
],
);
}
),
),
);
}
// CREATE ORDER page
class CreateOrder extends StatefulWidget {
CreateOrder({Key key, this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
_CreateOrderState createState() => _CreateOrderState();
}
class _CreateOrderState extends State<CreateOrder> {
int _counter = 0;
String _dropDownMenuBagType1;
String _dropDownMenuBagType2;
TextEditingController _controller;
DateTime _date = new DateTime.now();
Future<Null> _selectDate(BuildContext context) async {
final DateTime picked = await showDatePicker(context: context, initialDate: _date, firstDate: new DateTime(2020), lastDate: new DateTime(2030));
if (picked != null && picked != _date) {
print('Date Selected: ${_date.toString()} ');
setState(() {
_date = picked;
});
}
}
void initState() {
super.initState();
_controller = TextEditingController();
}
void dispose() {
_controller.dispose();
super.dispose();
}
Future<void> _confirmOrderCreation() async {
await _selectDate(context);
showDialog(
context: context,
builder: (_) => AlertDialog(
title: (_counter > 1)? Text("Create $_counter Orders?") : Text("Create an Order?"),
content: Text("This will create an order and print labels on $_date and will start printing labels"),
actions: <Widget>[
FlatButton(
child: Text("No"),
onPressed: () {
Navigator.of(context).pop(); // close the bubble
},
),
FlatButton(
child: Text("Yes"),
onPressed: (){
// ERPNEXT //
Navigator.of(context).pop(); // close the bubble
},
),
],
)
);
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: _heroAppBar(context:context),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: EdgeInsets.all(8),
child: Text(
'Choose Bag Type',
style: Theme.of(context).textTheme.headline5,
),
),Padding(
padding: EdgeInsets.fromLTRB(40,0,40,40),
child: DropdownButton<String>(
value: _dropDownMenuBagType1,
icon: Icon(Icons.arrow_downward),
iconSize: 24,
elevation: 16,
isExpanded: true,
style: TextStyle(color: Colors.blue),
underline: Container(
height: 2,
color: Colors.blue,
),
onChanged: (String newValue) {
setState(() {
_dropDownMenuBagType1 = newValue;
});
},
items: <String>['One', 'Two', 'Free', 'Four']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
),
Padding(
padding: EdgeInsets.all(8),
child: Text(
'End Customer',
style: Theme.of(context).textTheme.headline5,
),
),
Padding(
padding: EdgeInsets.fromLTRB(40,0,40,40),
child: Row(
children: <Widget>[
IconButton(
icon: Icon(Icons.group_add),
),
Expanded(
child: DropdownButton<String>(
value: _dropDownMenuBagType2,
icon: Icon(Icons.arrow_downward),
iconSize: 24,
elevation: 16,
isExpanded: true,
style: TextStyle(color: Colors.blue),
underline: Container(
height: 2,
color: Colors.blue,
),
onChanged: (String newValue) {
setState(() {
_dropDownMenuBagType2 = newValue;
});
},
items: <String>['One', 'Two', 'Free', 'Four']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
),
],
),
),
Padding(
padding: EdgeInsets.all(8),
child: Text(
'Order Size',
style: Theme.of(context).textTheme.headline5,
),
),Padding(
padding: EdgeInsets.fromLTRB(40,0,40,40),
child: TextField(
controller: _controller,
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.blue, width: 2),
),
),
onChanged: (userInput) async {
setState(() {
_counter = userInput?.isEmpty ? 0 :int.parse(userInput);
print(_counter);
});
},
),
),
Padding(
padding: EdgeInsets.all(8),
child: RaisedButton(
onPressed: _counter > 0
&& _dropDownMenuBagType1 != null
&& _dropDownMenuBagType2 != null
? _confirmOrderCreation : null,
child: Text(
'Submit',
),
),
),
],
),
),
);
}
}
// CALENDAR Page
class CalendarList extends StatefulWidget {
@override
_CalendarListState createState() => _CalendarListState();
}
class _CalendarListState extends State<CalendarList> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: _heroAppBar(context:context),
body: Center(
child: SfCalendar(
view: CalendarView.month,
monthViewSettings: MonthViewSettings(showAgenda: true),
),
),
);
}
}
// REPORTS PAGE
class Reports extends StatefulWidget {
@override
_ReportsState createState() => _ReportsState();
}
class _ReportsState extends State<Reports> {
@override
Widget build(BuildContext context) {
return Container();
}
}
// TODO : rename all tooltips
// todo: clean up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment