Skip to content

Commit

Permalink
refactor: changed the design of drop down menu
Browse files Browse the repository at this point in the history
  • Loading branch information
mariammahrous23 committed Aug 29, 2024
1 parent c3be419 commit 1a8c36d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 125 deletions.
3 changes: 1 addition & 2 deletions threefold_connect/lib/features/dao page/data/vote.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import 'package:tfchain_client/generated/dev/types/pallet_dao/proposal/dao_votes
import 'package:tfchain_client/tfchain_client.dart';

//TODO: mnemonic need to be changed with user mnemonic
const mnemonic =
"print also path fish pizza cannon seminar prison piano merry endorse flight";
const mnemonic = "";

Future<DaoVotes> vote(bool vote, String hash, int farmId) async {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:gridproxy_client/models/farms.dart';
import 'package:tfchain_client/models/dao.dart';
Expand All @@ -22,7 +23,8 @@ class _VoteDialogState extends State<VoteDialog> {
List<Farm> farms = [];

void setFarms() async {
List<Farm> farmsList = await getMyFarms(8711); //TODO: replace with actual twin id
List<Farm> farmsList =
await getMyFarms(0); //TODO: replace with actual twin id
setState(() {
farms = farmsList;
});
Expand Down Expand Up @@ -60,50 +62,65 @@ class _VoteDialogState extends State<VoteDialog> {
direction: Axis.vertical,
mainAxisSize: MainAxisSize.min,
children: [
Flexible(
fit: FlexFit.loose,
child: DropdownMenu(
menuHeight: MediaQuery.sizeOf(context).width * 0.5,
enableFilter: true,
width: MediaQuery.sizeOf(context).width * 0.6,
textStyle: TextStyle(color: white, fontFamily: interBold),
inputDecorationTheme: const InputDecorationTheme(
filled: true,
fillColor: backgroundColor,
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(15)),
borderSide: BorderSide.none,
DropdownMenu(
menuHeight: MediaQuery.sizeOf(context).height * 0.3,
enableFilter: true,
width: MediaQuery.sizeOf(context).width * 0.55,
textStyle:
TextStyle(color: white, fontFamily: interBold, fontSize: 14),
trailingIcon: const Icon(
CupertinoIcons.chevron_down,
color: white,
size: 18,
),
selectedTrailingIcon: const Icon(
CupertinoIcons.chevron_up,
color: white,
size: 18,
),
inputDecorationTheme: const InputDecorationTheme(
filled: true,
fillColor: backgroundColor,
enabledBorder: UnderlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(4)),
borderSide: BorderSide(
color: secondaryColor,
width: 8.0,
),
),
menuStyle: MenuStyle(
backgroundColor:
MaterialStateProperty.all<Color>(backgroundColor),
surfaceTintColor:
MaterialStateProperty.all<Color>(Colors.transparent),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(10)),
),
contentPadding: EdgeInsets.only(right: 5, left: 15),
),
menuStyle: MenuStyle(
backgroundColor:
MaterialStateProperty.all<Color>(backgroundColor),
surfaceTintColor:
MaterialStateProperty.all<Color>(Colors.transparent),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(4)),
),
),
label: Text(
'Select Farm',
style: TextStyle(color: white, fontFamily: interBold),
),
dropdownMenuEntries: _buildDropdownMenuEntries(farms),
onSelected: (int? value) {
if (value != null) {
farmId = value;
}
},
padding: MaterialStateProperty.all<EdgeInsets>(
const EdgeInsets.only(right: 5, left: 15, bottom: 5)),
),
label: Text(
'Select Farm',
style: TextStyle(
color: white, fontFamily: interBold, fontSize: 14),
),
dropdownMenuEntries: _buildDropdownMenuEntries(farms),
onSelected: (int? value) {
if (value != null) {
farmId = value;
}
},
),
const SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
TextButton(
onPressed: () async {
onPressed: () {
if (farmId != null) {
vote(true, widget.proposal.hash, farmId!);
}
Expand All @@ -124,7 +141,7 @@ class _VoteDialogState extends State<VoteDialog> {
),
),
TextButton(
onPressed: () async {
onPressed: () {
if (farmId != null) {
vote(false, widget.proposal.hash, farmId!);
}
Expand Down
88 changes: 0 additions & 88 deletions threefold_connect/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ void main() {
class MyApp extends StatelessWidget {
const MyApp({super.key});

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
Expand All @@ -20,90 +19,3 @@ class MyApp extends StatelessWidget {
}
}

class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});

// 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
State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;

void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}

@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: AppBar(
// TRY THIS: Try changing the color here to a specific color (to
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
// change color while the other colors stay the same.
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
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.
//
// 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).
//
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
// action in the IDE, or press "p" in the console), to see the
// wireframe for each widget.
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}

0 comments on commit 1a8c36d

Please sign in to comment.